private DkRecordMapper dkRecordMapper; | private DkRecordMapper dkRecordMapper; | ||||
// 每天18执行 | // 每天18执行 | ||||
@Scheduled(cron = "0 0 18 * * ?") | |||||
@Scheduled(cron = "0 0 2 * * ?") | |||||
// @Scheduled(cron = "0/10 * * * * ?") | // @Scheduled(cron = "0/10 * * * * ?") | ||||
public void executeTask() throws ParseException { | public void executeTask() throws ParseException { | ||||
// 任务逻辑 | // 任务逻辑 | ||||
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); | System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); | ||||
try { | try { | ||||
// 判断当天时间是否为节假日,为0的时候是工作日 | // 判断当天时间是否为节假日,为0的时候是工作日 | ||||
String yearHoliday = HolidayUtil.isWorkingDay(LocalDate.now().toString()); | |||||
if(yearHoliday.equals("0")){ | |||||
// String yearHoliday = HolidayUtil.isWorkingDay(LocalDate.now().toString()); | |||||
// if(yearHoliday.equals("0")){ | |||||
// 获取所有员工 | // 获取所有员工 | ||||
List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers(); | |||||
for (JSONObject jsonObject : jsonObjects) { | |||||
// 获取员工id | |||||
Long userId = jsonObject.getLong("userId"); | |||||
// 如果没有员工id,则跳过 | |||||
if (userId == null){ | |||||
continue; | |||||
} | |||||
// 获取员工姓名 | |||||
String userName = jsonObject.getString("userName"); | |||||
// 根据userId 查询考勤组信息 | |||||
DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId); | |||||
// 如果没有考勤组信息,则跳过 | |||||
if(appDTO == null){ | |||||
continue; | |||||
} | |||||
// 获取员工打卡记录根据员工id | |||||
List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId); | |||||
if(records == null || records.size() == 0){ | |||||
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); | |||||
dkCheckInRecord.setSysUserId(userId); | |||||
dkCheckInRecord.setSysUserName(userName); | |||||
dkCheckInRecord.setCheckInTime(LocalDateTime.now()); | |||||
dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setAttendanceGroupId(appDTO.getId()); | |||||
dkCheckInRecord.setAttendanceGroupName(appDTO.getName()); | |||||
dkRecordMapper.insertOrUpdate(dkCheckInRecord); | |||||
} | |||||
List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers(); | |||||
for (JSONObject jsonObject : jsonObjects) { | |||||
// 获取员工id | |||||
Long userId = jsonObject.getLong("userId"); | |||||
// 如果没有员工id,则跳过 | |||||
if (userId == null){ | |||||
continue; | |||||
} | |||||
// 获取员工姓名 | |||||
String userName = jsonObject.getString("userName"); | |||||
// 根据userId 查询考勤组信息 | |||||
DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId); | |||||
// 如果没有考勤组信息,则跳过 | |||||
if(appDTO == null){ | |||||
continue; | |||||
} | } | ||||
// 获取员工打卡记录根据员工id | |||||
// List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId); | |||||
// if(records == null || records.size() == 0){ | |||||
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); | |||||
dkCheckInRecord.setSysUserId(userId); | |||||
dkCheckInRecord.setSysUserName(userName); | |||||
dkCheckInRecord.setCheckInTime(LocalDateTime.now()); | |||||
dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0); | |||||
dkCheckInRecord.setAttendanceGroupId(appDTO.getId()); | |||||
dkCheckInRecord.setAttendanceGroupName(appDTO.getName()); | |||||
dkRecordMapper.insertOrUpdate(dkCheckInRecord); | |||||
// } | |||||
} | } | ||||
// } | |||||
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); | System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); | ||||
// 具体任务逻辑 | // 具体任务逻辑 |
AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId()); | AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId()); | ||||
// 判断是否已经打卡,如果已经打卡,则不允许再次打卡 | // 判断是否已经打卡,如果已经打卡,则不允许再次打卡 | ||||
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>(); | |||||
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); | |||||
queryWrapper.apply("DATE(check_in_time) = DATE(NOW())"); | |||||
List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper); | |||||
if (dkCheckInRecords.size() > 0){ | |||||
return "已经打卡,不允许重复打卡!"; | |||||
} | |||||
// LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>(); | |||||
// queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); | |||||
// queryWrapper.apply("DATE(check_in_time) = DATE(NOW())"); | |||||
// List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper); | |||||
// if (dkCheckInRecords.size() > 0){ | |||||
// return "已经打卡,不允许重复打卡!"; | |||||
// } | |||||
// 打卡开始时间 | // 打卡开始时间 | ||||
String workStartTime = appDTO1.getWorkStartTime(); | String workStartTime = appDTO1.getWorkStartTime(); | ||||
if(workStartTime == null){ | if(workStartTime == null){ | ||||
boolean result = canSignIn(workStartTime); | boolean result = canSignIn(workStartTime); | ||||
// 初始化打卡记录对象 | // 初始化打卡记录对象 | ||||
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); | DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); | ||||
LambdaQueryWrapper<DkCheckInRecord> queryWrapper1 = new LambdaQueryWrapper<>(); | |||||
queryWrapper1.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); | |||||
queryWrapper1.apply("DATE(check_in_time) = DATE(NOW())"); | |||||
// queryWrapper1.isNotNull(DkCheckInRecord::getClockIn); | |||||
List<DkCheckInRecord> dkCheckInRecords1 = dkRecordMapper.selectList(queryWrapper1); | |||||
if(dkCheckInRecords1.size() > 0){ | |||||
dkCheckInRecord = dkCheckInRecords1.get(0); | |||||
} | |||||
if(!result){ | if(!result){ | ||||
// 允许迟到打卡 | // 允许迟到打卡 | ||||
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | ||||
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | ||||
dkRecordMapper.insert(dkCheckInRecord); | |||||
dkRecordMapper.insertOrUpdate(dkCheckInRecord); | |||||
return "迟到打卡"; | return "迟到打卡"; | ||||
} | } | ||||
dkCheckInRecord.setSysUserId(appDTO.getUserId()); | dkCheckInRecord.setSysUserId(appDTO.getUserId()); | ||||
dkCheckInRecord.setDescription(appDTO.getDescription()); | dkCheckInRecord.setDescription(appDTO.getDescription()); | ||||
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | ||||
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | ||||
dkRecordMapper.insert(dkCheckInRecord); | |||||
dkRecordMapper.insertOrUpdate(dkCheckInRecord); | |||||
return "打卡成功"; | return "打卡成功"; | ||||
}else{ | }else{ | ||||
dkCheckInRecord.setSysUserId(appDTO.getUserId()); | dkCheckInRecord.setSysUserId(appDTO.getUserId()); | ||||
dkCheckInRecord.setDescription(appDTO.getDescription()); | dkCheckInRecord.setDescription(appDTO.getDescription()); | ||||
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId()); | ||||
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName()); | ||||
dkRecordMapper.insert(dkCheckInRecord); | |||||
dkRecordMapper.insertOrUpdate(dkCheckInRecord); | |||||
return "迟到打卡"; | return "迟到打卡"; | ||||
} | } | ||||
} | } | ||||
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); | queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); | ||||
// queryWrapper.eq(DkCheckInRecord::getCheckInType, "clockOut"); | // queryWrapper.eq(DkCheckInRecord::getCheckInType, "clockOut"); | ||||
// queryWrapper.isNotNull(DkCheckInRecord::getClockOut); | // queryWrapper.isNotNull(DkCheckInRecord::getClockOut); | ||||
queryWrapper.apply("DATE(check_in_time) = DATE(NOW())"); | |||||
queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime); | queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime); | ||||
// 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录 | // 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录 |
earlyCount ++; | earlyCount ++; | ||||
} | } | ||||
} | } | ||||
if(dk.getClockIn() == null && dk.getClockOut() == null){ | |||||
dayRecord.setRemark("缺卡"); | |||||
} | |||||
// if(dk.getClockIn() == null && dk.getClockOut() == null){ | |||||
// dayRecord.setRemark("缺卡"); | |||||
// } | |||||
// 判断是否为休假日加班 | // 判断是否为休假日加班 | ||||
if(Constans.EXPORT_ZHOULIU==week || Constans.EXPORT_ZHOURI== week){ | |||||
if(dk.getClockIn() != null && dk.getClockOut() != null){ | |||||
dayRecord.setXiuxiri("*"); | |||||
dayRecord.setRemark("加班1次"); | |||||
// 计算时间差 | |||||
Duration duration = Duration.between(dk.getClockIn(), dk.getClockOut()); | |||||
// 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
if(hours1 >= 30){ | |||||
BigDecimal a = new BigDecimal(hours1); | |||||
BigDecimal b = new BigDecimal("60"); | |||||
// 执行除法,指定精度和舍入模式 | |||||
BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
restOverTime = restOverTime.add(result); | |||||
} | |||||
} | |||||
}else { | |||||
// 判断是否为工作日加班 | |||||
if(dk.getClockOut() != null){ | |||||
if(dk.getClockOut().isAfter(workEndTime1)){ | |||||
// 计算时间差 | |||||
Duration duration = Duration.between(workEndTime1, dk.getClockOut()); | |||||
// 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
if(hours1 >= 30){ | |||||
BigDecimal a = new BigDecimal(hours1); | |||||
BigDecimal b = new BigDecimal("60"); | |||||
// 执行除法,指定精度和舍入模式 | |||||
BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
dayRecord.setGongzuori("*"); | |||||
dayRecord.setRemark("加班1次:" + result + "小时"); | |||||
workOverTime = workOverTime.add(result); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// if(Constans.EXPORT_ZHOULIU==week || Constans.EXPORT_ZHOURI== week){ | |||||
// if(dk.getClockIn() != null && dk.getClockOut() != null){ | |||||
// dayRecord.setXiuxiri("*"); | |||||
// dayRecord.setRemark("加班1次"); | |||||
// // 计算时间差 | |||||
// Duration duration = Duration.between(dk.getClockIn(), dk.getClockOut()); | |||||
// // 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
// long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
// | |||||
// if(hours1 >= 30){ | |||||
// BigDecimal a = new BigDecimal(hours1); | |||||
// BigDecimal b = new BigDecimal("60"); | |||||
// // 执行除法,指定精度和舍入模式 | |||||
// BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
// restOverTime = restOverTime.add(result); | |||||
// } | |||||
// } | |||||
// }else { | |||||
// // 判断是否为工作日加班 | |||||
// if(dk.getClockOut() != null){ | |||||
// if(dk.getClockOut().isAfter(workEndTime1)){ | |||||
// // 计算时间差 | |||||
// Duration duration = Duration.between(workEndTime1, dk.getClockOut()); | |||||
// // 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
// long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
// | |||||
// if(hours1 >= 30){ | |||||
// BigDecimal a = new BigDecimal(hours1); | |||||
// BigDecimal b = new BigDecimal("60"); | |||||
// // 执行除法,指定精度和舍入模式 | |||||
// BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
// dayRecord.setGongzuori("*"); | |||||
// dayRecord.setRemark("加班1次:" + result + "小时"); | |||||
// | |||||
// workOverTime = workOverTime.add(result); | |||||
// } | |||||
// } | |||||
// } | |||||
// } | |||||
// 判断是否为法定节假日加班 | // 判断是否为法定节假日加班 | ||||
// // 获取法定节假日时间 | // // 获取法定节假日时间 | ||||
// List<LocalDate> holidays = getHolidays(LocalDate.now().getYear()); | // List<LocalDate> holidays = getHolidays(LocalDate.now().getYear()); | ||||
earlyCount ++; | earlyCount ++; | ||||
} | } | ||||
} | } | ||||
if(dk.getClockIn() == null && dk.getClockOut() == null){ | |||||
dayRecord.setRemark("缺卡"); | |||||
} | |||||
// 判断是否为休假日加班 | |||||
if(Constans.EXPORT_ZHOULIU==week || Constans.EXPORT_ZHOURI==week){ | |||||
if(dk.getClockIn() != null && dk.getClockOut() != null){ | |||||
dayRecord.setXiuxiri("*"); | |||||
dayRecord.setRemark("加班1次"); | |||||
// 计算时间差 | |||||
Duration duration = Duration.between(dk.getClockIn(), dk.getClockOut()); | |||||
// 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
if(hours1 >= 30){ | |||||
BigDecimal a = new BigDecimal(hours1); | |||||
BigDecimal b = new BigDecimal("60"); | |||||
// 执行除法,指定精度和舍入模式 | |||||
BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
restOverTime = restOverTime.add(result); | |||||
} | |||||
} | |||||
}else{ | |||||
// 判断是否为工作日加班 | |||||
if(dk.getClockOut() != null){ | |||||
if(dk.getClockOut().isAfter(workEndTime1)){ | |||||
// 计算时间差 | |||||
Duration duration = Duration.between(workEndTime1, dk.getClockOut()); | |||||
// 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
if(hours1 >= 30){ | |||||
BigDecimal a = new BigDecimal(hours1); | |||||
BigDecimal b = new BigDecimal("60"); | |||||
// 执行除法,指定精度和舍入模式 | |||||
BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
dayRecord.setGongzuori("*"); | |||||
dayRecord.setRemark("加班1次:" + result + "小时"); | |||||
workOverTime = workOverTime.add(result); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// if(dk.getClockIn() == null && dk.getClockOut() == null){ | |||||
// dayRecord.setRemark("缺卡"); | |||||
// } | |||||
// // 判断是否为休假日加班 | |||||
// if(Constans.EXPORT_ZHOULIU==week || Constans.EXPORT_ZHOURI==week){ | |||||
// if(dk.getClockIn() != null && dk.getClockOut() != null){ | |||||
// dayRecord.setXiuxiri("*"); | |||||
// dayRecord.setRemark("加班1次"); | |||||
// // 计算时间差 | |||||
// Duration duration = Duration.between(dk.getClockIn(), dk.getClockOut()); | |||||
// // 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
// long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
// | |||||
// if(hours1 >= 30){ | |||||
// BigDecimal a = new BigDecimal(hours1); | |||||
// BigDecimal b = new BigDecimal("60"); | |||||
// // 执行除法,指定精度和舍入模式 | |||||
// BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
// restOverTime = restOverTime.add(result); | |||||
// } | |||||
// } | |||||
// }else{ | |||||
// // 判断是否为工作日加班 | |||||
// if(dk.getClockOut() != null){ | |||||
// if(dk.getClockOut().isAfter(workEndTime1)){ | |||||
// // 计算时间差 | |||||
// Duration duration = Duration.between(workEndTime1, dk.getClockOut()); | |||||
// // 获取小时差(注意:此方法会舍去分钟和秒部分) | |||||
// long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟) | |||||
// | |||||
// if(hours1 >= 30){ | |||||
// BigDecimal a = new BigDecimal(hours1); | |||||
// BigDecimal b = new BigDecimal("60"); | |||||
// // 执行除法,指定精度和舍入模式 | |||||
// BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP); | |||||
// dayRecord.setGongzuori("*"); | |||||
// dayRecord.setRemark("加班1次:" + result + "小时"); | |||||
// | |||||
// workOverTime = workOverTime.add(result); | |||||
// } | |||||
// } | |||||
// } | |||||
// } | |||||
// 判断是否为法定节假日加班 | // 判断是否为法定节假日加班 | ||||
// // 获取法定节假日时间 | // // 获取法定节假日时间 | ||||
// List<LocalDate> holidays = getHolidays(LocalDate.now().getYear()); | // List<LocalDate> holidays = getHolidays(LocalDate.now().getYear()); |
</if> | </if> | ||||
<if test="currentDate != null "> | <if test="currentDate != null "> | ||||
AND create_time = #{currentDate} | |||||
AND DATE(create_time) = #{currentDate} | |||||
</if> | </if> | ||||
</where> | </where> | ||||
</select> | </select> |