退伍复学-企业消息推送

This commit is contained in:
2026-03-19 15:48:00 +08:00
parent 1e359df1b2
commit 21e967a72e
5 changed files with 106 additions and 37 deletions

View File

@@ -3,10 +3,15 @@ package com.srs.flowable.listener.disbasic;
import com.srs.common.core.domain.entity.SysUser;
import com.srs.common.doman.vo.TeacherVo;
import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.WeChatUtil;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.DisBasic;
import com.srs.flowable.domain.NotificationManage;
import com.srs.flowable.mapper.DisBasicMapper;
import com.srs.flowable.mapper.EnlistmentReserveMapper;
import com.srs.flowable.mapper.LeaveMapper;
import com.srs.system.service.ISysUserService;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowNode;
@@ -76,6 +81,8 @@ public class DiscListener implements ExecutionListener {
execution.setVariable("approval", nextAssigneeId);
execution.setVariable("currentNode", currentNodeName);
}
// ========== 发送通知逻辑 ==========
sendApprovalNotification(execution, currentNodeName, nextAssigneeId, stId);
}
/**
@@ -188,9 +195,6 @@ public class DiscListener implements ExecutionListener {
// 暂时选择学籍管理科第一个人作为审核人
return shenDataInfo.get(0).getUserId();
case "教务处主管":
// 最后一个节点通过后 → 流程结束(无需设置负责人)
List<TeacherVo> teacherVos = sysDisBasicMapper.getShenDataInfo("教务处主管领导");
@@ -207,4 +211,92 @@ public class DiscListener implements ExecutionListener {
}
}
/**
* 发送审批通知(系统通知+企业微信通知)
* 适配DisBasic退伍复学业务场景
*/
private void sendApprovalNotification(DelegateExecution execution, String currentNodeName,
Long nextAssigneeId, Long basicId) {
try {
// 1. 获取需要的Mapper和工具类通过SpringUtils获取避免Autowired循环依赖
LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
// 2. 查询退伍复学申请详情
DisBasicMapper disBasicMapper = (DisBasicMapper) SpringUtils.getBean(DisBasicMapper.class);
DisBasic disBasic = disBasicMapper.selectSysDisBasicById(basicId);
if (disBasic == null) {
log.warn("未找到退伍复学申请记录basicId:{}", basicId);
return;
}
// 3. 查询下一个审批人的信息
SysUser nextApprover = sysUserService.selectUserById(nextAssigneeId);
if (nextApprover == null) {
log.warn("未找到审批人信息用户ID:{}", nextAssigneeId);
return;
}
String approverUserName = nextApprover.getUserName(); // 审批人工号/用户名
String approverName = nextApprover.getNickName(); // 审批人姓名
log.info("开始发送【退伍复学审批】通知,审批节点:{},审批人:{}({})申请ID{}",
currentNodeName, approverName, approverUserName, basicId);
// 4. 处理系统通知(先删后加,避免重复通知)
NotificationManage notificationManage = new NotificationManage();
notificationManage.setContent(String.format("您有一条【退伍复学审批】待处理(节点:%s", currentNodeName));
notificationManage.setReceiver(nextAssigneeId); // 接收人:下一个审批人
// 4.1 查询是否已有相同通知,有则删除
NotificationManage existNotify = leaveMapper.selectCphMsgListForFlowable(notificationManage);
if (existNotify != null) {
int delRes = leaveMapper.deleteCphMsgById(existNotify.getId());
log.info("删除重复的系统通知通知ID:{},删除结果:{}", existNotify.getId(), delRes);
}
// 4.2 添加新的系统通知
notificationManage.setSender(SecurityUtils.getUserId()); // 发送人:当前操作人
notificationManage.setCreateTime(DateUtils.getNowDate()); // 创建时间
int addRes = leaveMapper.insertCphMsg(notificationManage);
log.info("新增系统通知成功接收人ID:{},添加结果:{}", nextAssigneeId, addRes);
// 5. 企业微信推送消息(带超链接)
if (approverUserName != null && !approverUserName.isEmpty()) {
String weChatContent = String.format(
"您有一条【退伍复学审批】待处理(节点:%s<a href='https://zhxg.gxsdxy.cn/wab/#/pages/Approval/index'>请点击前往处理</a>",
currentNodeName
);
weChatUtil.sendTextMessage(approverUserName, weChatContent);
log.info("企业微信通知发送成功,接收人工号:{},节点:{}申请ID{}", approverUserName, currentNodeName, basicId);
} else {
log.warn("审批人工号为空无法发送企业微信通知用户ID:{}申请ID{}", nextAssigneeId, basicId);
}
// 6. 删除当前审批人的待处理通知(清理已处理的待办)
Long currentApproverId = SecurityUtils.getUserId();
if (currentApproverId == null) {
log.warn("当前审批人ID为空无法删除其待处理通知申请ID{}", basicId);
return;
}
NotificationManage currentNotifyQuery = new NotificationManage();
currentNotifyQuery.setContent(String.format("您有一条【退伍复学审批】待处理(节点:%s", currentNodeName));
currentNotifyQuery.setReceiver(currentApproverId);
NotificationManage currentExistNotify = leaveMapper.selectCphMsgListForFlowable(currentNotifyQuery);
if (currentExistNotify != null) {
int currentDelRes = leaveMapper.deleteCphMsgById(currentExistNotify.getId());
log.info("删除当前审批人({})的【{}】待处理通知通知ID:{},删除结果:{}申请ID{}",
currentApproverId, currentNodeName, currentExistNotify.getId(), currentDelRes, basicId);
} else {
log.info("当前审批人({})无【{}】节点的待处理通知无需删除申请ID{}", currentApproverId, currentNodeName, basicId);
}
} catch (Exception e) {
// 捕获所有异常,仅记录日志,不影响主流程
log.error("发送退伍复学审批通知失败,节点:{}审批人ID{}申请ID{},错误信息:{}",
currentNodeName, nextAssigneeId, basicId, e.getMessage(), e);
}
}
}