BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
@@ -40,12 +40,13 @@
import me.zhengjie.modules.treatment.domain.UserLevelWage;
import me.zhengjie.modules.treatment.repository.UserInsuranceRepository;
import me.zhengjie.modules.treatment.repository.UserLevelWageRepository;
import me.zhengjie.utils.DateUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.StringUtils;
import me.zhengjie.weixin.cp.api.WxCpOaWeDocSmartsheetService;
import me.zhengjie.weixin.cp.bean.smartsheet.field.*;
import me.zhengjie.weixin.cp.bean.smartsheet.record.*;
import me.zhengjie.weixin.cp.bean.smartsheet.sheet.*;
import me.zhengjie.modules.weixin.cp.api.WxCpOaWeDocSmartsheetService;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.field.*;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.record.*;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.sheet.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.data.domain.Sort;
@@ -117,7 +118,7 @@
            // 用户列表
            List<User> userList = new ArrayList<>();
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
@@ -219,7 +220,7 @@
            // 用户列表
            List<User> userList;
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
@@ -233,8 +234,15 @@
            for (User user : userList) {
                // 考勤记录:根据用户和日期查询
                Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate);
                // TODO:20250801修改 当天新建用户没有经过0点的考勤信息创建会空指针,需要创建记录
                if (attendance == null || attendance.getId().equals(null)) {
                    getWeComAttendanceList(Timestamp.valueOf(startAttendDate + " 00:00:00"), Arrays.asList(user));
                    attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate);
                }
                Boolean isHoliday = false;
                if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) {
                // 因存在周六日是工作日的情况,所以不能单纯用周六日作为判断条件
                if (attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) {
                    isHoliday = true;
                }
                // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(返回结果为空数组的情况下)
@@ -277,7 +285,7 @@
                            Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime());
                            // 考勤记录
                            if (!isHoliday) {
                                attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1)));
                                attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1, null)));
                            } else {
                                attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                            }
@@ -294,7 +302,7 @@
                            Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime());
                            // 考勤记录
                            if (!isHoliday) {
                                attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2)));
                                attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2, LocalDate.parse(startAttendDate))));
                            } else {
                                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                            }
@@ -316,6 +324,9 @@
            }
        } catch (WxErrorException wxErrorException) {
            wxErrorException.printStackTrace();
            sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
                            "<div class=\"highlight\">请前往API服务查看LOG。</div>",
                    "getWeComAttendanceListOfNoon"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
        }
    }
@@ -358,7 +369,7 @@
            // 用户列表
            List<User> userList;
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
@@ -372,8 +383,15 @@
            for (User user : userList) {
                // 考勤记录:根据用户和日期查询
                Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate);
                // TODO:20250801修改 当天新建用户没有经过0点的考勤信息创建会空指针,需要创建记录
                if (attendance == null || attendance.getId().equals(null)) {
                    getWeComAttendanceList(Timestamp.valueOf(startAttendDate + " 00:00:00"), Arrays.asList(user));
                    attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate);
                }
                Boolean isHoliday = false;
                if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) {
                // 因存在周六日是工作日的情况,所以不能单纯用周六日作为判断条件
                if (attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) {
                    isHoliday = true;
                }
                // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(oapiDingTalkRecordResultList为空的情况下)
@@ -416,7 +434,7 @@
                            Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime());
                            // 考勤记录
                            if (!isHoliday) {
                                attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1)));
                                attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1, null)));
                            } else {
                                attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                            }
@@ -433,7 +451,7 @@
                            Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime());
                            // 考勤记录
                            if (!isHoliday) {
                                attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2)));
                                attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2, LocalDate.parse(startAttendDate))));
                            } else {
                                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                            }
@@ -455,6 +473,9 @@
            }
        } catch (WxErrorException wxErrorException) {
            wxErrorException.printStackTrace();
            sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
                            "<div class=\"highlight\">请前往API服务查看LOG。</div>",
                    "getWeComAttendanceListOfNight"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
        }
    }
