|
@@ -1,17 +1,27 @@
|
|
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener;
|
|
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
|
|
|
+import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
|
|
import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService;
|
|
import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService;
|
|
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
|
|
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.flowable.bpmn.model.BoundaryEvent;
|
|
|
|
+import org.flowable.bpmn.model.BpmnModel;
|
|
|
|
+import org.flowable.bpmn.model.FlowElement;
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
|
|
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
|
|
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
|
|
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
|
|
import org.flowable.engine.delegate.event.FlowableActivityCancelledEvent;
|
|
import org.flowable.engine.delegate.event.FlowableActivityCancelledEvent;
|
|
import org.flowable.engine.history.HistoricActivityInstance;
|
|
import org.flowable.engine.history.HistoricActivityInstance;
|
|
|
|
+import org.flowable.job.api.Job;
|
|
import org.flowable.task.api.Task;
|
|
import org.flowable.task.api.Task;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -28,6 +38,9 @@ import java.util.Set;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
|
|
public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ @Lazy // 延迟加载,避免循环依赖
|
|
|
|
+ private BpmModelService modelService;
|
|
@Resource
|
|
@Resource
|
|
@Lazy // 解决循环依赖
|
|
@Lazy // 解决循环依赖
|
|
private BpmTaskService taskService;
|
|
private BpmTaskService taskService;
|
|
@@ -40,6 +53,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
|
|
.add(FlowableEngineEventType.TASK_ASSIGNED)
|
|
.add(FlowableEngineEventType.TASK_ASSIGNED)
|
|
// .add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,所以不需要监听了。
|
|
// .add(FlowableEngineEventType.TASK_COMPLETED) // 由于审批通过时,已经记录了 task 的 status 为通过,所以不需要监听了。
|
|
.add(FlowableEngineEventType.ACTIVITY_CANCELLED)
|
|
.add(FlowableEngineEventType.ACTIVITY_CANCELLED)
|
|
|
|
+ .add(FlowableEngineEventType.TIMER_FIRED) // 监听审批超时
|
|
.build();
|
|
.build();
|
|
|
|
|
|
public BpmTaskEventListener() {
|
|
public BpmTaskEventListener() {
|
|
@@ -72,4 +86,30 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void timerFired(FlowableEngineEntityEvent event) {
|
|
|
|
+ // 1.1 只处理 BoundaryEvent 边界计时时间
|
|
|
|
+ String processDefinitionId = event.getProcessDefinitionId();
|
|
|
|
+ BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processDefinitionId);
|
|
|
|
+ Job entity = (Job) event.getEntity();
|
|
|
|
+ FlowElement element = BpmnModelUtils.getFlowElementById(bpmnModel, entity.getElementId());
|
|
|
|
+ if (!(element instanceof BoundaryEvent)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 1.2 判断是否为超时处理
|
|
|
|
+ BoundaryEvent boundaryEvent = (BoundaryEvent) element;
|
|
|
|
+ String boundaryEventType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
|
|
|
|
+ BpmnModelConstants.BOUNDARY_EVENT_TYPE);
|
|
|
|
+ BpmBoundaryEventType bpmTimerBoundaryEventType = BpmBoundaryEventType.typeOf(NumberUtils.parseInt(boundaryEventType));
|
|
|
|
+ if (ObjectUtil.notEqual(bpmTimerBoundaryEventType, BpmBoundaryEventType.USER_TASK_TIMEOUT)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. 处理超时
|
|
|
|
+ String timeoutAction = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
|
|
|
|
+ BpmnModelConstants.USER_TASK_TIMEOUT_HANDLER_ACTION);
|
|
|
|
+ String taskKey = boundaryEvent.getAttachedToRefId();
|
|
|
|
+ taskService.processTaskTimeout(event.getProcessInstanceId(), taskKey, NumberUtils.parseInt(timeoutAction));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|