From 96a396202f23aa832f38b5fe73550a87bee8bef8 Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Wed, 10 Sep 2025 02:52:42 +0000
Subject: [PATCH] 企微通信失败添加消息提醒用于监控(根据情况变更消息接收人)
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateControlFieldServiceImpl.java | 17 ++++++++++++++---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateServiceImpl.java | 7 ++++++-
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java | 25 ++++++++++++++++++++-----
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateControlFieldServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateControlFieldServiceImpl.java
index eedcad9..5416f08 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateControlFieldServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateControlFieldServiceImpl.java
@@ -37,6 +37,7 @@
import me.zhengjie.modules.approval.service.mapstruct.TemplateControlMapper;
import me.zhengjie.modules.approval.service.mapstruct.TemplateMapper;
import me.zhengjie.modules.constant.Constant;
+import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.repository.DictRepository;
@@ -85,6 +86,7 @@
private final DictService dictService;
private final DictRepository dictRepository;
private final DictDetailService dictDetailService;
+ private final WeComServiceImpl weComService;
@Override
public Map<String,Object> queryAll(TemplateControlFieldQueryCriteria criteria, Pageable pageable){
@@ -202,7 +204,7 @@
Dict dict = dictRepository.findByName(Constant.WECOM_LEAVE_TYPE);
// 获取企业微信Token
- wxCpService.getAccessToken(true);
+ wxCpService.getAccessToken();
// 假勤组件需要获取假期相关配置
WxCpCorpConfInfo corpConfInfo = wxCpService.getOaService().getCorpConf();
List<DictDetail> newDictDetails = corpConfInfo.getLists().stream().map(m -> {
@@ -227,6 +229,9 @@
}
} catch (WxErrorException wxErrorException) {
wxErrorException.printStackTrace();
+ weComService.sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
+ "<div class=\"highlight\">请前往API服务查看LOG。</div>",
+ "updateWecomVacationType"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
throw new BadRequestException("数据更新异常");
}
}
@@ -299,7 +304,7 @@
public List<String> uploadWecomMediaFile(List<String> filePaths) {
try {
// 获取企业微信Token
- wxCpService.getAccessToken(true);
+ wxCpService.getAccessToken();
// 提交临时素材文件
return filePaths.stream().map(path -> {
@@ -314,6 +319,9 @@
}).collect(Collectors.toList());
} catch (Exception e) {
e.printStackTrace();
+ weComService.sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
+ "<div class=\"highlight\">请前往API服务查看LOG。</div>",
+ "uploadWecomMediaFile"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
throw new BadRequestException("文件上传准备异常");
}
}
@@ -780,7 +788,7 @@
}
// 获取企业微信Token
- wxCpService.getAccessToken(true);
+ wxCpService.getAccessToken();
// 初始化参数
WxCpOaApplyEventRequest eventRequest = new WxCpOaApplyEventRequest();
@@ -802,6 +810,9 @@
} catch (WxErrorException wxErrorException) {
// 通信失败
wxErrorException.printStackTrace();
+ weComService.sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
+ "<div class=\"highlight\">请前往API服务查看LOG。</div>",
+ "sendApplyEvent"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
resultMap.put("error", "通信失败");
} catch (IllegalAccessException illegalAccessException) {
// 解析后数据获取失败
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateServiceImpl.java
index fd7e193..b44e241 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/approval/service/impl/TemplateServiceImpl.java
@@ -28,6 +28,7 @@
import me.zhengjie.modules.approval.service.dto.TemplateControlQueryCriteria;
import me.zhengjie.modules.approval.service.mapstruct.TemplateControlMapper;
import me.zhengjie.modules.constant.Constant;
+import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
import me.zhengjie.modules.system.service.DictDetailService;
import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.utils.*;
@@ -65,6 +66,7 @@
private final TemplateControlMapper templateControlMapper;
private final WxCpService wxCpService;
private final DictDetailService dictDetailService;
+ private final WeComServiceImpl weComService;
@Override
public Map<String,Object> queryAll(TemplateQueryCriteria criteria, Pageable pageable){
@@ -132,7 +134,7 @@
try {
if (criteria.getQueryNew()) {
// 获取企业微信Token
- wxCpService.getAccessToken(true);
+ wxCpService.getAccessToken();
// 获取指定模版详细信息
WxCpOaApprovalTemplateResult templateResult = wxCpService.getOaService().getTemplateDetail(criteria.getTemplateId());
@@ -461,6 +463,9 @@
}
} catch (WxErrorException wxErrorException) {
wxErrorException.printStackTrace();
+ weComService.sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" +
+ "<div class=\"highlight\">请前往API服务查看LOG。</div>",
+ "queryWeComTemplate"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD);
throw new Exception("数据读取失败");
}
} else {
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..a1f3d85 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
@@ -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();
@@ -1515,6 +1524,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 +1557,7 @@
try {
// 获取企业微信Token
- wxCpService.getAccessToken(true);
+ wxCpService.getAccessToken();
// 查询现有子表信息
WxCpSheetQueryRequest sheetQueryRequest = new WxCpSheetQueryRequest();
@@ -2050,6 +2062,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