From ee756969610b6b0aaa39df85cebcdd0c8cef960e Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Thu, 16 Oct 2025 05:49:51 +0000
Subject: [PATCH] 企微通信redis锁问题修改

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 88 insertions(+), 18 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
index e686a18..4364299 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
@@ -42,10 +42,10 @@
 import me.zhengjie.modules.treatment.repository.UserLevelWageRepository;
 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;
@@ -233,6 +233,12 @@
             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)) {
                     isHoliday = true;
@@ -316,6 +322,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);
         }
     }
 
@@ -372,6 +381,12 @@
             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)) {
                     isHoliday = true;
@@ -455,6 +470,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);
         }
     }
 
@@ -568,6 +586,20 @@
             }
             //调用方法修改考勤打卡状态
             updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, 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 +784,16 @@
             } else {
                 // 上午
                 if (day) {
-                    // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时
-                    if (duration >= result) {
+                    // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况
+                    if (duration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST)) {
                         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.setEndClockResults(type);
                         attendance.setEndLocationResults(null);
                     } else {
@@ -783,14 +815,16 @@
             } else {
                 //打卡的情况,修改考勤状态
                 if (day) {
-                    if ((duration + result1) >= result) {
+                    // TODO:20250805修改 排除休息日情况
+                    if ((duration + result1) >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST)) {
                         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.setEndClockResults(type);
                         attendance.setEndLocationResults(null);
                     } else {
@@ -862,9 +896,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;
             }
         }
@@ -909,8 +943,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.setStartClockResults(type);
                 attendance.setStartLocationResults(null);
             } else {
@@ -918,8 +952,8 @@
             }
         }
         if (ObjectUtils.isEmpty(sDuration) && ObjectUtils.isEmpty(result)) {
-            // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时
-            if (eDuration >= noonResult) {
+            // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况
+            if (eDuration >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST)) {
                 attendance.setEndClockResults(type);
                 attendance.setEndLocationResults(null);
             } else {
@@ -940,7 +974,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.setStartClockResults(type);
                 attendance.setStartLocationResults(null);
             } else {
@@ -948,7 +983,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.setEndClockResults(type);
                 attendance.setEndLocationResults(null);
             } else {
@@ -1101,6 +1137,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);
             }
         }
     }
@@ -1178,6 +1217,20 @@
         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)) {
+                // 发送周报生成成功消息
+                WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
+                wxCpDefaultConfig.setWebhookKey(robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY));
+                wxCpService.setWxCpConfigStorage(wxCpDefaultConfig);
+                wxCpService.getGroupRobotService().sendText(robotParamMap.get(Constant.REMIND_REPORT_SUCCESS_MSG), Arrays.asList("@all"), Arrays.asList());
+            }
+        } catch (WxErrorException wxErrorException) {
+            wxErrorException.printStackTrace();
+        }
     }
 
     /**
@@ -1333,6 +1386,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);
@@ -1377,6 +1433,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());
@@ -1400,6 +1458,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("项目周报子表不存在");
@@ -1471,6 +1535,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();
             }
@@ -2006,6 +2073,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();
             }

--
Gitblit v1.9.3