houzhongjian
2024-12-03 874287a4c02d0a980d8b97c4a691b4f37ec5e812
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.framework.flowable.core.listener;
H 2
3 import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
4 import com.google.common.collect.ImmutableSet;
5 import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
6 import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
7 import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
8 import org.flowable.engine.delegate.event.FlowableCancelledEvent;
9 import org.flowable.engine.runtime.ProcessInstance;
10 import org.springframework.context.annotation.Lazy;
11 import org.springframework.stereotype.Component;
12
13 import javax.annotation.Resource;
14 import java.util.Set;
15
16 /**
17  * 监听 {@link ProcessInstance} 的状态变更,更新其对应的 status 状态
18  *
19  * @author jason
20  */
21 @Component
22 public class BpmProcessInstanceEventListener extends AbstractFlowableEngineEventListener {
23
24     @Resource
25     @Lazy
26     private BpmProcessInstanceService processInstanceService;
27
28     public static final Set<FlowableEngineEventType> PROCESS_INSTANCE_EVENTS = ImmutableSet.<FlowableEngineEventType>builder()
29                      .add(FlowableEngineEventType.PROCESS_CANCELLED)
30                      .add(FlowableEngineEventType.PROCESS_COMPLETED)
31                      .build();
32
33     public BpmProcessInstanceEventListener(){
34         super(PROCESS_INSTANCE_EVENTS);
35     }
36
37     @Override
38     protected void processCancelled(FlowableCancelledEvent event) {
39         processInstanceService.updateProcessInstanceWhenCancel(event);
40     }
41
42     @Override
43     protected void processCompleted(FlowableEngineEntityEvent event) {
44         processInstanceService.updateProcessInstanceWhenApprove((ProcessInstance)event.getEntity());
45     }
46
47 }