BAOLH
2025-04-25 6ce655e8911e0b1fd54c3b73cc393154e6045dae
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
@@ -1,18 +1,18 @@
/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service.impl;
import lombok.RequiredArgsConstructor;
@@ -57,10 +57,10 @@
/**
 * @author wcd
 * @website https://eladmin.vip
 * @description 服务实现
 * @date 2022-12-16
 **/
* @website https://eladmin.vip
* @description 服务实现
* @date 2022-12-16
**/
@Service
@RequiredArgsConstructor
public class AttendanceLeaveServiceImpl implements AttendanceLeaveService {
@@ -83,10 +83,10 @@
    private final TemplateControlFieldService templateControlFieldService;
    @Override
    public Map<String, Object> queryAll(AttendanceLeaveQueryCriteria criteria, Pageable pageable) {
        Page<AttendanceLeave> page = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
    public Map<String,Object> queryAll(AttendanceLeaveQueryCriteria criteria, Pageable pageable){
        Page<AttendanceLeave> page = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
        //将实体转换为Dto(重写)
        Function<AttendanceLeave, AttendanceLeaveDto> func = new Function<AttendanceLeave, AttendanceLeaveDto>() {
        Function<AttendanceLeave, AttendanceLeaveDto> func = new Function<AttendanceLeave, AttendanceLeaveDto>(){
            @Override
            public AttendanceLeaveDto apply(AttendanceLeave attendanceLeave) {
@@ -112,7 +112,7 @@
    }
    @Override
    public List<AttendanceLeaveDto> queryAll(AttendanceLeaveQueryCriteria criteria) {
    public List<AttendanceLeaveDto> queryAll(AttendanceLeaveQueryCriteria criteria){
        List<AttendanceLeaveDto> attendanceLeaveDtoList = attendanceLeaveMapper.toDto(attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
        attendanceLeaveDtoList.forEach(attendanceLeaveDto -> {
            //查询用户信息
@@ -129,7 +129,7 @@
    @Transactional
    public AttendanceLeaveDto findById(Long id) {
        AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(id).orElseGet(AttendanceLeave::new);
        ValidationUtil.isNull(attendanceLeave.getId(), "AttendanceLeave", "id", id);
        ValidationUtil.isNull(attendanceLeave.getId(),"AttendanceLeave","id",id);
        return attendanceLeaveMapper.toDto(attendanceLeave);
    }
@@ -141,17 +141,17 @@
        String LeaStartTime = df.format(resources.getLeaveStartTime());
        String LeaEndTime = df.format(resources.getLeaveEndTime());
        // 如果按天为单位请假拼接请假时间的时分秒,取上下班基准时间
        if (resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
        if(resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
            //查询用户的排班时间
            User user = userRepository.getOne(resources.getUserId());
            LeaStartTime = LeaStartTime.substring(0, 10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00";
            LeaEndTime = LeaEndTime.substring(0, 10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00";
            LeaStartTime = LeaStartTime.substring(0,10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00";
            LeaEndTime = LeaEndTime.substring(0,10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00";
        }
        // 查询其他状态的表是否有重复
//        repeatValidation(LeaStartTime, LeaEndTime, resources.getUserId());
        // 验证请假时间是否冲突
        List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(LeaStartTime, LeaEndTime, resources.getUserId());
        if (attendanceLeaveList.size() > 0) {
        List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(LeaStartTime,LeaEndTime, resources.getUserId());
        if(attendanceLeaveList.size() > 0){
            AttendanceLeave errTime = attendanceLeaveList.get(0);
            //LocalDateTime转换为Date
            LocalDateTime strartTime = errTime.getLeaveStartTime().toLocalDateTime();
@@ -166,30 +166,30 @@
            SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            throw new BadRequestException("请假时间冲突," + errorFormat.format(strTime) + "至" + errorFormat.format(endTim)
                    + "已经存在请假记录,请调整时间");
        } else {
        }else {
            // 获取当前登陆人信息,设置为请假发起人
            User user = userRepository.getOne(resources.getUserId());
            User approvalUser = userRepository.getOne(resources.getApprovalUserId());
            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
            // 查询节假日
            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
            for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) {
                if (sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)) {
            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
                    //工作日
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10));
                } else {
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10));
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }else{
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }
            }
            // 循环添加开始时间到结束时间的每一天
            List<String> dateList = getBetweenDate(resources.getLeaveStartTime().toLocalDateTime().toString(), resources.getLeaveEndTime().toLocalDateTime().toString());
            List<String> dateList = getBetweenDate(resources.getLeaveStartTime().toLocalDateTime().toString(),resources.getLeaveEndTime().toLocalDateTime().toString());
            int i = 0;
            for (String date : dateList) {
            for(String date : dateList){
                LocalDate localDate = LocalDate.parse(date);
                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
                // 不是周末并且节假日表中不存在在创建
                if ((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))) {
                    AttendanceLeave attendanceLeave = getAttendanceLeave(resources, date, user, i, LeaStartTime, LeaEndTime, null);
                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
                    AttendanceLeave attendanceLeave = getAttendanceLeave(resources,date,user,i,LeaStartTime,LeaEndTime,null);
                    // 判断是否提交企微审批
                    List<DictDetail> siteTypes = dictDetailRepository.findByDictName(Constant.APPROVAL_SITE_TYPE).stream().filter(siteType -> siteType.getValue().toLowerCase().equals("wecom")).collect(Collectors.toList());
@@ -235,37 +235,37 @@
     * @param LeaEndTime
     * @return
     */
    public AttendanceLeave getAttendanceLeave(AttendanceLeave resources, String date, User user, int i, String LeaStartTime, String LeaEndTime, Long resUserId) {
    public AttendanceLeave getAttendanceLeave(AttendanceLeave resources,String date,User user,int i,String LeaStartTime,String LeaEndTime,Long resUserId){
        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        AttendanceLeave attendanceLeave = new AttendanceLeave();
        //resUserId为null说明是添加,反之
        if (resUserId == null) {
        if(resUserId == null){
            resources.setUserId(user.getId());
        } else {
        }else{
            resources.setUserId(resUserId);
        }
        //日期时间单位是小时
        if (resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)) {
        if(resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)){
            Calculate calculate = new Calculate();
            String startTime = date + " " + LeaStartTime.substring(11, 19);
            String endTime = date + " " + LeaEndTime.substring(11, 19);
            String startTime = date + " " + LeaStartTime.substring(11,19);
            String endTime = date + " " + LeaEndTime.substring(11,19);
            //请假开始时间结束时间不相等的情况
            if (!LeaStartTime.substring(0, 10).equals(LeaEndTime.substring(0, 10))) {
            if(!LeaStartTime.substring(0,10).equals(LeaEndTime.substring(0,10))){
                //第一次循环用下班基准时间和请假开始时间算时长
                if (i == 0) {
                    calculate.setStart(LocalDateTime.parse(startTime, sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00", sdf));
                if(i == 0){
                    calculate.setStart(LocalDateTime.parse(startTime,sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
                    resources.setLeaveStartTime(Timestamp.valueOf(startTime));
                    resources.setLeaveEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
                } else if (date.equals(LeaEndTime.substring(0, 10))) {
                }else if(date.equals(LeaEndTime.substring(0,10))){
                    //最后一次循环
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00", sdf));
                    calculate.setEnd(LocalDateTime.parse(endTime, sdf));
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
                    calculate.setEnd(LocalDateTime.parse(endTime,sdf));
                    resources.setLeaveStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
                    resources.setLeaveEndTime(Timestamp.valueOf(endTime));
                } else {
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00", sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00", sdf));
                }else{
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
                    resources.setLeaveStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
                    resources.setLeaveEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
                }
@@ -273,7 +273,7 @@
                Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                resources.setLeaveDuration(result);
            }
        } else {
        }else{
            String startTime = date + " " + user.getSysRostering().getWorkStartTime() + ":00";
            String endTime = date + " " + user.getSysRostering().getWorkEndTime() + ":00";
            resources.setLeaveStartTime(Timestamp.valueOf(startTime));
@@ -289,11 +289,11 @@
    @Transactional(rollbackFor = Exception.class)
    public void update(AttendanceLeave resources) {
        AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(resources.getId()).orElseGet(AttendanceLeave::new);
        ValidationUtil.isNull(attendanceLeave.getId(), "AttendanceLeave", "id", resources.getId());
        ValidationUtil.isNull( attendanceLeave.getId(),"AttendanceLeave","id",resources.getId());
        attendanceLeave.copy(resources);
        //审核通过或者退回不能删除
        if (attendanceLeave.getApprovalStatus().equals(Constant.APPROVAL_STATUS_PASSED) || attendanceLeave.getApprovalStatus().equals(Constant.APPROVAL_STATUS_RETURNED)) {
        if(attendanceLeave.getApprovalStatus().equals(Constant.APPROVAL_STATUS_PASSED) || attendanceLeave.getApprovalStatus().equals(Constant.APPROVAL_STATUS_RETURNED)){
            throw new BadRequestException("审核通过或退回的不能进行修改");
        }
@@ -301,8 +301,8 @@
        User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
        Role role = user1.getRoles().iterator().next();
        //除超管、总经理只能修改自己信息
        if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
            if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())) {
        if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
            if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
                throw new BadRequestException("只能修改自己的记录");
            }
        }
@@ -311,11 +311,11 @@
        String LeaStartTime = df.format(resources.getLeaveStartTime());
        String LeaEndTime = df.format(resources.getLeaveEndTime());
        // 如果按天为单位请假拼接请假时间的时分秒,取上下班基准时间
        if (resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
        if(resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)){
            //查询用户的排班时间
            User user = userRepository.getOne(resources.getUserId());
            LeaStartTime = LeaStartTime.substring(0, 10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00";
            LeaEndTime = LeaEndTime.substring(0, 10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00";
            LeaStartTime = LeaStartTime.substring(0,10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00";
            LeaEndTime = LeaEndTime.substring(0,10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00";
        }
        // 查询其他状态的表是否有重复
//        repeatValidation(LeaStartTime, LeaEndTime, resources.getUserId());
@@ -326,9 +326,9 @@
        if (attendanceLeaveList.size() > 0) {
            AttendanceLeave errorSysAskForLeave = attendanceLeaveList.get(0);
            SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
            throw new BadRequestException("请假时间冲突," + errorFormat.format(errorSysAskForLeave.getLeaveStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getLeaveEndTime())
                    + "已经存在请假记录,请调整时间");
        } else {
                throw new BadRequestException("请假时间冲突," + errorFormat.format(errorSysAskForLeave.getLeaveStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getLeaveEndTime())
                        + "已经存在请假记录,请调整时间");
        }else{
            //暂存userId
            Long resUserId = attendanceLeave.getUserId();
            // 删除以前的记录
@@ -340,23 +340,23 @@
            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
            // 查询节假日
            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
            for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) {
                if (sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)) {
            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
                    //工作日
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10));
                } else {
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10));
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }else{
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }
            }
            // 循环添加开始时间到结束时间的每一天
            List<String> dateList = getBetweenDate(resources.getLeaveStartTime().toLocalDateTime().toString(), resources.getLeaveEndTime().toLocalDateTime().toString());
            List<String> dateList = getBetweenDate(resources.getLeaveStartTime().toLocalDateTime().toString(),resources.getLeaveEndTime().toLocalDateTime().toString());
            int i = 0;
            for (String date : dateList) {
            for(String date : dateList){
                LocalDate localDate = LocalDate.parse(date);
                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
                // 不是周末并且节假日表中不存在在创建
                if ((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))) {
                    AttendanceLeave attendanceLeave1 = getAttendanceLeave(resources, date, user, i, LeaStartTime, LeaEndTime, resUserId);
                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
                    AttendanceLeave attendanceLeave1 = getAttendanceLeave(resources,date,user,i,LeaStartTime,LeaEndTime,resUserId);
                    i++;
                    attendanceLeaveRepository.save(attendanceLeave1);
                }
@@ -371,18 +371,18 @@
     * @param endTime
     * @param userId
     */
    public void repeatValidation(String startTime, String endTime, Long userId) {
    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())
                    + "已经存在外出记录,请调整时间");
        }
        // 查询出差表
        List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(startTime.substring(0, 10), endTime.substring(0, 10), userId);
        if (attendanceBusinessTravelList.size() > 0) {
        List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(startTime.substring(0,10),endTime.substring(0,10), userId);
        if(attendanceBusinessTravelList.size() > 0){
            AttendanceBusinessTravel errorSysAskForLeave = attendanceBusinessTravelList.get(0);
            SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
            throw new BadRequestException("出差时间冲突," + errorFormat.format(errorSysAskForLeave.getTravelStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getTravelEndTime())
@@ -398,7 +398,7 @@
     * @param endTime
     * @return
     */
    public List<String> getBetweenDate(String startTime, String endTime) {
    public List<String> getBetweenDate(String startTime, String endTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 声明保存日期集合
        List<String> list = new ArrayList<String>();
@@ -409,7 +409,7 @@
            //用Calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime() <= endDate.getTime()) {
            while (startDate.getTime()<=endDate.getTime()) {
                // 把日期添加到集合
                list.add(sdf.format(startDate));
                // 设置日期
@@ -417,7 +417,7 @@
                //把日期增加一天
                calendar.add(Calendar.DATE, 1);
                // 获取增加后的日期
                startDate = calendar.getTime();
                startDate=calendar.getTime();
            }
        } catch (ParseException e) {
            e.printStackTrace();
@@ -438,8 +438,8 @@
        //根据字典名称查询
        List<DictDetail> dictDetailList = dictDetailRepository.findByDictName("leave_type");
        List<String> leaveTypes = new ArrayList<>();
        for (DictDetail dictDetail : dictDetailList) {
            if (dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_REPLACE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE)) {
        for(DictDetail dictDetail : dictDetailList){
            if(dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_REPLACE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE)){
                //事假和年假
                leaveTypes.add(dictDetail.getValue());
            }
@@ -449,11 +449,11 @@
        calculate.setEnd(resources.getLeaveEndTime().toLocalDateTime());
        Double result = new Double(0.00);
        //判断集合是否包含年假或事假,包含计算以时为单位,反之以天为单位进行计算
        if (leaveTypes.contains(resources.getLeaveType())) {
        if(leaveTypes.contains(resources.getLeaveType())){
            Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
            result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            attendanceLeaveDto.setLeaveDurationUnit(Constant.LEAVE_TIME_TYPE_HOUR);
        } else {
        }else{
            Integer days = attendanceService.calculateDays(calculate);
            result = Double.valueOf(new BigDecimal(days).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            attendanceLeaveDto.setLeaveDurationUnit(Constant.LEAVE_TIME_TYPE_DAY);
@@ -475,7 +475,33 @@
            for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
                // 获取今年
                int year = Calendar.getInstance().get(Calendar.YEAR);
                if (!sysUserLevelOther.getYearMonth().isEmpty() && sysUserLevelOther.getYearMonth().substring(0, 4).equals(String.valueOf(year))) {
                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 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);
@@ -495,22 +521,56 @@
     */
    @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;
        }
@@ -522,25 +582,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();
    }
@@ -552,19 +628,19 @@
    @Override
    public void updateApprove(AttendanceLeave resources) throws Exception {
        AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(resources.getId()).orElseGet(AttendanceLeave::new);
        ValidationUtil.isNull(attendanceLeave.getId(), "AttendanceLeave", "id", resources.getId());
        ValidationUtil.isNull( attendanceLeave.getId(),"AttendanceLeave","id",resources.getId());
        attendanceLeave.copy(resources);
        attendanceLeaveRepository.save(attendanceLeave);
        // 调用定时任务修改考勤记录
        List<User> userList = new ArrayList<>();
        if (ObjectUtils.isNotEmpty(attendanceLeave.getUserId())) {
        if(ObjectUtils.isNotEmpty(attendanceLeave.getUserId())){
            User user = userRepository.findById(attendanceLeave.getUserId()).orElseGet(User::new);
            userList.add(user);
        }
        if (attendanceLeave.getLeaveStartTime().before(new Date())) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String attendanceDate = df.format(attendanceLeave.getLeaveStartTime());
            weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
            weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate,userList);
        }
    }
@@ -574,7 +650,7 @@
            //根据id查询记录
            Optional<AttendanceLeave> attendanceLeave = attendanceLeaveRepository.findById(id);
            //审核通过或者退回不能删除
            if (attendanceLeave.get().getApprovalStatus().equals(Constant.APPROVAL_STATUS_PASSED) || attendanceLeave.get().getApprovalStatus().equals(Constant.APPROVAL_STATUS_RETURNED)) {
            if(attendanceLeave.get().getApprovalStatus().equals(Constant.APPROVAL_STATUS_PASSED) || attendanceLeave.get().getApprovalStatus().equals(Constant.APPROVAL_STATUS_RETURNED)){
                throw new BadRequestException("审核通过或退回的不能进行删除");
            }
@@ -584,8 +660,8 @@
            //根据id查询记录
            Optional<AttendanceLeave> attendanceLeave1 = attendanceLeaveRepository.findById(id);
            //除超管、总经理只能删除自己信息
            if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
                if (!Long.valueOf(attendanceLeave1.get().getUserId()).equals(SecurityUtils.getCurrentUserId())) {
            if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
                if (!Long.valueOf(attendanceLeave1.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
                    throw new BadRequestException("只能删除自己的记录");
                }
            }
@@ -603,7 +679,7 @@
        // 循环ID列表
        for (Long id : request.getIds()) {
            AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(id).orElseGet(AttendanceLeave::new);
            ValidationUtil.isNull(attendanceLeave.getId(), "AttendanceLeave", "id", id);
            ValidationUtil.isNull( attendanceLeave.getId(),"AttendanceLeave","id",id);
            if (request.getNum().equals(Long.valueOf(1))) {
                attendanceLeave.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED);
            } else {
@@ -612,13 +688,13 @@
            attendanceLeaveRepository.save(attendanceLeave);
            // 调用定时任务修改考勤记录
            List<User> userList = new ArrayList<>();
            if (ObjectUtils.isNotEmpty(attendanceLeave.getUserId())) {
            if(ObjectUtils.isNotEmpty(attendanceLeave.getUserId())){
                User user = userRepository.findById(attendanceLeave.getUserId()).orElseGet(User::new);
                userList.add(user);
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String attendanceDate = df.format(attendanceLeave.getLeaveStartTime());
            weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
            weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate,userList);
        }
    }
@@ -628,7 +704,7 @@
        for (AttendanceLeaveDto attendanceLeave : all) {
            String leavrType = attendanceLeave.getLeaveType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.LEAVE_TYPE, attendanceLeave.getLeaveType()).getLabel() : "";
            String leaveStatus = attendanceLeave.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVAL_STATUS, attendanceLeave.getApprovalStatus()).getLabel() : "";
            Map<String, Object> map = new LinkedHashMap<>();
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("申请者", attendanceLeave.getUserName());
            map.put("审批者", attendanceLeave.getAppUserName());
            map.put("请假类型", leavrType);