Explorar el Código

修改打卡逻辑

main
1341924763@qq.com hace 1 día
padre
commit
c24fdec270

+ 34
- 34
zs-manager/src/main/java/com/ruoyi/zhushi/job/DkJob.java Ver fichero

@@ -22,50 +22,50 @@ public class DkJob {
private DkRecordMapper dkRecordMapper;

// 每天18执行
@Scheduled(cron = "0 0 18 * * ?")
@Scheduled(cron = "0 0 2 * * ?")
// @Scheduled(cron = "0/10 * * * * ?")
public void executeTask() throws ParseException {
// 任务逻辑
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
try {
// 判断当天时间是否为节假日,为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());
// 具体任务逻辑

+ 19
- 10
zs-manager/src/main/java/com/ruoyi/zhushi/service/impl/DkAppServiceImpl.java Ver fichero

@@ -32,13 +32,13 @@ public class DkAppServiceImpl implements DkAppService {
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();
if(workStartTime == null){
@@ -56,6 +56,14 @@ public class DkAppServiceImpl implements DkAppService {
boolean result = canSignIn(workStartTime);
// 初始化打卡记录对象
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){
// 允许迟到打卡
@@ -85,7 +93,7 @@ public class DkAppServiceImpl implements DkAppService {
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId());
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName());

dkRecordMapper.insert(dkCheckInRecord);
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "迟到打卡";
}
dkCheckInRecord.setSysUserId(appDTO.getUserId());
@@ -107,7 +115,7 @@ public class DkAppServiceImpl implements DkAppService {
dkCheckInRecord.setDescription(appDTO.getDescription());
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId());
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName());
dkRecordMapper.insert(dkCheckInRecord);
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功";
}else{
dkCheckInRecord.setSysUserId(appDTO.getUserId());
@@ -128,7 +136,7 @@ public class DkAppServiceImpl implements DkAppService {
dkCheckInRecord.setDescription(appDTO.getDescription());
dkCheckInRecord.setAttendanceGroupId(appDTO.getAttendanceGroupId());
dkCheckInRecord.setAttendanceGroupName(appDTO.getAttendanceGroupName());
dkRecordMapper.insert(dkCheckInRecord);
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "迟到打卡";
}
}
@@ -214,6 +222,7 @@ public class DkAppServiceImpl implements DkAppService {
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
// queryWrapper.eq(DkCheckInRecord::getCheckInType, "clockOut");
// queryWrapper.isNotNull(DkCheckInRecord::getClockOut);
queryWrapper.apply("DATE(check_in_time) = DATE(NOW())");
queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime);

// 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录

+ 87
- 87
zs-manager/src/main/java/com/ruoyi/zhushi/service/impl/DkRecordServiceImpl.java Ver fichero

@@ -367,51 +367,51 @@ public class DkRecordServiceImpl implements DkRecordService {
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());
@@ -770,51 +770,51 @@ public class DkRecordServiceImpl implements DkRecordService {
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());

+ 1
- 1
zs-manager/src/main/resources/mapper/DkRecordMapper.xml Ver fichero

@@ -24,7 +24,7 @@
</if>

<if test="currentDate != null ">
AND create_time = #{currentDate}
AND DATE(create_time) = #{currentDate}
</if>
</where>
</select>

Cargando…
Cancelar
Guardar