Commit 0075d19f88f695cc3a0122f3e7d1a05a9514787a

Authored by YunaiV
1 parent 28aeb8a6

feat:优化 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1554 代码的小排版

yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
@@ -66,7 +66,8 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { @@ -66,7 +66,8 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
66 66
67 @Override 67 @Override
68 protected void taskAssigned(FlowableEngineEntityEvent event) { 68 protected void taskAssigned(FlowableEngineEntityEvent event) {
69 - taskService.processTaskAssigned((Task) event.getEntity()); 69 + Task entity = (Task) event.getEntity();
  70 + FlowableUtils.execute(entity.getTenantId(), () -> taskService.processTaskAssigned(entity));
70 } 71 }
71 72
72 @Override 73 @Override
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
@@ -478,17 +478,19 @@ public class BpmnModelUtils { @@ -478,17 +478,19 @@ public class BpmnModelUtils {
478 if (source == null || source instanceof StartEvent || source instanceof SubProcess) { 478 if (source == null || source instanceof StartEvent || source instanceof SubProcess) {
479 return; 479 return;
480 } 480 }
481 - 481 + // 获取入口连线
482 List<SequenceFlow> incomingFlows = getElementIncomingFlows(source); 482 List<SequenceFlow> incomingFlows = getElementIncomingFlows(source);
483 if (CollUtil.isEmpty(incomingFlows)) { 483 if (CollUtil.isEmpty(incomingFlows)) {
484 return; 484 return;
485 } 485 }
486 486
  487 + // 循环找到目标元素
487 for (SequenceFlow incomingFlow : incomingFlows) { 488 for (SequenceFlow incomingFlow : incomingFlows) {
488 // 如果发现连线重复,说明连线已经走过。跳过 489 // 如果发现连线重复,说明连线已经走过。跳过
489 if (incomingFlow == null || !visitedSequenceFlowIds.add(incomingFlow.getId())) { 490 if (incomingFlow == null || !visitedSequenceFlowIds.add(incomingFlow.getId())) {
490 continue; 491 continue;
491 } 492 }
  493 + // 如果 source 是 UserTask,则添加到结果中
492 FlowElement sourceFlowElement = incomingFlow.getSourceFlowElement(); 494 FlowElement sourceFlowElement = incomingFlow.getSourceFlowElement();
493 if (sourceFlowElement instanceof UserTask) { 495 if (sourceFlowElement instanceof UserTask) {
494 if (resultSequenceFlowIds.add(incomingFlow.getId())) { 496 if (resultSequenceFlowIds.add(incomingFlow.getId())) {
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
@@ -1470,6 +1470,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1470,6 +1470,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1470 log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId()); 1470 log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId());
1471 return; 1471 return;
1472 } 1472 }
  1473 +
1473 // 需要基于 instance 设置租户编号,避免 Flowable 内部异步执行时【例如:超时自动通过】 丢失租户编号 1474 // 需要基于 instance 设置租户编号,避免 Flowable 内部异步执行时【例如:超时自动通过】 丢失租户编号
1474 FlowableUtils.execute(processInstance.getTenantId(), () -> { 1475 FlowableUtils.execute(processInstance.getTenantId(), () -> {
1475 // 自动去重,通过自动审批的方式 1476 // 自动去重,通过自动审批的方式
@@ -1499,10 +1500,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1499,10 +1500,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1499 List<String> sourceTaskIds = convertList(BpmnModelUtils.getElementIncomingUserTaskFlows( // 获取所有的上一个 UserTask 节点连线 1500 List<String> sourceTaskIds = convertList(BpmnModelUtils.getElementIncomingUserTaskFlows( // 获取所有的上一个 UserTask 节点连线
1500 BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey())), 1501 BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey())),
1501 SequenceFlow::getSourceRef); 1502 SequenceFlow::getSourceRef);
1502 - // 设置 taskIds, 并按创建时间倒序排序  
1503 - sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds)  
1504 - .orderByTaskCreateTime()  
1505 - .desc(); 1503 + sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).orderByTaskCreateTime().desc(); // 设置 taskIds, 并按创建时间倒序排序
1506 HistoricTaskInstance firstHisTask = CollUtil.getFirst(sameAssigneeQuery.list()); 1504 HistoricTaskInstance firstHisTask = CollUtil.getFirst(sameAssigneeQuery.list());
1507 if (firstHisTask != null && StrUtil.equals(firstHisTask.getAssignee(), task.getAssignee())) { 1505 if (firstHisTask != null && StrUtil.equals(firstHisTask.getAssignee(), task.getAssignee())) {
1508 getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1506 getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
@@ -1571,6 +1569,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1571,6 +1569,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1571 } 1569 }
1572 } 1570 }
1573 1571
  1572 + // 发送消息
1574 AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())); 1573 AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId()));
1575 messageService.sendMessageWhenTaskAssigned(BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task)); 1574 messageService.sendMessageWhenTaskAssigned(BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
1576 }); 1575 });