From d5ec37ffcf57e5c72b562df8809b3ec091c04b0f Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Mon, 15 Sep 2025 17:11:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(workflow):=20=E6=B7=BB=E5=8A=A0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=8A=82=E7=82=B9=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 IWfTaskService 接口中添加了 checkTaskNodeType 方法 - 在 WfTaskServiceImpl 类中实现了 checkTaskNodeType 方法 - 优化了 WfProcessServiceImpl 类中的 assignNextUsers 方法注释 --- .../workflow/service/IWfTaskService.java | 7 +++ .../service/impl/WfProcessServiceImpl.java | 22 +------ .../service/impl/WfTaskServiceImpl.java | 59 +++++++++++++++++++ 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IWfTaskService.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IWfTaskService.java index 7fbdda0..78fbbe4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IWfTaskService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/IWfTaskService.java @@ -117,4 +117,11 @@ public interface IWfTaskService { void startFirstTask(ProcessInstance processInstance, Map variables); public List getApprovedRecords(Long userId, String category); + + /** + * 检查任务节点类型 + * @param taskId 任务ID + * @return Map包含isStartNode和isEndNode信息 + */ + Map checkTaskNodeType(String taskId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfProcessServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfProcessServiceImpl.java index cbb27e0..24f8a8d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfProcessServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfProcessServiceImpl.java @@ -888,7 +888,7 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce * * @param bpmnModel 流程模型 * @param processInstanceId 流程实例ID - * @param candidateUsers 审批人字符串 + * @param candidateUsers 审批人ID(单个用户) */ private void assignNextUsers(BpmnModel bpmnModel, String processInstanceId, String candidateUsers) { if (StringUtils.isBlank(candidateUsers)) { @@ -905,25 +905,9 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce return; } - // 解析审批人字符串,格式可能是:userId1,userId2,userId3 - String[] userIds = candidateUsers.split(","); - - // 为每个任务直接指定实际办理人 + // 为每个任务直接指定实际办理人(现在只支持单个用户) for (Task task : tasks) { - // 如果只有一个审批人,直接设置为实际办理人 - if (userIds.length == 1 && StringUtils.isNotBlank(userIds[0])) { - taskService.setAssignee(task.getId(), userIds[0].trim()); - } else if (userIds.length > 1) { - // 如果有多个审批人,设置第一个为实际办理人,其他为候选人 - // 或者根据业务需求,可以只设置候选人让用户自己认领 - taskService.setAssignee(task.getId(), userIds[0].trim()); - // 如果需要其他人也能看到任务,可以添加候选人 - for (int i = 1; i < userIds.length; i++) { - if (StringUtils.isNotBlank(userIds[i])) { - taskService.addCandidateUser(task.getId(), userIds[i].trim()); - } - } - } + taskService.setAssignee(task.getId(), candidateUsers.trim()); } } catch (Exception e) { e.printStackTrace(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfTaskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfTaskServiceImpl.java index b0b841e..0f89c49 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfTaskServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/workflow/service/impl/WfTaskServiceImpl.java @@ -729,4 +729,63 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ } return null; } + + /** + * 检查任务节点类型 + * @param taskId 任务ID + * @return Map包含isStartNode和isEndNode信息 + */ + @Override + public Map checkTaskNodeType(String taskId) { + Map result = new HashMap<>(); + result.put("isStartNode", false); + result.put("isEndNode", false); + + try { + // 获取任务信息 + Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); + if (task == null) { + return result; + } + + // 获取流程定义 + ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() + .processDefinitionId(task.getProcessDefinitionId()) + .singleResult(); + + // 获取BPMN模型 + BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId()); + Process process = bpmnModel.getMainProcess(); + + // 获取当前任务节点 + FlowElement currentElement = process.getFlowElement(task.getTaskDefinitionKey()); + if (currentElement instanceof UserTask) { + UserTask userTask = (UserTask) currentElement; + + // 检查是否为开始节点的下一个节点 + List incomingFlows = userTask.getIncomingFlows(); + for (SequenceFlow flow : incomingFlows) { + FlowElement sourceElement = process.getFlowElement(flow.getSourceRef()); + if (sourceElement instanceof StartEvent) { + result.put("isStartNode", true); + break; + } + } + + // 检查是否为结束节点的上一个节点 + List outgoingFlows = userTask.getOutgoingFlows(); + for (SequenceFlow flow : outgoingFlows) { + FlowElement targetElement = process.getFlowElement(flow.getTargetRef()); + if (targetElement instanceof EndEvent) { + result.put("isEndNode", true); + break; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return result; + } }