Commit 48c976cf0a72ff6b1ecc685c6bd13ce2fceb6045
1 parent
f7e4293e
【代码评审】BPM:子流程的超时
Showing
6 changed files
with
21 additions
and
18 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
| @@ -110,6 +110,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { | @@ -110,6 +110,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { | ||
| 110 | } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) { | 110 | } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) { |
| 111 | String taskKey = boundaryEvent.getAttachedToRefId(); | 111 | String taskKey = boundaryEvent.getAttachedToRefId(); |
| 112 | taskService.triggerReceiveTask(event.getProcessInstanceId(), taskKey); | 112 | taskService.triggerReceiveTask(event.getProcessInstanceId(), taskKey); |
| 113 | + // 2.3 子流程超时处理 | ||
| 113 | } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT)) { | 114 | } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT)) { |
| 114 | String taskKey = boundaryEvent.getAttachedToRefId(); | 115 | String taskKey = boundaryEvent.getAttachedToRefId(); |
| 115 | taskService.processChildProcessTimeout(event.getProcessInstanceId(), taskKey); | 116 | taskService.processChildProcessTimeout(event.getProcessInstanceId(), taskKey); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| @@ -416,6 +416,7 @@ public class SimpleModelUtils { | @@ -416,6 +416,7 @@ public class SimpleModelUtils { | ||
| 416 | private BoundaryEvent buildUserTaskTimeoutBoundaryEvent(UserTask userTask, | 416 | private BoundaryEvent buildUserTaskTimeoutBoundaryEvent(UserTask userTask, |
| 417 | BpmSimpleModelNodeVO.TimeoutHandler timeoutHandler) { | 417 | BpmSimpleModelNodeVO.TimeoutHandler timeoutHandler) { |
| 418 | // 1.1 定时器边界事件 | 418 | // 1.1 定时器边界事件 |
| 419 | + // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么? | ||
| 419 | BoundaryEvent boundaryEvent = new BoundaryEvent(); | 420 | BoundaryEvent boundaryEvent = new BoundaryEvent(); |
| 420 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); | 421 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); |
| 421 | boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断 | 422 | boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断 |
| @@ -723,6 +724,7 @@ public class SimpleModelUtils { | @@ -723,6 +724,7 @@ public class SimpleModelUtils { | ||
| 723 | // 2. 添加接收任务的 Timer Boundary Event | 724 | // 2. 添加接收任务的 Timer Boundary Event |
| 724 | if (node.getDelaySetting() != null) { | 725 | if (node.getDelaySetting() != null) { |
| 725 | // 2.1 定时器边界事件 | 726 | // 2.1 定时器边界事件 |
| 727 | + // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么? | ||
| 726 | BoundaryEvent boundaryEvent = new BoundaryEvent(); | 728 | BoundaryEvent boundaryEvent = new BoundaryEvent(); |
| 727 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); | 729 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); |
| 728 | boundaryEvent.setCancelActivity(false); | 730 | boundaryEvent.setCancelActivity(false); |
| @@ -872,6 +874,7 @@ public class SimpleModelUtils { | @@ -872,6 +874,7 @@ public class SimpleModelUtils { | ||
| 872 | 874 | ||
| 873 | // 7. 超时设置 | 875 | // 7. 超时设置 |
| 874 | if (childProcessSetting.getTimeoutSetting() != null) { | 876 | if (childProcessSetting.getTimeoutSetting() != null) { |
| 877 | + // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么? | ||
| 875 | BoundaryEvent boundaryEvent = new BoundaryEvent(); | 878 | BoundaryEvent boundaryEvent = new BoundaryEvent(); |
| 876 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); | 879 | boundaryEvent.setId("Event-" + IdUtil.fastUUID()); |
| 877 | boundaryEvent.setCancelActivity(false); | 880 | boundaryEvent.setCancelActivity(false); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| @@ -414,7 +414,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -414,7 +414,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 414 | // 处理每个任务的 tasks 属性 | 414 | // 处理每个任务的 tasks 属性 |
| 415 | for (HistoricActivityInstance activity : taskActivities) { | 415 | for (HistoricActivityInstance activity : taskActivities) { |
| 416 | HistoricTaskInstance task = taskMap.get(activity.getTaskId()); | 416 | HistoricTaskInstance task = taskMap.get(activity.getTaskId()); |
| 417 | - // TODO @lesan:这里为啥 continue 哈? @芋艿:子流程的 activity 中 task 是null 下面的方法会报错 | 417 | + // TODO @lesan:这里为啥 continue 哈? @芋艿:子流程的 activity 中 task 是null 下面的方法会报错;TODO @lesan:写个注释??? |
| 418 | if (task == null) { | 418 | if (task == null) { |
| 419 | continue; | 419 | continue; |
| 420 | } | 420 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| @@ -276,21 +276,21 @@ public interface BpmTaskService { | @@ -276,21 +276,21 @@ public interface BpmTaskService { | ||
| 276 | */ | 276 | */ |
| 277 | void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType); | 277 | void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType); |
| 278 | 278 | ||
| 279 | - // TODO @jason:改成 triggerTask。然后,“触发 ReceiveTask,让流程继续执行”,改成一些调用场景 | ||
| 280 | /** | 279 | /** |
| 281 | - * 触发 ReceiveTask,让流程继续执行 | 280 | + * 处理 ChildProcess 子流程的审批超时事件 |
| 282 | * | 281 | * |
| 283 | * @param processInstanceId 流程示例编号 | 282 | * @param processInstanceId 流程示例编号 |
| 284 | * @param taskDefineKey 任务 Key | 283 | * @param taskDefineKey 任务 Key |
| 285 | */ | 284 | */ |
| 286 | - void triggerReceiveTask(String processInstanceId, String taskDefineKey); | 285 | + void processChildProcessTimeout(String processInstanceId, String taskDefineKey); |
| 287 | 286 | ||
| 287 | + // TODO @jason:改成 triggerTask。然后,“触发 ReceiveTask,让流程继续执行”,改成一些调用场景 | ||
| 288 | /** | 288 | /** |
| 289 | - * 处理 子流程 审批超时事件 | 289 | + * 触发 ReceiveTask,让流程继续执行 |
| 290 | * | 290 | * |
| 291 | * @param processInstanceId 流程示例编号 | 291 | * @param processInstanceId 流程示例编号 |
| 292 | * @param taskDefineKey 任务 Key | 292 | * @param taskDefineKey 任务 Key |
| 293 | */ | 293 | */ |
| 294 | - void processChildProcessTimeout(String processInstanceId, String taskDefineKey); | 294 | + void triggerReceiveTask(String processInstanceId, String taskDefineKey); |
| 295 | 295 | ||
| 296 | } | 296 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -1324,6 +1324,16 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -1324,6 +1324,16 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 1324 | } | 1324 | } |
| 1325 | 1325 | ||
| 1326 | @Override | 1326 | @Override |
| 1327 | + @Transactional(rollbackFor = Exception.class) | ||
| 1328 | + public void processChildProcessTimeout(String processInstanceId, String taskDefineKey) { | ||
| 1329 | + List<ActivityInstance> activityInstances = runtimeService.createActivityInstanceQuery() | ||
| 1330 | + .processInstanceId(processInstanceId) | ||
| 1331 | + .activityId(taskDefineKey).list(); | ||
| 1332 | + activityInstances.forEach(activityInstance -> FlowableUtils.execute(activityInstance.getTenantId(), | ||
| 1333 | + () -> moveTaskToEnd(activityInstance.getCalledProcessInstanceId(), BpmReasonEnum.TIMEOUT_APPROVE.getReason()))); | ||
| 1334 | + } | ||
| 1335 | + | ||
| 1336 | + @Override | ||
| 1327 | public void triggerReceiveTask(String processInstanceId, String taskDefineKey) { | 1337 | public void triggerReceiveTask(String processInstanceId, String taskDefineKey) { |
| 1328 | Execution execution = runtimeService.createExecutionQuery() | 1338 | Execution execution = runtimeService.createExecutionQuery() |
| 1329 | .processInstanceId(processInstanceId) | 1339 | .processInstanceId(processInstanceId) |
| @@ -1340,17 +1350,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -1340,17 +1350,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 1340 | () -> runtimeService.trigger(execution.getId())); | 1350 | () -> runtimeService.trigger(execution.getId())); |
| 1341 | } | 1351 | } |
| 1342 | 1352 | ||
| 1343 | - @Override | ||
| 1344 | - @Transactional(rollbackFor = Exception.class) | ||
| 1345 | - public void processChildProcessTimeout(String processInstanceId, String taskDefineKey) { | ||
| 1346 | - List<ActivityInstance> activityInstances = runtimeService.createActivityInstanceQuery() | ||
| 1347 | - .processInstanceId(processInstanceId) | ||
| 1348 | - .activityId(taskDefineKey).list(); | ||
| 1349 | - activityInstances.forEach(activityInstance -> FlowableUtils.execute(activityInstance.getTenantId(), () -> { | ||
| 1350 | - moveTaskToEnd(activityInstance.getCalledProcessInstanceId(), BpmReasonEnum.TIMEOUT_APPROVE.getReason()); | ||
| 1351 | - })); | ||
| 1352 | - } | ||
| 1353 | - | ||
| 1354 | /** | 1353 | /** |
| 1355 | * 获得自身的代理对象,解决 AOP 生效问题 | 1354 | * 获得自身的代理对象,解决 AOP 生效问题 |
| 1356 | * | 1355 | * |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmCallActivityListener.java
| @@ -82,7 +82,7 @@ public class BpmCallActivityListener implements ExecutionListener { | @@ -82,7 +82,7 @@ public class BpmCallActivityListener implements ExecutionListener { | ||
| 82 | try { | 82 | try { |
| 83 | FlowableUtils.setAuthenticatedUserId(Long.parseLong(formFieldValue)); | 83 | FlowableUtils.setAuthenticatedUserId(Long.parseLong(formFieldValue)); |
| 84 | } catch (Exception e) { | 84 | } catch (Exception e) { |
| 85 | - log.error("[error][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]", | 85 | + log.error("[notify][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]", |
| 86 | DELEGATE_EXPRESSION, formFieldValue); | 86 | DELEGATE_EXPRESSION, formFieldValue); |
| 87 | FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId())); | 87 | FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId())); |
| 88 | } | 88 | } |