From 85c9bb5b666d9b33b3e8e8af285629c1b1445d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E?= <3154396966@qq.com> Date: Sun, 14 Sep 2025 17:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=91=E5=AD=A6=E5=92=8C=E7=BB=99=E4=B8=8E?= =?UTF-8?q?=E9=80=80=E5=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/disciplinary/XGLDSHListener.java | 57 ++++++++++--------- .../impl/RtStuQuitSchoolServiceImpl.java | 2 +- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/srs-flowable/src/main/java/com/srs/flowable/listener/disciplinary/XGLDSHListener.java b/srs-flowable/src/main/java/com/srs/flowable/listener/disciplinary/XGLDSHListener.java index 901788e..1768dcf 100644 --- a/srs-flowable/src/main/java/com/srs/flowable/listener/disciplinary/XGLDSHListener.java +++ b/srs-flowable/src/main/java/com/srs/flowable/listener/disciplinary/XGLDSHListener.java @@ -1,60 +1,65 @@ package com.srs.flowable.listener.disciplinary; import com.srs.common.utils.WeChatUtil; -import com.srs.common.utils.spring.SpringUtils; import com.srs.flowable.mapper.DisciplinaryMapper; import lombok.extern.slf4j.Slf4j; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import java.util.List; -@Component +/** + * 学工领导审批监听器 + * 使用 @Component + @Autowired,兼容 Flowable Delegate Expression + */ +@Component("xgldshListener") @Slf4j public class XGLDSHListener implements ExecutionListener { + @Autowired + private DisciplinaryMapper disciplinaryMapper; @Autowired private WeChatUtil weChatUtil; @Override - public void notify(DelegateExecution delegateExecution) { - DisciplinaryMapper disciplinaryMapper = SpringUtils.getBean(DisciplinaryMapper.class); + public void notify(DelegateExecution execution) { - // 固定角色 Key final String TARGET_ROLE_KEY = "xgldsp"; + String processInstanceId = execution.getProcessInstanceId(); - // 步骤 1: 查询角色下的所有审批人 userId + log.info("流程实例 [{}]: 触发 XGLDSHListener,为角色 '{}' 节点准备数据...", processInstanceId, TARGET_ROLE_KEY); + + // 查询角色下审批人 List userIdList = disciplinaryMapper.getApprovalByRoleKey(TARGET_ROLE_KEY); - - if (userIdList == null || userIdList.isEmpty()) { - throw new RuntimeException("未找到角色 '" + TARGET_ROLE_KEY + "' 的审批人员,无法发送通知。"); + if (CollectionUtils.isEmpty(userIdList)) { + log.error("流程实例 [{}]: 角色 '{}' 未配置审批人员", processInstanceId, TARGET_ROLE_KEY); + throw new RuntimeException("学工领导审批人员未设置"); } + // 发送企微通知 + sendWeChatNotification(userIdList, processInstanceId, TARGET_ROLE_KEY); + } + + private void sendWeChatNotification(List userIdList, String processInstanceId, String roleKey) { try { - // 步骤 2: 查询 userName 列表 List userNameList = disciplinaryMapper.getUserNamesByUserIdList(userIdList); - - if (userNameList != null && !userNameList.isEmpty()) { - String toUser = String.join("|", userNameList); - - WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class); - - String content = "您有一条新的学生违纪审批任务待处理," + - "请点击前往处理。"; - - // 步骤 3: 发送企业微信通知 - weChatUtil.sendTextMessage(toUser, content); - log.info("已成功向角色 '{}' 的成员发送企业微信审批通知。接收人: {}", TARGET_ROLE_KEY, toUser); - - } else { - log.warn("角色 '{}' 下找到 {} 个用户,但无对应的企业微信账号,无法发送通知。", TARGET_ROLE_KEY, userIdList.size()); + if (CollectionUtils.isEmpty(userNameList)) { + log.warn("流程实例 [{}]: 角色 '{}' 审批人存在但无人配置企微账号", processInstanceId, roleKey); + return; } + String toUser = String.join("|", userNameList); + String content = "您有一条新的学生违纪审批任务待处理," + + "请点击前往处理"; + + weChatUtil.sendTextMessage(toUser, content); + log.info("流程实例 [{}]: 已成功向角色 '{}' 成员发送企微通知,接收人: {}", processInstanceId, roleKey, toUser); } catch (Exception e) { - log.error("向角色 '{}' 发送企业微信通知时出现异常,但流程将继续。错误详情: {}", TARGET_ROLE_KEY, e.getMessage(), e); + log.error("流程实例 [{}]: 向角色 '{}' 发送企微通知异常", processInstanceId, roleKey, e); } } } diff --git a/srs-routine/src/main/java/com/srs/routine/service/impl/RtStuQuitSchoolServiceImpl.java b/srs-routine/src/main/java/com/srs/routine/service/impl/RtStuQuitSchoolServiceImpl.java index f79219f..0565689 100644 --- a/srs-routine/src/main/java/com/srs/routine/service/impl/RtStuQuitSchoolServiceImpl.java +++ b/srs-routine/src/main/java/com/srs/routine/service/impl/RtStuQuitSchoolServiceImpl.java @@ -114,7 +114,7 @@ public class RtStuQuitSchoolServiceImpl extends ServiceImpl