From dac503c1ce37ca44c8a69dabfd432dea7d3d794e Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Mon, 22 Sep 2025 08:05:51 +0000
Subject: [PATCH] 生成周报记录任务空指针异常修改

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java |   45 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 36 insertions(+), 9 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 9e20816..0674f90 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;
@@ -192,7 +192,7 @@
     public void getWeComAttendanceListOfNoon(String attendDate, List attUser) throws Exception {
         try {
             // 获取企业微信Token
-            wxCpService.getAccessToken(true);
+            wxCpService.getAccessToken();
 
             // 获取参数日期类
             Calendar calAttendDate = Calendar.getInstance();
@@ -322,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);
         }
     }
 
@@ -335,7 +338,7 @@
     public void getWeComAttendanceListOfNight(String attendDate, List attUser) throws Exception {
         try {
             // 获取企业微信Token
-            wxCpService.getAccessToken(true);
+            wxCpService.getAccessToken();
 
             // 获取参数日期类
             Calendar calAttendDate = Calendar.getInstance();
@@ -467,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);
         }
     }
 
@@ -1092,7 +1098,7 @@
         if (userWeComIdList.size() > 0) {
             try {
                 // 获取企业微信Token
-                wxCpService.getAccessToken(true);
+                wxCpService.getAccessToken();
 
                 // 编辑消息
                 WxCpMessage wxCpMessage = new WxCpMessage();
@@ -1131,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);
             }
         }
     }
@@ -1261,7 +1270,7 @@
 
             try {
                 // 获取企业微信Token
-                wxCpService.getAccessToken(true);
+                wxCpService.getAccessToken();
 
                 // 查询现有子表信息
                 WxCpSheetQueryRequest sheetQueryRequest = new WxCpSheetQueryRequest();
@@ -1372,11 +1381,17 @@
                         sort.setFieldTitle("提交日期");
                         sort.setDesc(true);
                         recordQueryRequest.setSort(Arrays.asList(sort));
+                        // 待删除记录
+                        List<Record> recordDeleteList = new ArrayList<>();
                         WxCpRecordInfo recordInfo = wxCpOaWeDocSmartsheetService.recordInfo(recordQueryRequest);
 
                         // 制作项目周报数据
                         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())) {
+                                    recordDeleteList.add(r);
+                                    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);
@@ -1444,6 +1459,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("项目周报子表不存在");
@@ -1515,6 +1536,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();
             }
@@ -1545,7 +1569,7 @@
 
             try {
                 // 获取企业微信Token
-                wxCpService.getAccessToken(true);
+                wxCpService.getAccessToken();
 
                 // 查询现有子表信息
                 WxCpSheetQueryRequest sheetQueryRequest = new WxCpSheetQueryRequest();
@@ -2050,6 +2074,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