feat(flowable): 添加卫生所和心理中心的通知监听器
- 新增 WSSListener 和 XLZXListener 类,用于向卫生所和心理中心发送违纪审批通知 - 更新 RtStuReentrySchoolServiceImpl 中的流程实例 ID - 优化 XWGSListener 类的注释
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 宁博
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class WSSListener implements ExecutionListener {
|
||||
@Override
|
||||
public void notify(DelegateExecution delegateExecution) {
|
||||
DisciplinaryMapper disciplinaryMapper = SpringUtils.getBean(DisciplinaryMapper.class);
|
||||
|
||||
// 1. 【核心】定义"卫生所" wss
|
||||
final String TARGET_ROLE_KEY = "wss";
|
||||
log.info("流程实例 [{}]: 准备向角色 '{}' 发送通知。", delegateExecution.getProcessInstanceId(), TARGET_ROLE_KEY);
|
||||
|
||||
// 2. 根据这个固定的角色Key,查询该角色的所有成员ID(即使只有一个)。
|
||||
List<Long> userIdList = disciplinaryMapper.getApprovalByRoleKey(TARGET_ROLE_KEY);
|
||||
// 3. 检查是否找到了成员。
|
||||
if (userIdList == null || userIdList.isEmpty()) {
|
||||
log.error("根据角色Key '{}' 未找到任何用户,无法发送通知。", TARGET_ROLE_KEY);
|
||||
return; // 中止执行,不抛出异常以免中断流程
|
||||
}
|
||||
|
||||
// 4. 发送企业微信通知。
|
||||
// (我们的批量发送逻辑即使只有一个用户也能完美处理)
|
||||
try {
|
||||
// 批量查询userName (即使只有一个ID,这个方法也能正常工作)
|
||||
List<String> userNameList = disciplinaryMapper.getUserNamesByUserIdList(userIdList);
|
||||
|
||||
if (!userNameList.isEmpty()) {
|
||||
// 将列表拼接成 "username1|username2|..." 的格式
|
||||
String toUser = String.join("|", userNameList);
|
||||
|
||||
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
|
||||
String content = "您有一条新的学生违纪审批任务待处理,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>。";
|
||||
|
||||
weChatUtil.sendTextMessage(toUser, content);
|
||||
log.info("已成功向角色 '{}' 的成员发送通知。接收人: {}", TARGET_ROLE_KEY, toUser);
|
||||
} else {
|
||||
log.warn("角色 '{}' 中找到了 {} 个用户,但无人配置企业微信账号,未发送任何通知。", TARGET_ROLE_KEY, userIdList.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("向角色 '{}' 发送企业微信通知时出现异常。流程将继续。错误详情: {}", TARGET_ROLE_KEY, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,57 @@
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 宁博
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class XLZXListener implements ExecutionListener {
|
||||
@Override
|
||||
public void notify(DelegateExecution delegateExecution) {
|
||||
DisciplinaryMapper disciplinaryMapper = SpringUtils.getBean(DisciplinaryMapper.class);
|
||||
|
||||
// 1. 【核心】定义"心理中心" xlzx
|
||||
final String TARGET_ROLE_KEY = "xlzx";
|
||||
log.info("流程实例 [{}]: 准备向角色 '{}' 发送通知。", delegateExecution.getProcessInstanceId(), TARGET_ROLE_KEY);
|
||||
|
||||
// 2. 根据这个固定的角色Key,查询该角色的所有成员ID(即使只有一个)。
|
||||
List<Long> userIdList = disciplinaryMapper.getApprovalByRoleKey(TARGET_ROLE_KEY);
|
||||
// 3. 检查是否找到了成员。
|
||||
if (userIdList == null || userIdList.isEmpty()) {
|
||||
log.error("根据角色Key '{}' 未找到任何用户,无法发送通知。", TARGET_ROLE_KEY);
|
||||
return; // 中止执行,不抛出异常以免中断流程
|
||||
}
|
||||
|
||||
// 4. 发送企业微信通知。
|
||||
// (我们的批量发送逻辑即使只有一个用户也能完美处理)
|
||||
try {
|
||||
// 批量查询userName (即使只有一个ID,这个方法也能正常工作)
|
||||
List<String> userNameList = disciplinaryMapper.getUserNamesByUserIdList(userIdList);
|
||||
|
||||
if (!userNameList.isEmpty()) {
|
||||
// 将列表拼接成 "username1|username2|..." 的格式
|
||||
String toUser = String.join("|", userNameList);
|
||||
|
||||
WeChatUtil weChatUtil = SpringUtils.getBean(WeChatUtil.class);
|
||||
String content = "您有一条新的学生违纪审批任务待处理,<a href='http://zhxg.gxsdxy.cn/web/#/pages/Approval/index'>请点击前往处理</a>。";
|
||||
|
||||
weChatUtil.sendTextMessage(toUser, content);
|
||||
log.info("已成功向角色 '{}' 的成员发送通知。接收人: {}", TARGET_ROLE_KEY, toUser);
|
||||
} else {
|
||||
log.warn("角色 '{}' 中找到了 {} 个用户,但无人配置企业微信账号,未发送任何通知。", TARGET_ROLE_KEY, userIdList.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("向角色 '{}' 发送企业微信通知时出现异常。流程将继续。错误详情: {}", TARGET_ROLE_KEY, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 根据辅导员的部门id,查询该部门的学无干事人员 知无涯
|
||||
* 根据辅导员的部门id,查询该部门的学务干事人员 知无涯
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
|
@@ -178,7 +178,7 @@ public class RtStuReentrySchoolServiceImpl extends ServiceImpl<RtStuReentrySchoo
|
||||
variables.put("approval", SecurityUtils.getUserId());
|
||||
variables.put("deptId", SecurityUtils.getDeptId());
|
||||
|
||||
AjaxResult ajaxResult = flowDefinitionService.startProcessInstanceById("flow_9ffew1pj:5:390063", variables);
|
||||
AjaxResult ajaxResult = flowDefinitionService.startProcessInstanceById("flow_9ffew1pj:13:1000008", variables);
|
||||
String code = ajaxResult.get("code").toString();
|
||||
if (code.equals("200")) {
|
||||
|
||||
|
Reference in New Issue
Block a user