入伍保留学籍申请-驳回到学生申请,学生修改重新提交申请代码逻辑

This commit is contained in:
962704835@qq.com
2025-11-25 21:41:39 +08:00
parent bf5f1b558c
commit c0fca88261

View File

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import com.srs.routine.mapper.RtStuLeaveApplicationMapper;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.IdentityService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,6 +48,15 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl<RtEnlistmentRese
@Autowired
IdentityService identityService;
// 新增注入RuntimeService之前缺失
@Autowired
private RuntimeService runtimeService;
// 辅导员审批节点的名称(直接使用中文名称匹配)
private static final String COUNSELOR_TASK_NAME = "辅导员审批";
/**
* 查询应征入伍保留学籍申请
*
@@ -157,6 +167,39 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl<RtEnlistmentRese
if (isProcessStarted) {
// 流程已启动:仅更新数据库,不操作流程(避免重复启动)
System.out.println("申请表[" + rtEnlistmentReserve.getId() + "]流程已启动实例ID" + existing.getProcessInstanceId() + "),仅更新数据");
// ========== 核心新增逻辑:学生自动完成自己的待办任务 ==========
String processInstanceId = existing.getProcessInstanceId();
Long studentId = SecurityUtils.getUserId(); // 获取当前操作的学生ID
String studentUserId = studentId.toString(); // 转换为Flowable的Assignee字符串类型
// 1. 查询学生当前的待办任务流程实例ID+学生ID作为负责人
List<Task> studentTaskList = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.taskAssignee(studentUserId) // 学生作为任务负责人
.active() // 仅查询活跃任务
.list();
if (!studentTaskList.isEmpty()) {
for (Task studentTask : studentTaskList) {
// 补充完成任务的流程变量(如审批意见、结果,根据你的流程需求设置)
Map<String, Object> completeVariables = new HashMap<>();
completeVariables.put("approvalResult", "AGREE"); // 学生提交(默认同意)
completeVariables.put("approvalOpinion", "学生自动提交申请,等待辅导员审批");
completeVariables.put("operator", "student"); // 操作人类型
// 2. 学生自动完成待办任务
taskService.complete(studentTask.getId(), completeVariables);
System.out.println("学生[" + studentUserId + "]已自动完成待办任务任务ID" + studentTask.getId());
}
// 3. 分配下一节点(辅导员)的待办任务负责人【不再复用监听器,独立实现】
assignCounselorTask(processInstanceId, existing.getId(), existing.getStudentNo());
} else {
System.out.println("流程实例[" + processInstanceId + "]中未查询到学生[" + studentUserId + "]的待办任务,无需自动完成");
}
// 同步更新流程变量(将业务表状态同步到流程中)
runtimeService.setVariable(processInstanceId, "applyStatus", rtEnlistmentReserve.getApplyStatus());
// 注意:若需更新流程相关变量,需调用 Flowable 的 runtimeService.setVariables(),此处仅更新业务表
return rtEnlistmentReserveMapper.updateRtEnlistmentReserve(rtEnlistmentReserve);
} else {
@@ -186,6 +229,57 @@ public class RtEnlistmentReserveServiceImpl extends ServiceImpl<RtEnlistmentRese
}
}
/**
* 核心辅助方法:为辅导员审批节点分配负责人【独立实现,不复用监听器】
* 支持三种常见的辅导员ID获取方式根据你的业务场景选择其一即可
* @param processInstanceId 流程实例ID
* @param enlistmentId 入伍申请表ID用于从业务表查询辅导员
*/
private void assignCounselorTask(String processInstanceId, Long enlistmentId, String studentNo) {
// 1. 查询辅导员审批节点的待办任务
List<Task> counselorTaskList = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.taskName(COUNSELOR_TASK_NAME) // 直接使用节点名称匹配
.active() // 仅查询活跃任务
.list();
if (counselorTaskList.isEmpty()) {
System.out.println("流程实例[" + processInstanceId + "]中未生成辅导员审批节点的待办任务,无需分配负责人");
return;
}
// 2. 获取辅导员ID
// 查询辅导员信息
TeacherVo counselorInfo = rtEnlistmentReserveMapper.getCounselorInfo(studentNo);
if (counselorInfo == null) {
throw new ServiceException("申请表[" + enlistmentId + "]根据学生学号[" + studentNo + "]未查询到辅导员信息,分配失败", 500);
}
// 4. Long类型的用户ID转换为String避免空指针+类型转换)
Long counselorUserId = counselorInfo.getUserId();
if (counselorUserId == null) {
throw new ServiceException("辅导员的用户ID为空无法分配审批任务", 500);
}
String counselorIdStr = counselorUserId.toString(); // Long转String
if (StringUtils.isBlank(counselorIdStr)) {
throw new ServiceException("申请表[" + enlistmentId + "]未查询到辅导员信息,分配失败", 500);
}
// 3. 为辅导员节点的待办任务设置负责人
for (Task counselorTask : counselorTaskList) {
taskService.setAssignee(counselorTask.getId(), counselorIdStr);
// 可选:添加任务分配的备注(便于流程追溯)
taskService.addComment(
counselorTask.getId(),
processInstanceId,
"自动分配负责人",
"学生已经重新修改提交申请"
);
System.out.println("辅导员审批节点任务[" + counselorTask.getId() + "]已分配负责人:" + counselorIdStr);
}
}
/**
* 开启应征入伍保留学籍申请工作流
*