@@ -501,7 +522,7 @@
            }
        }
        // 查询外出表
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), DateUtil.parseAttStartTime(attendance.getRosteringWorkStartTime().toLocalDateTime()), DateUtil.parseAttEndTime(attendance.getRosteringWorkEndTime().toLocalDateTime()));
        for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) {
            // 上午/下午
            if (attendanceGoOut.getOutStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceGoOut.getOutEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) {
@@ -528,46 +549,91 @@
        // 查询考勤请假表
        List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime());
        // 查询考勤出差表
        List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime().withHour(0).withMinute(0).withSecond(0).withNano(0), attendance.getAttendanceDate().toLocalDateTime().withHour(23).withMinute(59).withSecond(59).withNano(999));
        List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime().withHour(0).withMinute(0).withSecond(0).withNano(0), attendance.getAttendanceDate().toLocalDateTime().withHour(23).withMinute(59).withSecond(59).withNano(0));
        // 查询考勤外出表
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), DateUtil.parseAttStartTime(attendance.getAttendanceDate().toLocalDateTime()), DateUtil.parseAttEndTime(attendance.getAttendanceDate().toLocalDateTime()));
        Double outStartDuration = new Double(0.00); // 上午时长
        Double outEndDuration = new Double(0.00); // 下午时长
        Double bussStartDuration = new Double(0.00); // 上午时长
        Double bussEndDuration = new Double(0.00); // 下午时长
        Double leaveStartDuration = new Double(0.00); // 上午时长
        Double leaveEndDuration = new Double(0.00); // 下午时长
        Map<Timestamp, String> startTimeMap = new HashMap<>();
        Map<Timestamp, String> endTimeMap = new HashMap<>();
        // TODO:统计规则请假优先于出差优先于外出
        if (attendanceGoOutList.size() > 0) {
            // 统计外出
            Double outStartDuration = new Double(0.00); // 上午时长
            Double outEndDuration = new Double(0.00); // 下午时长
            for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) {
                // 上午时长、下午时长
                outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance);
                outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance);
                startTimeMap.put(attendanceGoOut.getOutStartTime(), Constant.ATTENDANCE_STATE_GOOUT);
                endTimeMap.put(attendanceGoOut.getOutEndTime(), Constant.ATTENDANCE_STATE_GOOUT);
            }
            // 调用方法修改考勤打卡状态
            updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration);
        }
        if (attendanceBusinessTravelList.size() > 0) {
            // 统计出差
            Double bussStartDuration = new Double(0.00); // 上午时长
            Double bussEndDuration = new Double(0.00); // 下午时长
            for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) {
                // 上午时长、下午时长
                bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
                bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
                startTimeMap.put(attendanceBusinessTravel.getTravelStartTime(), Constant.ATTENDANCE_STATE_BUSINESS);
                endTimeMap.put(attendanceBusinessTravel.getTravelEndTime(), Constant.ATTENDANCE_STATE_BUSINESS);
            }
            // 调用方法修改考勤打卡状态
            updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration);
        }
        if (attendanceLeaveList.size() > 0) {
            // 统计请假
            Double leaveStartDuration = new Double(0.00); // 上午时长
            Double leaveEndDuration = new Double(0.00); // 下午时长
            for (AttendanceLeave attendanceLeave : attendanceLeaveList) {
                // 上午总时长、下午总时长
                leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance);
                leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance);
                startTimeMap.put(attendanceLeave.getLeaveStartTime(), Constant.ATTENDANCE_STATE_LEAVE);
                endTimeMap.put(attendanceLeave.getLeaveEndTime(), Constant.ATTENDANCE_STATE_LEAVE);
            }
            //调用方法修改考勤打卡状态
            updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, leaveEndDuration);
        }
        // 选出最早的开始时间, 更新考勤记录
        if (!startTimeMap.isEmpty()) {
            Timestamp startTime = startTimeMap.keySet().stream().sorted(Comparator.comparing(Timestamp::toLocalDateTime)).findFirst().get();
            if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_GOOUT)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00);
            } else if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00);
            } else if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_LEAVE)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00);
            }
        }
        // 选出最晚的结束时间, 更新考勤记录
        if (!endTimeMap.isEmpty()) {
            Timestamp endTime = endTimeMap.keySet().stream().sorted(Comparator.comparing(Timestamp::toLocalDateTime).reversed()).findFirst().get();
            if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_GOOUT)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration);
            } else if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration);
            } else if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_LEAVE)) {
                updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration);
            }
        }
        // TODO:20250813修改 增加打卡时间判断,打卡时间需要闭环
        Boolean actualTimeLoopFlag = ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) == ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime());
        if (!actualTimeLoopFlag) {
            List<String> editStatusList = Arrays.asList(Constant.ATTENDANCE_STATE_GOOUT, Constant.ATTENDANCE_STATE_BUSINESS, Constant.ATTENDANCE_STATE_LEAVE);
            if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && editStatusList.contains(attendance.getStartClockResults())) {
                attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
            }
            if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && editStatusList.contains(attendance.getEndClockResults())) {
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
            }
        }
