云
6 天以前 c7673b8c8f1d20c58c7265fa00c6fbf69caf994d
fix(shift): 修复排班与考勤的时间范围查询条件

- 修改考勤记录查询,将排班时间精确匹配改为全天范围匹配
- 修改排班存在性校验,将跨月和不跨月的时间匹配改为整月范围
- 优化排班数据更新逻辑,使用当天起止时间范围替代精确时间匹配
- 解决因时间精度问题导致的排班与考勤数据查询或更新遗漏
已修改2个文件
25 ■■■■■ 文件已修改
src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/staff/service/impl/PersonalShiftServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java
@@ -71,7 +71,8 @@
        //判断判断员工当天是否有排班数据
        List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery()
                .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId())
                .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay())
                .ge(PersonalShift::getWorkTime, currentDate.atStartOfDay())
                .lt(PersonalShift::getWorkTime, currentDate.plusDays(1).atStartOfDay())
                .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId)
                .ne(PersonalShift::getPersonalAttendanceLocationConfigId, 999));
        if (CollectionUtil.isEmpty(personalShifts)){
@@ -230,7 +231,8 @@
        //获取该员工对应的打卡规则
        List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery()
                .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId())
                .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay())
                .ge(PersonalShift::getWorkTime, currentDate.atStartOfDay())
                .lt(PersonalShift::getWorkTime, currentDate.plusDays(1).atStartOfDay())
                .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId)
                .ne(PersonalShift::getPersonalAttendanceLocationConfigId, 999));
        if (CollectionUtil.isNotEmpty(personalShifts)){
src/main/java/com/ruoyi/staff/service/impl/PersonalShiftServiceImpl.java
@@ -53,19 +53,21 @@
        LocalDateTime endWeek = performanceShiftAddDto.getEndWeek();//结束日期
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter);
        String[] splitUserId = performanceShiftAddDto.getStaffOnJobId().split(",");
        for (String userId : splitUserId) {
            //判断是否跨月
            boolean isMonth = startWeek.getMonthValue() != endWeek.getMonthValue();
            if (isMonth){
                //如果跨月,则两个月都判断一下看数据库是哪个月份的数据没有
                LocalDateTime startMonthBegin = startWeek.toLocalDate().withDayOfMonth(1).atStartOfDay();
                LocalDateTime endMonthBegin = endWeek.toLocalDate().withDayOfMonth(1).atStartOfDay();
                boolean exists1 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .eq(PersonalShift::getWorkTime, startWeek)
                        .ge(PersonalShift::getWorkTime, startMonthBegin)
                        .lt(PersonalShift::getWorkTime, startMonthBegin.plusMonths(1))
                        .eq(PersonalShift::getStaffOnJobId, userId));
                boolean exists2 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .eq(PersonalShift::getWorkTime, endWeek)
                        .ge(PersonalShift::getWorkTime, endMonthBegin)
                        .lt(PersonalShift::getWorkTime, endMonthBegin.plusMonths(1))
                        .eq(PersonalShift::getStaffOnJobId, userId));
                if (!exists1 && !exists2){
                    //两个月都不存在数据
@@ -80,8 +82,10 @@
                }
            }else {
                //不跨月
                LocalDateTime monthBegin = startWeek.toLocalDate().withDayOfMonth(1).atStartOfDay();
                boolean exists = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery()
                        .in(PersonalShift::getWorkTime, formattedDateTime)
                        .ge(PersonalShift::getWorkTime, monthBegin)
                        .lt(PersonalShift::getWorkTime, monthBegin.plusMonths(1))
                        .eq(PersonalShift::getStaffOnJobId, userId));
                // 如果不存在添加数据
                if (!exists) {
@@ -96,16 +100,17 @@
        // 再次更新
        List<LocalDateTime> datesBetween = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek());
        for (LocalDateTime date : datesBetween) {
            LocalDateTime dayBegin = date.toLocalDate().atStartOfDay();
            for (String s : splitUserId) {
                PersonalShift personalShift = new PersonalShift();
                personalShift.setPersonalAttendanceLocationConfigId(performanceShiftAddDto.getPersonalAttendanceLocationConfigId());
                personalShift.setStaffOnJobId(Long.valueOf(s));
                personalShift.setWorkTime(date);
                String formatterDateTime = date.format(formatter);
                baseMapper.update(new PersonalShift(), Wrappers.<PersonalShift>lambdaUpdate()
                        .set(PersonalShift::getPersonalAttendanceLocationConfigId, performanceShiftAddDto.getPersonalAttendanceLocationConfigId())
                        .eq(PersonalShift::getStaffOnJobId, s)
                        .eq(PersonalShift::getWorkTime, formatterDateTime));
                        .ge(PersonalShift::getWorkTime, dayBegin)
                        .lt(PersonalShift::getWorkTime, dayBegin.plusDays(1)));
            }
        }
        return 0;