package com.controller;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.ChuqinEntity;
import com.service.ChuqinService;
import com.entity.view.ChuqinView;
import com.service.YonghuService;
import com.entity.YonghuEntity;
import com.utils.PageUtils;
import com.utils.R;
/**
* 考勤
* 后端接口
* @author
* @email
* @date 2021-02-25
*/
@RestController
@Controller
@RequestMapping("/chuqin")
public class ChuqinController {
private static final Logger logger = LoggerFactory.getLogger(ChuqinController.class);
@Autowired
private ChuqinService chuqinService;
@Autowired
private TokenService tokenService;
//级联表service
@Autowired
private YonghuService yonghuService;
//字典表map
Map<String, Map<Integer, String>> dictionaryMap;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isNotEmpty(role) && "用户".equals(role)){
params.put("yonghuId",request.getSession().getAttribute("userId"));
}
PageUtils page = chuqinService.queryPage(params);
//字典表数据转换
List<ChuqinView> list =(List<ChuqinView>)page.getList();
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
for(ChuqinView c:list){
this.dictionaryConvert(c);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
ChuqinEntity chuqin = chuqinService.selectById(id);
if(chuqin !=null){
//entity转view
ChuqinView view = new ChuqinView();
BeanUtils.copyProperties( chuqin , view );//把实体数据重构到view中
//级联表
YonghuEntity yonghu = yonghuService.selectById(chuqin.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
}
//字典表字典转换
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
this.dictionaryConvert(view);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 打卡
*/
@RequestMapping("/clockIn")
public R clockIn(String flag, HttpServletRequest request){
logger.debug("clockIn方法:,,Controller:{},,flag:{}",this.getClass().getName(),flag);
try {
Integer id = (Integer)request.getSession().getAttribute("userId");
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role) || "管理员".equals(role)){
return R.error(511,"没有打卡权限");
}
Date d = new Date();
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
String date = format1.format(d);
List<ChuqinEntity> chuqinList = new ArrayList<ChuqinEntity>();//要生成的list数据
List<String> s = new ArrayList<>();
s.add("yonghu_id+0");
Wrapper<ChuqinEntity> queryWrapper3 = new EntityWrapper<ChuqinEntity>().eq("yonghu_id",id).orderDesc(s);
List<ChuqinEntity> oldChuqinList = chuqinService.selectList(queryWrapper3);
if("1".equals(flag)){
//上班卡
Date date1 = new Date();
date1.setHours(8);
date1.setMinutes(0);
date1.setSeconds(0);
//上班打卡
//新增前先查看当前用户最大打卡时间
if(oldChuqinList != null && oldChuqinList.size()>0){
ChuqinEntity entity = oldChuqinList.get(0);
String today = entity.getToday();//获取出勤表最大出勤
//把日期加一天
Date todayTime = format1.parse(today);
Calendar calendar = new GregorianCalendar();
calendar.setTime(todayTime);
calendar.add(calendar.DATE,1);
String newToday = format1.format(calendar.getTime());
if(date.equals(today)){
return R.error(511,"已经打过上班卡了");
}else if(!date.equals(newToday)){//当天日期 不是出勤最大日期加一天的话 就是补充缺勤日期
chuqinList = this.getQueQin(d, format1, today, id);
}
if(chuqinList !=null && chuqinList.size() >0){
chuqinService.insertBatch(chuqinList);
}
//插入当天的上班卡
ChuqinEntity chuqin = new ChuqinEntity();
chuqin.setOnTime(d);
if(d.compareTo(date1)>0){//当前时间d 大于规定时间date1
chuqin.setChuqinTypes(6);//设置为迟到
}else if(d.compareTo(date1)<=0){//当前时间d 小于等于规定时间date1
chuqin.setChuqinTypes(3);//设置为未打下班卡
}
chuqin.setCreateTime(d);
chuqin.setToday(date);
chuqin.setYonghuId(id);
chuqinService.insert(chuqin);
}else{
//第一次打卡
ChuqinEntity chuqin = new ChuqinEntity();
chuqin.setOnTime(d);
if(d.compareTo(date1)>0){//当前时间d 大于规定时间date1
chuqin.setChuqinTypes(6);//设置为迟到
}else if(d.compareTo(date1)<=0){//当前时间d 小于等于规定时间date1
chuqin.setChuqinTypes(3);//设置为未打下班卡
}
chuqin.setCreateTime(d);
chuqin.setToday(date);
chuqin.setYonghuId(id);
chuqinService.insert(chuqin);
}
}else if("2".equals(flag)){
//下班卡
Date date1 = new Date();
date1.setHours(19);
date1.setMinutes(00);
date1.setSeconds(0);
Date date2 = new Date();
date2.setHours(18);
date2.setMinutes(
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
JSP+SSM项目-单位人事管理系统的Java毕业设计(源码+说明+演示视频+数据库).rar 【项目技术】 开发语言:Java 框架:ssm 架构:B/S 数据库:mysql 【实现功能】 人事变动管理,人员档案管理,职务类别管理,考勤管理,职称类别管理等
资源推荐
资源详情
资源评论
收起资源包目录
JSP+SSM项目-单位人事管理系统的Java毕业设计(源码+说明+演示视频+数据库).rar (816个子文件)
pink-violet.css 171KB
yellow-green.css 149KB
bootstrap.min.css 141KB
bootstrap.css 120KB
bootstrap.min.css 98KB
style.css 66KB
animate.css 55KB
ueditor.css 44KB
ueditor.min.css 34KB
font-awesome.min.css 30KB
jquery-ui-1.10.4.custom.min.css 27KB
jquery.treetable.theme.default.css 25KB
animate.css 23KB
styles.css 23KB
entypo-icon.css 23KB
all.css 21KB
font-awesome.css 21KB
video-js.css 21KB
font-awesome.min.css 20KB
all.css 19KB
image.css 19KB
jquery.idealforms.css 17KB
themify-icons.css 16KB
video.css 15KB
attachment.css 15KB
square.min.css 14KB
all.css 14KB
all.css 13KB
all.css 13KB
bootstrap-select.css 13KB
all.css 12KB
dropzone.css 11KB
video-js.min.css 11KB
bootstrap-switch.css 11KB
bootstrap-datetimepicker.min.css 11KB
extra-pages.css 11KB
ladda.min.css 10KB
tooltipster.css 9KB
calendar.css 9KB
responsive.css 8KB
shCoreDefault.css 7KB
social.css 7KB
jquery-jvectormap.css 6KB
clockface.css 6KB
jquery.steps.css 6KB
dripicon.css 5KB
weather-icons.min.css 5KB
footable.core.css 5KB
dataTables.bootstrap4.min.css 5KB
datepicker.css 5KB
style-responsive.css 5KB
tabelizer.min.css 5KB
datepicker.css 5KB
datepicker.css 5KB
footable.standalone.css 5KB
signin.css 5KB
media.css 5KB
family.css 5KB
slidebars.css 4KB
skin-select.css 4KB
datepicker.css 4KB
scrawl.css 4KB
DT_bootstrap.css 4KB
datepicker.css 4KB
lightbox.css 4KB
bootstrap-timepicker.css 3KB
jquery.news-ticker.css 3KB
green.css 3KB
yellow.css 3KB
red.css 3KB
blue.css 3KB
violet.css 3KB
codemirror.css 3KB
bootstrap-colorpicker.css 3KB
maki-icons.css 3KB
jquery.treeview.css 3KB
profile.css 3KB
charts.css 3KB
jquery.searchableSelect.css 2KB
background.css 2KB
bootstrap-wysihtml5.css 2KB
awwwards.css 2KB
jquery.stepy.css 2KB
responsive-table.css 2KB
emotion.css 2KB
dialogbase.css 2KB
jquery.pnotify.default.css 2KB
music.css 2KB
demo.css 1KB
all.css 1KB
polaris.css 1KB
polaris.css 1KB
acc-wizard.min.css 1KB
jquery.easy-pie-chart.css 1KB
futurico.css 1KB
futurico.css 1KB
pace-theme-center-simple.css 1KB
uploader.css 1KB
edittable.css 1KB
editor.css 1KB
共 816 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
岛上程序猿
- 粉丝: 5639
- 资源: 4236
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功