yaozc2021
2025-03-13 908298c5ee4c87ca8575d7088050e7170a124724
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
@@ -336,7 +336,7 @@
    public void repeatValidation(String startTime, String endTime, Long userId){
        // 查询外出表
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(startTime, endTime, userId);
        if(attendanceGoOutList.size() > 0){
        if(attendanceGoOutList.size() > 0) {
            AttendanceGoOut errorSysAskForLeave = attendanceGoOutList.get(0);
            SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
            throw new BadRequestException("外出时间冲突," + errorFormat.format(errorSysAskForLeave.getOutStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getOutEndTime())
@@ -370,7 +370,7 @@
            //用Calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime()<=endDate.getTime()){
            while (startDate.getTime()<=endDate.getTime()) {
                // 把日期添加到集合
                list.add(sdf.format(startDate));
                // 设置日期
@@ -451,26 +451,86 @@
    }
    /**
     * 获取用户年假剩余时长
     */
    @Override
    public Double getYearTimeLength(Long userId, String year) {
        //获取年假剩余(新)
        Double surplusYearTime = new Double(0.00);
        // 根据用户查询
        List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
        if (sysUserLevelOtherList.size() > 0) {
            for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
                if (!sysUserLevelOther.getYearMonth().isEmpty() && sysUserLevelOther.getYearMonth().substring(0,4).equals(String.valueOf(year))) {
                    //年假总时长
                    Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
                    String startTime = year + "-01-01 00:00:00";
                    String endTime = year + "-12-31 23:59:59";
                    Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime);
                    surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime);
                }
            }
        }
        return surplusYearTime;
    }
    /**
     * 获取用户调休假剩余时长
     */
    @Override
    public Double getOverTimeLength(Long userId) {
        //获取调休假剩余时长
        Double surplusYearTime = new Double(0.00);
        LocalDate localDateStart = LocalDate.now().withDayOfMonth(1).minusMonths(3);
        LocalDate localDateEnd = LocalDate.now().plusDays(1);
        List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay());
        if (!attendanceOvertimeList.isEmpty()) {
            surplusYearTime = attendanceOvertimeList.stream()
                    .filter(attendanceOvertime -> !attendanceOvertime.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS))
                    .map(attendanceOvertime -> attendanceOvertime.getOvertimeDuration()).reduce(0.0, (o1, o2) -> o1 + o2);
            Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
            if (usedTime > 0) {
                surplusYearTime = surplusYearTime - usedTime;
            }
        LocalDate localDateStart = LocalDate.of(2024, 1, 1);
        LocalDate localDateMiddle = LocalDate.now().withDayOfMonth(1).minusMonths(3);
        Double overTimeLast = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateStart.atStartOfDay(), localDateMiddle.atStartOfDay()); // TODO
        if (overTimeLast == null) {
            overTimeLast = 0.0;
        }
        LocalDate localDateEnd = LocalDate.now().plusMonths(1).withDayOfMonth(1);
        Double surplusYearTime = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateMiddle.atStartOfDay(), localDateEnd.atStartOfDay());
        if (surplusYearTime == null) {
            surplusYearTime = 0.0;
        }
        Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
        if (usedTime == null) {
            usedTime = 0.0;
        }
        if (overTimeLast > usedTime) {
            return surplusYearTime;
        }
        surplusYearTime = surplusYearTime + overTimeLast - usedTime;
        if (surplusYearTime <= 0.0) {
            return 0.0;
        }
        return BigDecimal.valueOf(surplusYearTime).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    @Override
    public Double getOverTimeLength(Long userId, String yearMonth) {
        LocalDate localDateStart = LocalDate.of(2024, 1, 1);
        LocalDate localDateMiddle = LocalDate.parse(yearMonth + "-01").minusMonths(3);
        Double overTimeLast = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateStart.atStartOfDay(), localDateMiddle.atStartOfDay()); // TODO
        if (overTimeLast == null) {
            overTimeLast = 0.0;
        }
        LocalDate localDateEnd = LocalDate.parse(yearMonth + "-01").plusMonths(1).withDayOfMonth(1);
        Double surplusYearTime = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateMiddle.atStartOfDay(), localDateEnd.atStartOfDay());
        if (surplusYearTime == null) {
            surplusYearTime = 0.0;
        }
        Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
        if (usedTime == null) {
            usedTime = 0.0;
        }
        if (overTimeLast > usedTime) {
            return surplusYearTime;
        }
        surplusYearTime = surplusYearTime + overTimeLast - usedTime;
        if (surplusYearTime <= 0.0) {
            return 0.0;
        }
@@ -482,26 +542,41 @@
     */
    @Override
    public Double getOverTimeCloseLength(Long userId) {
        //获取年假剩余(新)
        Double surplusYearTime = new Double(0.00);
        LocalDate localDateStart = LocalDate.now().withDayOfMonth(1).minusMonths(4);
        LocalDate localDateEnd = LocalDate.now().plusDays(1);
        List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, localDateStart.atStartOfDay(), localDateStart.plusMonths(1).withDayOfMonth(1).atStartOfDay());
        if (!attendanceOvertimeList.isEmpty()) {
            surplusYearTime = attendanceOvertimeList.stream()
                    .filter(attendanceOvertime -> !attendanceOvertime.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS))
                    .map(attendanceOvertime -> attendanceOvertime.getOvertimeDuration()).reduce(0.0, (o1, o2) -> o1 + o2);
            Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
            if (usedTime > 0) {
                surplusYearTime = surplusYearTime - usedTime;
            }
        LocalDate localDateStart = LocalDate.of(2024, 1, 1);
        LocalDate localDateMiddle = LocalDate.now().withDayOfMonth(1).minusMonths(3);
        Double surplusYearTime = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateStart.atStartOfDay(), localDateMiddle.atStartOfDay()); // TODO
        if (surplusYearTime == null) {
            surplusYearTime = 0.0;
        }
        if (surplusYearTime <= 0.0) {
        LocalDate localDateEnd = LocalDate.now().plusMonths(1).withDayOfMonth(1);
        Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
        if (usedTime == null) {
            usedTime = 0.0;
        }
        if (surplusYearTime <= usedTime) {
            return 0.0;
        }
        surplusYearTime = surplusYearTime - usedTime;
        return BigDecimal.valueOf(surplusYearTime).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    @Override
    public Double getOverTimeCloseLength(Long userId, String yearMonth) {
        LocalDate localDateStart = LocalDate.of(2024, 1, 1);
        LocalDate localDateMiddle = LocalDate.parse(yearMonth + "-01").minusMonths(3);
        Double surplusYearTime = attendanceOvertimeRepository.findByUserIdAndYearMonth(userId, localDateStart.atStartOfDay(), localDateMiddle.atStartOfDay()); // TODO
        if (surplusYearTime == null) {
            surplusYearTime = 0.0;
        }
        LocalDate localDateEnd = LocalDate.parse(yearMonth + "-01").plusMonths(1).withDayOfMonth(1);
        Double usedTime = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(userId, localDateStart.atStartOfDay(), localDateEnd.atStartOfDay(), Constant.LEAVE_TYPE_REPLACE).stream().mapToDouble(AttendanceLeave::getLeaveDuration).sum();
        if (usedTime == null) {
            usedTime = 0.0;
        }
        if (surplusYearTime <= usedTime) {
            return 0.0;
        }
        surplusYearTime = surplusYearTime - usedTime;
        return BigDecimal.valueOf(surplusYearTime).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }