123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package com.ruoyi.system.service;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.HolidayUtils;
- import com.ruoyi.system.domain.AttendanceTime;
- import com.ruoyi.system.domain.KaoqinRecord;
- import com.ruoyi.system.mapper.AttendanceTimeMapper;
- import com.ruoyi.system.mapper.KaoqinRecordMapper;
- import com.ruoyi.system.mapper.SysUserMapper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- @Component
- public class Task {
- @Autowired
- private SysUserMapper userMapper;
- @Autowired
- private KaoqinRecordMapper kaoqinRecordMapper;
- @Autowired
- private AttendanceTimeMapper attendanceTimeMapper;
- /***
- * 定时插入未打卡数据
- */
- @Async
- //@Scheduled(cron = "0 0/2 * * * ? ")
- @Scheduled(cron = "0 1 0 * * ? ")
- public void thirdNucleicAcid() {
- String day = DateUtils.getDate();
- //获取前一天的日期
- String data = DateUtils.plusSeconds(DateUtils.getDate(),-1,"yyyy-MM-dd");
- //判断当天天是否是法定节假日 0 上班 1周末 2节假日
- String jsonResult = HolidayUtils.request(data);
- if(!"0".equals(jsonResult)){
- //是节假日的话不需要插入数据,直接返回
- return;
- }
- //查询考勤规则
- AttendanceTime attendanceTime = new AttendanceTime();
- List<AttendanceTime> attendanceTimes = attendanceTimeMapper.selectAttendanceTimeList(attendanceTime);
- //根据部门分类
- //Map<Long, List<AttendanceTime>> collect = attendanceTimes.stream().collect(Collectors.groupingBy(AttendanceTime::getDeptId));
- //获取所有有部门的人员
- List<SysUser> userList = userMapper.selectUserListNoDept();
- //获取前一天的所有考勤记录
- KaoqinRecord kaoqinRecord = new KaoqinRecord();
- kaoqinRecord.setKaTime(data);
- List<KaoqinRecord> kaoqinRecordList = kaoqinRecordMapper.selectKaoqinRecordList(kaoqinRecord);
- for (SysUser sysUser : userList) {
- boolean blt = false;
- if(attendanceTimes != null && !attendanceTimes.isEmpty()){
- for (AttendanceTime time : attendanceTimes) {
- if(time.getDeptName().contains(sysUser.getDept().getDeptName()) && DateUtils.isDateBetween(DateUtils.convertStringToDate(data), time.getStartTime(), time.getEndTime())){
- blt = true;
- break;
- }
- }
- }
- if(!blt){
- continue;
- }
- boolean bl = true;
- for (KaoqinRecord record : kaoqinRecordList) {
- if(record.getUserId().equals(sysUser.getUserId())){
- bl = false;
- }
- }
- if(bl){
- //将日期拆分成年月日的数组
- String[] datas = data.split("-");
- KaoqinRecord kaoqinRecords = new KaoqinRecord();
- kaoqinRecords.setUserId(sysUser.getUserId());
- kaoqinRecords.setUserName(sysUser.getNickName());
- kaoqinRecords.setPhone(sysUser.getPhonenumber());
- kaoqinRecords.setDeptId(sysUser.getDeptId());
- kaoqinRecords.setDeptName(sysUser.getDept().getDeptName());
- kaoqinRecords.setAncestors(sysUser.getDept().getAncestors());
- kaoqinRecords.setKaYear(datas[0]);
- kaoqinRecords.setKaMonth(datas[1]);
- kaoqinRecords.setKaDay(datas[2]);
- kaoqinRecords.setKaWeek(DateUtils.dateToWeek(data));
- kaoqinRecords.setKaTime(data);
- kaoqinRecords.setKaTypeAmIn("5");
- kaoqinRecords.setKaTypeAmOut("5");
- kaoqinRecords.setKaTypePmIn("5");
- kaoqinRecords.setKaTypePmOut("5");
- kaoqinRecords.setKaStatus("2");
- kaoqinRecords.setCreateTime(DateUtils.getNowDate());
- kaoqinRecordMapper.insertKaoqinRecord(kaoqinRecords);
- }
- }
- }
- //0 上班 1周末 2节假日
- /*public static void main(String[] args) {
- String data = DateUtils.plusSeconds(DateUtils.getDate(),-1,"yyyy-MM-dd");
- System.out.println(data);
- }*/
- }
|