yao-zengchun
2025-05-23 2fca78b4607264e13a11f0deb84c34c9ac9489cc
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
@@ -207,6 +207,68 @@
    }
    /**
     * 计算时间(小时)包含假期
     * @param userId
     * @return
     */
    @Override
    public Integer calcTimesIncludeHoliday(Calculate calculate, Long userId) {
        User userInfo = userRepository.getOne(userId);
        SysRostering sysRostering = userInfo.getSysRostering();
        // 计算天数
        Integer count = 0;
        Long chronoUnit =  ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= chronoUnit; i++) {
            count++;
        }
        Calculate startCalculate = new Calculate();
        startCalculate.setStart(calculate.getStart());
        startCalculate.setEnd(calculate.getStart());
        Integer startDays = 0;
        Long startChronoUnit =  ChronoUnit.DAYS.between(startCalculate.getStart().toLocalDate(), startCalculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= startChronoUnit; i++) {
            startDays++;
        }
        Calculate endCalculate = new Calculate();
        endCalculate.setStart(calculate.getEnd());
        endCalculate.setEnd(calculate.getEnd());
        Integer endDays = 0;
        Long endChronoUnit =  ChronoUnit.DAYS.between(endCalculate.getStart().toLocalDate(), endCalculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= endChronoUnit; i++) {
            endDays++;
        }
        Integer time = 0;
        time = (count - startDays - endDays) * 8 * 3600;
        calculate.setStart(formateDateTime(calculate.getStart(), sysRostering));
        calculate.setEnd(formateDateTime(calculate.getEnd(), sysRostering));
        if (startDays > 0) {
            Duration startDuration = Duration.between(calculate.getStart(), calculate.getStart().toLocalDate().atTime(sysRostering.getWorkEndTime()));
            Long StartSeconds = startDuration.getSeconds();
            if (calculate.getStart().toLocalTime().isBefore(LocalTime.NOON)) {
                time += StartSeconds.intValue() - 3600;
            }else if(calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0){
                // 补充,请假开始时间大于等于中午基准休息时间小于休息结束时间
                time += StartSeconds.intValue() - 3600;
            } else {
                time += StartSeconds.intValue();
            }
        }
        if (endDays > 0) {
            Duration endDuration = Duration.between(calculate.getEnd().toLocalDate().atTime(sysRostering.getWorkStartTime()), calculate.getEnd());
            Long endSeconds = endDuration.getSeconds();
            if (calculate.getEnd().toLocalTime().isAfter(LocalTime.NOON)) {
                time += endSeconds.intValue() - 3600;
            } else {
                time += endSeconds.intValue();
            }
        }
        return time;
    }
    /**
     * 计算时间(天)
     * @param calculate
     * @return