diff --git a/srs-flowable/src/main/java/com/srs/flowable/service/impl/FlowTaskServiceImpl.java b/srs-flowable/src/main/java/com/srs/flowable/service/impl/FlowTaskServiceImpl.java index 538fdf8..2866b62 100644 --- a/srs-flowable/src/main/java/com/srs/flowable/service/impl/FlowTaskServiceImpl.java +++ b/srs-flowable/src/main/java/com/srs/flowable/service/impl/FlowTaskServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.TypeReference; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.srs.common.core.domain.AjaxResult; +import com.srs.common.core.domain.entity.SysDept; import com.srs.common.core.domain.entity.SysRole; import com.srs.common.core.domain.entity.SysUser; @@ -27,6 +28,7 @@ import com.srs.flowable.service.IFlowTaskService; import com.srs.flowable.service.ISysDeployFormService; import com.srs.flowable.service.ISysFormService; import com.srs.system.domain.SysForm; +import com.srs.system.mapper.SysDeptMapper; import com.srs.system.service.ISysRoleService; import com.srs.system.service.ISysUserService; import com.sun.jna.platform.win32.OaIdl; @@ -55,6 +57,7 @@ import org.flowable.task.api.Task; import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -818,6 +821,9 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask return t -> seen.add(keyExtractor.apply(t)); } + @Autowired + SysDeptMapper sysDeptMapper; + /** * 流程历史流转记录 * @@ -876,8 +882,22 @@ public class FlowTaskServiceImpl extends FlowServiceFactory implements IFlowTask stringBuilder.append(sysUser.getNickName()).append(","); } if (StringUtils.isNotBlank(identityLink.getGroupId())) { +// SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); +// stringBuilder.append(sysRole.getRoleName()).append(","); + // 尝试按角色ID查询 SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); - stringBuilder.append(sysRole.getRoleName()).append(","); + if (sysRole != null) { + stringBuilder.append(sysRole.getRoleName()).append(","); + } else { + // 若角色不存在,尝试按部门ID查询(很多场景下groupId实际是部门ID) + SysDept sysDept = sysDeptMapper.selectDeptById(Long.parseLong(identityLink.getGroupId())); + if (sysDept != null) { + stringBuilder.append(sysDept.getDeptName()).append(","); + } else { + // 若都不存在,显示原始ID(避免报错,方便排查) + stringBuilder.append("未知分组(").append(identityLink.getGroupId()).append("),"); + } + } } } } diff --git a/srs-routine/pom.xml b/srs-routine/pom.xml index 6d6f16e..e5d6c6e 100644 --- a/srs-routine/pom.xml +++ b/srs-routine/pom.xml @@ -104,6 +104,12 @@ com.srs srs-comprehensive + + io.github.classgraph + classgraph + 4.8.149 + compile + 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 32ecfac..a67ef33 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 @@ -2,8 +2,10 @@ package com.srs.routine.mapper; import java.util.List; +import com.srs.common.doman.vo.TeacherVo; import com.srs.routine.domain.RtEnlistmentReserve; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Options; /** * 应征入伍保留学籍申请Mapper接口 @@ -20,6 +22,9 @@ public interface RtEnlistmentReserveMapper extends BaseMapper + public TeacherVo getCounselorInfo(String stuNo); + /** * 查询应征入伍保留学籍申请列表 * @@ -34,6 +39,7 @@ public interface RtEnlistmentReserveMapper extends BaseMapper variables = new HashMap<>(); - variables.put("applyNo", rtEnlistmentReserve.getApplyNo().toString()); -// variables.put("applyNo", rtEnlistmentReserve.getReserveNo()); + // 1. 传递关键变量(申请编号+主键ID,用于任务匹配) + String applyNo = rtEnlistmentReserve.getApplyNo(); // 申请编号(如RY2024001) + Long enlistmentId = rtEnlistmentReserve.getId(); // 申请表主键ID + variables.put("applyNo", applyNo); + variables.put("enlistmentId", enlistmentId); // 新增:用于任务匹配的主键变量 variables.put("stuId", rtEnlistmentReserve.getStudentId()); - TeacherVo counselorInfo = rtStuLeaveApplicationMapper.getCounselorInfo(rtEnlistmentReserve.getStudentId()); - // 把辅导员的userId放到approval中 - variables.put("approval", counselorInfo.getUserId()); + + // 2. 查询辅导员信息 + TeacherVo counselorInfo = rtEnlistmentReserveMapper.getCounselorInfo(rtEnlistmentReserve.getStudentNo()); + if (counselorInfo == null) { + throw new ServiceException("该学生暂无辅导员", 500); + } + variables.put("approval", counselorInfo.getUserId()); // 下一节点:辅导员 variables.put("deptId", counselorInfo.getDeptId()); - //flow_m4npextk:28:257686 flow_m4npextk:31:755004 - AjaxResult ajaxResult = flowDefinitionService.startProcessInstanceById("flow_r064jfpz:3:1027504", variables); + // 3. 启动流程 + AjaxResult ajaxResult = flowDefinitionService.startProcessInstanceById("flow_r064jfpz:4:1032511", variables); String code = ajaxResult.get("code").toString(); - if (code.equals("200")) { - - System.out.println("流程启动成功"); - - Object obj = ajaxResult.get("data"); - ProcessResultDto dto = (ProcessResultDto) obj; - - // 操作工作流 - // 设置当前用户 - identityService.setAuthenticatedUserId(SecurityUtils.getUserId().toString()); - // 查询待办任务列表 - List tasks = taskService.createTaskQuery() - .processInstanceId(dto.getProcessInstanceId()) - .taskAssignee(SecurityUtils.getUserId().toString()) - .active() - .list(); - // 保存审核结果到任务变量中 - variables.put("approved", true); - // 完成待办任务列表 - for (Task task : tasks) { - String taskId = task.getId(); - String leaveId = taskService.getVariable(taskId, "enlistmentReserveId").toString(); - if (leaveId.equals(rtEnlistmentReserve.getId().toString())) { - taskService.complete(task.getId(), variables); - } - } - - // todo 企业微信推送消息 - - - return dto; - } else { - return null; + if (!"200".equals(code)) { + throw new ServiceException("流程启动失败,错误码:" + code, 500); } + + ProcessResultDto dto = (ProcessResultDto) ajaxResult.get("data"); + System.out.println("流程启动成功,实例ID:" + dto.getProcessInstanceId()); + + // 4. 学生自动完成自己的待办任务 + identityService.setAuthenticatedUserId(SecurityUtils.getUserId().toString()); + // 精准查询当前流程中属于学生的待办任务 + List tasks = taskService.createTaskQuery() + .processInstanceId(dto.getProcessInstanceId()) + .taskAssignee(SecurityUtils.getUserId().toString()) + .active() + .list(); + + if (tasks.isEmpty()) { + throw new ServiceException("未查询到学生的待办任务,请检查流程设计", 500); + } + + // 5. 完成任务(匹配主键ID,避免错误) + variables.put("approved", true); // 学生提交确认 + for (Task task : tasks) { + // 安全获取变量:先判断是否为null,再转换类型 + Object varValue = taskService.getVariable(task.getId(), "enlistmentId"); + if (varValue == null) { + continue; + } + // 转换为Long类型(与主键ID匹配) + Long taskEnlistmentId; + try { + taskEnlistmentId = Long.parseLong(varValue.toString()); + } catch (NumberFormatException e) { + continue; // 类型不匹配,跳过 + } + // 匹配当前申请表的主键ID + if (taskEnlistmentId.equals(enlistmentId)) { + taskService.complete(task.getId(), variables); + System.out.println("学生已完成待办任务,任务ID:" + task.getId()); + break; // 完成后退出循环,避免重复处理 + } + } + + // 6. 推送消息给辅导员(待办提醒) + // todo: 企业微信推送逻辑 + + return dto; } /** diff --git a/srs-routine/src/main/resources/mapper/routine/RtEnlistmentReserveMapper.xml b/srs-routine/src/main/resources/mapper/routine/RtEnlistmentReserveMapper.xml index 051ee1f..1858771 100644 --- a/srs-routine/src/main/resources/mapper/routine/RtEnlistmentReserveMapper.xml +++ b/srs-routine/src/main/resources/mapper/routine/RtEnlistmentReserveMapper.xml @@ -60,6 +60,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + + insert into rt_enlistment_reserve