【代码评审】BPM:子流程的超时

This commit is contained in:
YunaiV 2025-02-25 12:41:30 +08:00
parent f7e4293ed2
commit 48c976cf0a
6 changed files with 24 additions and 21 deletions

View File

@ -110,6 +110,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
} else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) { } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) {
String taskKey = boundaryEvent.getAttachedToRefId(); String taskKey = boundaryEvent.getAttachedToRefId();
taskService.triggerReceiveTask(event.getProcessInstanceId(), taskKey); taskService.triggerReceiveTask(event.getProcessInstanceId(), taskKey);
// 2.3 子流程超时处理
} else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT)) { } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT)) {
String taskKey = boundaryEvent.getAttachedToRefId(); String taskKey = boundaryEvent.getAttachedToRefId();
taskService.processChildProcessTimeout(event.getProcessInstanceId(), taskKey); taskService.processChildProcessTimeout(event.getProcessInstanceId(), taskKey);

View File

@ -416,6 +416,7 @@ public class SimpleModelUtils {
private BoundaryEvent buildUserTaskTimeoutBoundaryEvent(UserTask userTask, private BoundaryEvent buildUserTaskTimeoutBoundaryEvent(UserTask userTask,
BpmSimpleModelNodeVO.TimeoutHandler timeoutHandler) { BpmSimpleModelNodeVO.TimeoutHandler timeoutHandler) {
// 1.1 定时器边界事件 // 1.1 定时器边界事件
// TODO @lesan一些 BoundaryEvent timeout 可以做一些基础的设置么
BoundaryEvent boundaryEvent = new BoundaryEvent(); BoundaryEvent boundaryEvent = new BoundaryEvent();
boundaryEvent.setId("Event-" + IdUtil.fastUUID()); boundaryEvent.setId("Event-" + IdUtil.fastUUID());
boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断 boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断
@ -723,6 +724,7 @@ public class SimpleModelUtils {
// 2. 添加接收任务的 Timer Boundary Event // 2. 添加接收任务的 Timer Boundary Event
if (node.getDelaySetting() != null) { if (node.getDelaySetting() != null) {
// 2.1 定时器边界事件 // 2.1 定时器边界事件
// TODO @lesan一些 BoundaryEvent timeout 可以做一些基础的设置么
BoundaryEvent boundaryEvent = new BoundaryEvent(); BoundaryEvent boundaryEvent = new BoundaryEvent();
boundaryEvent.setId("Event-" + IdUtil.fastUUID()); boundaryEvent.setId("Event-" + IdUtil.fastUUID());
boundaryEvent.setCancelActivity(false); boundaryEvent.setCancelActivity(false);
@ -872,6 +874,7 @@ public class SimpleModelUtils {
// 7. 超时设置 // 7. 超时设置
if (childProcessSetting.getTimeoutSetting() != null) { if (childProcessSetting.getTimeoutSetting() != null) {
// TODO @lesan一些 BoundaryEvent timeout 可以做一些基础的设置么
BoundaryEvent boundaryEvent = new BoundaryEvent(); BoundaryEvent boundaryEvent = new BoundaryEvent();
boundaryEvent.setId("Event-" + IdUtil.fastUUID()); boundaryEvent.setId("Event-" + IdUtil.fastUUID());
boundaryEvent.setCancelActivity(false); boundaryEvent.setCancelActivity(false);

View File

@ -414,7 +414,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 处理每个任务的 tasks 属性 // 处理每个任务的 tasks 属性
for (HistoricActivityInstance activity : taskActivities) { for (HistoricActivityInstance activity : taskActivities) {
HistoricTaskInstance task = taskMap.get(activity.getTaskId()); HistoricTaskInstance task = taskMap.get(activity.getTaskId());
// TODO @lesan这里为啥 continue @芋艿子流程的 activity task 是null 下面的方法会报错 // TODO @lesan这里为啥 continue @芋艿子流程的 activity task 是null 下面的方法会报错TODO @lesan写个注释
if (task == null) { if (task == null) {
continue; continue;
} }

View File

@ -276,6 +276,14 @@ public interface BpmTaskService {
*/ */
void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType); void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType);
/**
* 处理 ChildProcess 子流程的审批超时事件
*
* @param processInstanceId 流程示例编号
* @param taskDefineKey 任务 Key
*/
void processChildProcessTimeout(String processInstanceId, String taskDefineKey);
// TODO @jason改成 triggerTask然后触发 ReceiveTask让流程继续执行改成一些调用场景 // TODO @jason改成 triggerTask然后触发 ReceiveTask让流程继续执行改成一些调用场景
/** /**
* 触发 ReceiveTask让流程继续执行 * 触发 ReceiveTask让流程继续执行
@ -285,12 +293,4 @@ public interface BpmTaskService {
*/ */
void triggerReceiveTask(String processInstanceId, String taskDefineKey); void triggerReceiveTask(String processInstanceId, String taskDefineKey);
/**
* 处理 子流程 审批超时事件
*
* @param processInstanceId 流程示例编号
* @param taskDefineKey 任务 Key
*/
void processChildProcessTimeout(String processInstanceId, String taskDefineKey);
} }

View File

@ -1323,6 +1323,16 @@ public class BpmTaskServiceImpl implements BpmTaskService {
})); }));
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void processChildProcessTimeout(String processInstanceId, String taskDefineKey) {
List<ActivityInstance> activityInstances = runtimeService.createActivityInstanceQuery()
.processInstanceId(processInstanceId)
.activityId(taskDefineKey).list();
activityInstances.forEach(activityInstance -> FlowableUtils.execute(activityInstance.getTenantId(),
() -> moveTaskToEnd(activityInstance.getCalledProcessInstanceId(), BpmReasonEnum.TIMEOUT_APPROVE.getReason())));
}
@Override @Override
public void triggerReceiveTask(String processInstanceId, String taskDefineKey) { public void triggerReceiveTask(String processInstanceId, String taskDefineKey) {
Execution execution = runtimeService.createExecutionQuery() Execution execution = runtimeService.createExecutionQuery()
@ -1340,17 +1350,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
() -> runtimeService.trigger(execution.getId())); () -> runtimeService.trigger(execution.getId()));
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void processChildProcessTimeout(String processInstanceId, String taskDefineKey) {
List<ActivityInstance> activityInstances = runtimeService.createActivityInstanceQuery()
.processInstanceId(processInstanceId)
.activityId(taskDefineKey).list();
activityInstances.forEach(activityInstance -> FlowableUtils.execute(activityInstance.getTenantId(), () -> {
moveTaskToEnd(activityInstance.getCalledProcessInstanceId(), BpmReasonEnum.TIMEOUT_APPROVE.getReason());
}));
}
/** /**
* 获得自身的代理对象解决 AOP 生效问题 * 获得自身的代理对象解决 AOP 生效问题
* *

View File

@ -82,7 +82,7 @@ public class BpmCallActivityListener implements ExecutionListener {
try { try {
FlowableUtils.setAuthenticatedUserId(Long.parseLong(formFieldValue)); FlowableUtils.setAuthenticatedUserId(Long.parseLong(formFieldValue));
} catch (Exception e) { } catch (Exception e) {
log.error("[error][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]", log.error("[notify][监听器:{},子流程监听器设置流程的发起人字符串转 Long 失败,字符串:{}]",
DELEGATE_EXPRESSION, formFieldValue); DELEGATE_EXPRESSION, formFieldValue);
FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId())); FlowableUtils.setAuthenticatedUserId(Long.parseLong(parent.getStartUserId()));
} }