dongyukun
6 天以前 ed8fc5f674544d3af63c6f68093ffc038385c493
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.iailab.module.bpm.framework.flowable.core.listener;
 
import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
import com.google.common.collect.ImmutableSet;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Set;
 
/**
 * 监听 {@link ProcessInstance} 的状态变更,更新其对应的 status 状态
 *
 * @author jason
 */
@Component
public class BpmProcessInstanceEventListener extends AbstractFlowableEngineEventListener {
 
    public static final Set<FlowableEngineEventType> PROCESS_INSTANCE_EVENTS = ImmutableSet.<FlowableEngineEventType>builder()
            .add(FlowableEngineEventType.PROCESS_COMPLETED)
            .build();
 
    @Resource
    @Lazy // 延迟加载,避免循环依赖
    private BpmProcessInstanceService processInstanceService;
 
    public BpmProcessInstanceEventListener(){
        super(PROCESS_INSTANCE_EVENTS);
    }
 
    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        processInstanceService.processProcessInstanceCompleted((ProcessInstance)event.getEntity());
    }
}