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