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
41
42
43
44
45
package com.iailab.module.bpm.framework.flowable.core.listener;
 
import cn.hutool.core.collection.CollUtil;
import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
import com.iailab.module.bpm.service.task.BpmProcessInstanceCopyService;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Set;
 
/**
 * 处理抄送用户的 {@link JavaDelegate} 的实现类
 * <p>
 * 目前只有仿钉钉/飞书模式的【抄送节点】使用
 *
 * @author hou
 */
@Component(BpmCopyTaskDelegate.BEAN_NAME)
public class BpmCopyTaskDelegate implements JavaDelegate {
 
    public static final String BEAN_NAME = "bpmCopyTaskDelegate";
 
    @Resource
    private BpmTaskCandidateInvoker taskCandidateInvoker;
 
    @Resource
    private BpmProcessInstanceCopyService processInstanceCopyService;
 
    @Override
    public void execute(DelegateExecution execution) {
        // 1. 获得抄送人
        Set<Long> userIds = taskCandidateInvoker.calculateUsersByTask(execution);
        if (CollUtil.isEmpty(userIds)) {
            return;
        }
        // 2. 执行抄送
        FlowElement currentFlowElement = execution.getCurrentFlowElement();
        processInstanceCopyService.createProcessInstanceCopy(userIds, null, execution.getProcessInstanceId(),
                currentFlowElement.getId(), currentFlowElement.getName(), null);
    }
 
}