//        // 查询考勤请假表
@@ -752,16 +818,16 @@
            } else {
                // 上午
                if (day) {
                    // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时
                    if (duration >= result) {
                    // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
                    if (duration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                        attendance.setStartClockResults(type);
                        attendance.setStartLocationResults(null);
                    } else {
                        attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME);
                    }
                } else {
                    // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时
                    if (duration >= noonResult) {
                    // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
                    if (duration >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                        attendance.setEndClockResults(type);
                        attendance.setEndLocationResults(null);
                    } else {
@@ -783,14 +849,16 @@
            } else {
                //打卡的情况,修改考勤状态
                if (day) {
                    if ((duration + result1) >= result) {
                    // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
                    if ((duration + result1) >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                        attendance.setStartClockResults(type);
                        attendance.setStartLocationResults(null);
                    } else {
                        attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME);
                    }
                } else {
                    if ((duration + noonResult1) >= noonResult) {
                    // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
                    if ((duration + noonResult1) >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                        attendance.setEndClockResults(type);
                        attendance.setEndLocationResults(null);
                    } else {
@@ -814,17 +882,20 @@
     *
     * @param sysRostering
     * @param timestamp
     * @param type
     * @param type / 1上班打卡。2下班打卡。
     * @param attendanceDate / 考勤日期当天(下班打卡使用)
     * @return
     */
    public String checkResult(SysRostering sysRostering, Timestamp timestamp, Integer type) {
    public String checkResult(SysRostering sysRostering, Timestamp timestamp, Integer type, LocalDate attendanceDate) {
        String result = ObjectUtil.isEmpty(timestamp) ? Constant.ATTENDANCE_STATE_NOTSIGNED : Constant.ATTENDANCE_STATE_NORMAL;
        if (type.equals(1)) {
            // 上班打卡
            if (timestamp.toLocalDateTime().toLocalTime().isAfter(sysRostering.getWorkStartTime())) {
                result = Constant.ATTENDANCE_START_LATE;
            }
        } else {
            if (timestamp.toLocalDateTime().toLocalTime().isBefore(sysRostering.getWorkEndTime())) {
            // 下班打卡
            if (timestamp.toLocalDateTime().toLocalTime().isBefore(sysRostering.getWorkEndTime()) && (attendanceDate != null ? !timestamp.toLocalDateTime().toLocalDate().isAfter(attendanceDate) : true)) {
                result = Constant.ATTENDANCE_START_EARLY;
            }
        }
@@ -859,9 +930,9 @@
     */
    public Boolean getCardSupplement(Long userId, String st, Timestamp checkTime) {
        if (ObjectUtils.isNotEmpty(checkTime)) {
            // 查询补卡记录
            // 查询补卡记录 TODO:20250805修改 正常考勤状态全部验证通过处理
            AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndTime(userId, checkTime);
            if (ObjectUtils.isNotEmpty(attendanceCardreplacement) && st.equals(Constant.ATTENDANCE_STATE_NORMAL)) {
            if (ObjectUtils.isNotEmpty(attendanceCardreplacement) && (st.equals(Constant.ATTENDANCE_STATE_NORMAL) || st.equals(Constant.ATTENDANCE_STATE_LEAVE) || st.equals(Constant.ATTENDANCE_STATE_BUSINESS)|| st.equals(Constant.ATTENDANCE_STATE_GOOUT))) {
                return true;
            }
        }
@@ -906,8 +977,8 @@
     */
    public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, Attendance attendance, String type) {
        if (ObjectUtils.isEmpty(eDuration) && ObjectUtils.isEmpty(noonResult)) {
            // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时
            if (sDuration >= result) {
            // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
            if (sDuration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                attendance.setStartClockResults(type);
                attendance.setStartLocationResults(null);
            } else {
@@ -915,8 +986,8 @@
            }
        }
        if (ObjectUtils.isEmpty(sDuration) && ObjectUtils.isEmpty(result)) {
            // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时
            if (eDuration >= noonResult) {
            // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
            if (eDuration >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                attendance.setEndClockResults(type);
                attendance.setEndLocationResults(null);
            } else {
@@ -937,7 +1008,8 @@
     */
    public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, Attendance attendance, String type) {
        if (ObjectUtils.isEmpty(eDuration) && sDuration > 0) {
            if ((sDuration + result1) >= result) {
            // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
            if ((sDuration + result1) >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                attendance.setStartClockResults(type);
                attendance.setStartLocationResults(null);
            } else {
@@ -945,7 +1017,8 @@
            }
        }
        if (ObjectUtils.isEmpty(sDuration) && eDuration > 0) {
            if ((eDuration + result1) >= noonResult) {
            // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环)
            if ((eDuration + result1) >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) {
                attendance.setEndClockResults(type);
                attendance.setEndLocationResults(null);
            } else {
@@ -964,7 +1037,7 @@
    public Integer calculateTimes(LocalDateTime start, LocalDateTime end) {
        Integer time = 0;
        Duration duration = null;
        duration = Duration.between(start, start.toLocalDate().atTime(end.toLocalTime()));
        duration = Duration.between(start, end);
        Long StartSeconds = duration.getSeconds();
        time += StartSeconds.intValue();
        return time;
@@ -1098,6 +1171,9 @@
                wxCpService.getMessageService().send(wxCpMessage);
            } catch (WxErrorException wxErrorException) {
                wxErrorException.printStackTrace();
//                sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
//                                "<div class=\"highlight\">请前往API服务查看LOG。</div>",
//                        "sendNotice"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
            }
        }
    }
@@ -1125,10 +1201,8 @@
            Map<String, String> robotParamMap = dictDetailRepository.findByDictName(Constant.WECOM_ROBOT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue));
            if (robotParamMap.containsKey(Constant.REMIND_REPORT_WEBHOOK_KEY) && robotParamMap.containsKey(Constant.REMIND_REPORT_MSG)) {
                // 发送消息
                WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
                wxCpDefaultConfig.setWebhookKey(robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY));
                wxCpService.setWxCpConfigStorage(wxCpDefaultConfig);
                wxCpService.getGroupRobotService().sendText(robotParamMap.get(Constant.REMIND_REPORT_MSG), Arrays.asList("@all"), Arrays.asList());
                String webhookUrl = wxCpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/webhook/send?key=") + robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY);
                wxCpService.getGroupRobotService().sendText(webhookUrl, robotParamMap.get(Constant.REMIND_REPORT_MSG), Arrays.asList("@all"), Arrays.asList());
            }
        } catch (WxErrorException wxErrorException) {
            wxErrorException.printStackTrace();
@@ -1160,6 +1234,7 @@
        // 个人报告
        UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
        userQueryCriteria.setEnabled(true);
        userQueryCriteria.setLoginEnabled(true);
        userQueryCriteria.setWeComIdNotNull(true);
        userQueryCriteria.getDeptIds().add(7L);
        // 先查找是否存在子节点
@@ -1175,6 +1250,18 @@
        projectQueryCriteria.setProjectStatusIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY));
        List<Long> projectIds = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, projectQueryCriteria, criteriaBuilder)).stream().map(p -> p.getId()).collect(Collectors.toList());
        toWeComSheetPushProjectReport(projectIds);
        try {
            // 获取企微机器人参数
            Map<String, String> robotParamMap = dictDetailRepository.findByDictName(Constant.WECOM_ROBOT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue));
            if (robotParamMap.containsKey(Constant.REMIND_REPORT_WEBHOOK_KEY) && robotParamMap.containsKey(Constant.REMIND_REPORT_SUCCESS_MSG)) {
                // 发送周报生成成功消息
                String webhookUrl = wxCpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/webhook/send?key=") + robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY);
                wxCpService.getGroupRobotService().sendText(webhookUrl, robotParamMap.get(Constant.REMIND_REPORT_SUCCESS_MSG), Arrays.asList("@all"), Arrays.asList());
            }
        } catch (WxErrorException wxErrorException) {
            wxErrorException.printStackTrace();
        }
    }
    /**
@@ -1223,6 +1310,9 @@
                Gson gson = new Gson();
                // 特殊参数:开发-公共事务、公司-公共事务的项目名称细化到任务详情一级
                Set<Long> specialProjectType = new HashSet<>(Arrays.asList(46L, 47L));
                // 应用参数
                DateTimeFormatter ymdFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                Map<String, String> leaveTypeMap = dictDetailRepository.findByDictName(Constant.LEAVE_TYPE).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
                for (Long userId : userIds) {
                    // 查询用户信息
@@ -1299,6 +1389,10 @@
                            return new BigDecimal(leave.getLeaveDuration());
                        }
                    }).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur));
                    String leaveHourDetail = leaveList.stream().map(leave -> {
                        BigDecimal leaveHour = leave.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY) ? new BigDecimal(8).multiply(new BigDecimal(leave.getLeaveDuration())) : new BigDecimal(leave.getLeaveDuration());
                        return String.format("%s %s %sH", leave.getLeaveStartTime().toLocalDateTime().format(ymdFormatter), leaveTypeMap.get(leave.getLeaveType()), leaveHour.stripTrailingZeros().toPlainString());
                    }).collect(Collectors.joining(";"));
                    // 统计换休信息
                    AttendanceOvertimeQueryCriteria overtimeQueryCriteria = new AttendanceOvertimeQueryCriteria();
                    overtimeQueryCriteria.setUserId(userId);
@@ -1330,6 +1424,9 @@
                        // 制作项目周报数据
                        Map<String, List<Record>> filterRecordMap = daliyMongoDtoList.stream().map(item -> {
                            Record record = recordInfo.getRecords().stream().filter(r -> {
                                if (ObjectUtils.isEmpty(r.getValues().get("项目名称")) || StringUtils.isBlank(r.getValues().get("项目名称").toString())) {
                                    return false;
                                }
                                LocalDate createDate = Instant.ofEpochMilli(Long.parseLong(r.getValues().get("提交日期").toString())).atZone(ZoneId.systemDefault()).toLocalDate();
                                RecordOption projectNameRecord = ((List<?>) r.getValues().get("项目名称")).stream().map(o -> RecordOption.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordOption::new);
                                RecordCellUserValue submitterRecord = ((List<?>) r.getValues().get("提交人")).stream().map(o -> RecordCellUserValue.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordCellUserValue::new);
@@ -1374,6 +1471,8 @@
                            record.setValues(values);
                            return record;
                        }).collect(Collectors.groupingBy(record -> StringUtils.isNotBlank(record.getRecordId()) ? "EDIT" : "CREATE"));
                        // 待删除记录
                        List<Record> recordDeleteList = recordInfo.getRecords().stream().filter(r -> ObjectUtils.isEmpty(r.getValues().get("项目名称")) || StringUtils.isBlank(r.getValues().get("项目名称").toString())).collect(Collectors.toList());
                        // 创建新纪录
                        List<Record> recordCreateList = filterRecordMap.getOrDefault("CREATE", Collections.emptyList());
@@ -1397,6 +1496,12 @@
                            recordEditRequest.setRecords(recordEditList);
                            // 提交记录
                            wxCpOaWeDocSmartsheetService.recordEdit(recordEditRequest);
                        }
                        // 删除记录(仅限空数据)
                        if (recordDeleteList.size() > 0) {
                            List<String> recordIdDeleteList = recordDeleteList.stream().map(r -> r.getRecordId()).collect(Collectors.toList());
                            wxCpOaWeDocSmartsheetService.recordDelete(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID), weeklyReportProjectSheet.getSheetId(), recordIdDeleteList);
                        }
                    } else {
                        System.out.println("项目周报子表不存在");
@@ -1441,6 +1546,11 @@
                            String submitTimestamp = String.valueOf(endTime.getTime());
                            values.put("提交日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, submitTimestamp).getValue());
                            record.setValues(values);
                            // 请假详细
                            RecordCellTextValue leaveDetail = new RecordCellTextValue();
                            leaveDetail.setType("text");
                            leaveDetail.setText(leaveHourDetail);
                            values.put("请假详细", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(leaveDetail)).getValue());
                            if (StringUtils.isNotBlank(record.getRecordId())) {
                                // 编辑记录
@@ -1468,6 +1578,9 @@
                }
            } catch (WxErrorException wxErrorException) {
                wxErrorException.printStackTrace();
                sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
                                "<div class=\"highlight\">请前往API服务查看LOG。</div>",
                        "toWecomSheetPushWeeklyReport"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -2003,6 +2116,9 @@
                }
            } catch (WxErrorException wxErrorException) {
                wxErrorException.printStackTrace();
                sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
                                "<div class=\"highlight\">请前往API服务查看LOG。</div>",
                        "toWeComSheetPushProjectReport"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
            } catch (Exception e) {
                e.printStackTrace();
            }