From 52de1dda74b61b824f20256a8acd1e243c956ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=81=92=E6=88=90?= <962704835@qq.com> Date: Tue, 11 Nov 2025 11:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E5=BE=81=E5=85=A5=E4=BC=8D=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=AD=A6=E7=B1=8D=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApprovalAssigneeListener.java | 150 ++++++++++++++++++ .../routine/domain/RtEnlistmentReserve.java | 9 ++ .../mapper/RtEnlistmentReserveMapper.java | 8 + .../impl/RtEnlistmentReserveServiceImpl.java | 4 +- .../routine/RtEnlistmentReserveMapper.xml | 24 ++- 5 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 srs-flowable/src/main/java/com/srs/flowable/listener/enlistmentReserve/ApprovalAssigneeListener.java diff --git a/srs-flowable/src/main/java/com/srs/flowable/listener/enlistmentReserve/ApprovalAssigneeListener.java b/srs-flowable/src/main/java/com/srs/flowable/listener/enlistmentReserve/ApprovalAssigneeListener.java new file mode 100644 index 0000000..61ebfba --- /dev/null +++ b/srs-flowable/src/main/java/com/srs/flowable/listener/enlistmentReserve/ApprovalAssigneeListener.java @@ -0,0 +1,150 @@ +package com.srs.flowable.listener.enlistmentReserve; + +import com.srs.common.core.domain.entity.SysUser; + + +import com.srs.common.utils.SecurityUtils; +import com.srs.system.service.ISysUserService; +import org.flowable.bpmn.model.BpmnModel; +import org.flowable.bpmn.model.FlowNode; +import org.flowable.engine.HistoryService; +import org.flowable.engine.RepositoryService; +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 java.util.List; + + +/** + * 审批流程负责人自动流转监听器 + * 用于节点审批通过时,更新下一个节点的负责人变量(approval) + */ +@Component("approvalAssigneeListener") // Spring Bean名称,与BPMN表达式对应 +public class ApprovalAssigneeListener implements ExecutionListener { + + @Autowired + private ISysUserService sysUserService; // 用户服务(查询部门/学院负责人) + +// @Autowired +// private FlowBusinessService enlistmentReserveMapper; // 业务表Mapper + + @Autowired + private HistoryService historyService; // Flowable历史服务 + + // 用于查询流程定义中的节点信息 + @Autowired + private RepositoryService repositoryService; + + @Override + public void notify(DelegateExecution execution) { + // 1. 获取当前节点ID和流程定义ID + String currentActivityId = execution.getCurrentActivityId(); // 当前节点ID(兼容所有版本) + String processDefinitionId = execution.getProcessDefinitionId(); // 流程定义ID + + // 2. 根据节点ID查询节点名称(核心修正:通过流程定义获取名称) + String currentNodeName = getNodeNameByActivityId(processDefinitionId, currentActivityId); + if (currentNodeName == null) { + throw new RuntimeException("未找到节点ID=" + currentActivityId + "的名称"); + } + + // 3. 获取流程实例ID + String processInstanceId = execution.getProcessInstanceId(); + + // 4. 后续逻辑不变:查询下一个节点负责人并更新变量 + Long nextAssigneeId = getNextAssignee(currentNodeName, processInstanceId); + if (nextAssigneeId != null) { + execution.setVariable("approval", nextAssigneeId); + execution.setVariable("currentNode", currentNodeName); + } + } + + /** + * 根据节点ID和流程定义ID,查询节点名称(兼容所有版本的核心方法) + */ + private String getNodeNameByActivityId(String processDefinitionId, String activityId) { + // 获取流程模型 + BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId); + if (bpmnModel == null) { + throw new RuntimeException("未找到流程定义ID=" + processDefinitionId + "的模型"); + } + + // 从模型中获取节点信息(FlowNode包含用户任务、网关等节点) + FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(activityId); + return flowNode != null ? flowNode.getName() : null; + } + + /** + * 根据当前节点查询下一个节点的负责人 + */ + private Long getNextAssignee(String currentNodeName, String processInstanceId) { + // 获取当前登录用户的部门id + Long currentDeptId = SecurityUtils.getDeptId(); + if (currentDeptId == null) { + throw new RuntimeException("当前登录用户未分配部门,无法匹配学务负责人"); + } + // 注意:节点名称需与BPMN模型中完全一致(区分大小写) + switch (currentNodeName) { + case "辅导员审批": + // 辅导员通过后 → 下一个节点:学务(筛选出角色ID=105,且与当前部门一致) + // 查询角色ID=105(学务)的所有用户 + SysUser queryUser = new SysUser(); + queryUser.setRoleId(105L); // 学务角色固定ID + List academicAffairsUsers = sysUserService.selectAllocatedList(queryUser); + if (academicAffairsUsers.isEmpty()) { + throw new RuntimeException("未查询到角色ID=105(学务)的用户"); + } + + // 3. 从学务用户中筛选出部门ID与当前辅导员部门一致的用户 + SysUser targetAcademic = academicAffairsUsers.stream() + .filter(user -> currentDeptId.equals(user.getDeptId())) // 部门ID匹配 + .findFirst() // 取第一个匹配的学务(若有多个,可根据排序或优先级调整) + .orElseThrow(() -> new RuntimeException("未找到部门ID=" + currentDeptId + "的学务负责人")); + + // 4. 返回匹配的学务用户ID(作为下一个节点负责人) + return targetAcademic.getUserId(); + + case "学务审批": + // 学务通过后 → 下一个节点:二级学院(角色ID=106,匹配学生所属学院) + // 查询当前流程对应的业务数据(获取学生所属学院ID) +// RtEnlistmentReserve reserve = enlistmentReserveMapper.selectRtEnlistmentReserveByProcessInstanceId(processInstanceId); +// if (reserve == null) { +// throw new RuntimeException("未查询到流程对应的业务数据,processInstanceId=" + processInstanceId); +// } + + // 查询角色ID=106(二级学院)的所有用户 + SysUser qUser = new SysUser(); + qUser.setRoleId(106L); // 二级学院角色固定ID=106 + List collegeUsers = sysUserService.selectAllocatedList(qUser); + if (collegeUsers.isEmpty()) { + throw new RuntimeException("未查询到角色ID=106(二级学院)的用户"); + } + + // 筛选出部门ID(学院ID)与登录用户所属学院一致的二级学院负责人 + SysUser targetCollegeLeader = collegeUsers.stream() + .filter(user -> currentDeptId.equals(user.getDeptId())) // 学院ID匹配(部门ID即学院ID) + .findFirst() + .orElseThrow(() -> new RuntimeException("未找到学院ID=" + currentDeptId + "的二级学院负责人(角色ID=106)")); + + // 4. 返回匹配的二级学院负责人ID + return targetCollegeLeader.getUserId(); + + case "二级学院审批": + // 二级学院通过后 → 下一个节点:学籍管理科(假设部门ID=30) + return 30L; + + case "学籍管理科审批": + // 学籍管理科通过后 → 下一个节点:教务处(假设部门ID=40) + return 40L; + + case "教务处主管领导审批": + // 最后一个节点通过后 → 流程结束(无需设置负责人) + return null; + + default: + throw new RuntimeException("未配置节点[" + currentNodeName + "]的下一个负责人规则"); + } + } +} \ No newline at end of file diff --git a/srs-routine/src/main/java/com/srs/routine/domain/RtEnlistmentReserve.java b/srs-routine/src/main/java/com/srs/routine/domain/RtEnlistmentReserve.java index 168780c..b1e81ba 100644 --- a/srs-routine/src/main/java/com/srs/routine/domain/RtEnlistmentReserve.java +++ b/srs-routine/src/main/java/com/srs/routine/domain/RtEnlistmentReserve.java @@ -50,6 +50,15 @@ private static final long serialVersionUID=1L; @Excel(name = "学生ID" , readConverterExp = "关=联sys_user") private Long studentId; + + /** + * 辅导员姓名 + */ + @ApiModelProperty("辅导员姓名") + @TableField("teacher_name") + @Excel(name = "辅导员姓名") + private String teacherName; + /** * 姓名 */ diff --git a/srs-routine/src/main/java/com/srs/routine/mapper/RtEnlistmentReserveMapper.java b/srs-routine/src/main/java/com/srs/routine/mapper/RtEnlistmentReserveMapper.java index a67ef33..f5ef192 100644 --- a/srs-routine/src/main/java/com/srs/routine/mapper/RtEnlistmentReserveMapper.java +++ b/srs-routine/src/main/java/com/srs/routine/mapper/RtEnlistmentReserveMapper.java @@ -22,6 +22,14 @@ public interface RtEnlistmentReserveMapper extends BaseMapper public TeacherVo getCounselorInfo(String stuNo); diff --git a/srs-routine/src/main/java/com/srs/routine/service/impl/RtEnlistmentReserveServiceImpl.java b/srs-routine/src/main/java/com/srs/routine/service/impl/RtEnlistmentReserveServiceImpl.java index efcca06..7127e02 100644 --- a/srs-routine/src/main/java/com/srs/routine/service/impl/RtEnlistmentReserveServiceImpl.java +++ b/srs-routine/src/main/java/com/srs/routine/service/impl/RtEnlistmentReserveServiceImpl.java @@ -99,7 +99,7 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl - + + @@ -29,14 +30,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, apply_no, student_id, student_name, gender, nation, grade, student_no, class_name, major, family_address, parent_phone, apply_reason, apply_status, process_instance_id, reserve_no, reserve_start_date, reserve_end_date, approval_no, create_time, update_time from rt_enlistment_reserve + select id, apply_no, student_id, teacher_name, student_name, gender, nation, grade, student_no, class_name, major, family_address, parent_phone, apply_reason, apply_status, process_instance_id, reserve_no, reserve_start_date, reserve_end_date, approval_no, create_time, update_time from rt_enlistment_reserve + + - + insert into rt_enlistment_reserve apply_no, student_id, + teacher_name, student_name, gender, nation, @@ -94,10 +102,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" approval_no, create_time, update_time, - + #{applyNo}, #{studentId}, + #{teacherName}, #{studentName}, #{gender}, #{nation}, @@ -116,7 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{approvalNo}, #{createTime}, #{updateTime}, - + @@ -124,6 +133,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" apply_no = #{applyNo}, student_id = #{studentId}, + teacher_name = #{teacherName}, student_name = #{studentName}, gender = #{gender}, nation = #{nation}, @@ -151,7 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from rt_enlistment_reserve where id in + delete from rt_enlistment_reserve where id in #{id}