zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package org.jeecg.common.config;
 
import com.google.common.collect.Lists;
 
import org.activiti.engine.*;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.jeecg.modules.activiti.manage.CustomGroupEntityManager;
import org.jeecg.modules.activiti.manage.CustomUserEntityManager;
import org.jeecg.modules.apply.lisener.CustomEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.PlatformTransactionManager;
 
import javax.sql.DataSource;
import java.io.IOException;
 
/**
 * 工作流配置
 *
 * @author len
 * @date 2019/06/13
 */
@Configuration
public class ActivitiConfig {
 
    @Autowired
    private CustomUserEntityManager customUserEntityManager;
 
    @Autowired
    private CustomGroupEntityManager customGroupEntityManager;
 
    @Autowired
    private CustomEventListener customEventListener;
 
 
    /**
     * 核心流程引擎类
     *
     * @param transactionManager transactionManager
     * @param dataSource         dataSource
     * @return ProcessEngine
     */
    @Bean
    public ProcessEngine processEngine(PlatformTransactionManager transactionManager, DataSource dataSource)
            throws IOException {
        SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
        // 自动部署已有的流程文件
//        Resource[] resources = new PathMatchingResourcePatternResolver()
//                .getResources(ResourceLoader.CLASSPATH_URL_PREFIX + "processes/*.bpmn");
//        Resource[] resources2 = new PathMatchingResourcePatternResolver()
//                .getResources(ResourceLoader.CLASSPATH_URL_PREFIX + "processes/*.bpmn20.xml");
//        ArrayList<Resource> arrayList = new ArrayList(Arrays.asList(resources));
//        arrayList.addAll(Arrays.asList(resources2));
//        Resource[] arr =new Resource[arrayList.size()];
//        Resource[] resources1 = arrayList.toArray(arr);
//        processEngineConfiguration.setDeploymentResources(resources1);
//        processEngineConfiguration.setDeploymentName("系统自动部署流程");
 
        processEngineConfiguration.setTransactionManager(transactionManager);
        processEngineConfiguration.setDataSource(dataSource);
        processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
//        processEngineConfiguration.setDatabaseSchema("tcore_dev");
//        processEngineConfiguration.setDatabaseTablePrefix("ACT");
        // 自定义用户和组
//        processEngineConfiguration.setUserEntityManager(customUserEntityManager);
//        processEngineConfiguration.setGroupEntityManager(customGroupEntityManager);
 
        processEngineConfiguration.setActivityFontName("SimHei");
        processEngineConfiguration.setAnnotationFontName("SimHei");
        processEngineConfiguration.setLabelFontName("SimHei");
 
 
        //自定义事件监听配置
        processEngineConfiguration.setEventListeners(Lists.newArrayList(customEventListener));
        return processEngineConfiguration.buildProcessEngine();
 
    }
 
    /**
     * 流程仓库Service,用于管理流程仓库,例如部署、删除、读取流程资源
     *
     * @param processEngine processEngine
     * @return RepositoryService
     */
    @Bean
    public RepositoryService repositoryService(ProcessEngine processEngine) {
        return processEngine.getRepositoryService();
    }
 
    /**
     * 运行时Service,可以也拿过来处理所有正在运行状态的流程实例、任务等
     *
     * @param processEngine processEngine
     * @return RuntimeService
     */
    @Bean
    public RuntimeService runtimeService(ProcessEngine processEngine) {
        return processEngine.getRuntimeService();
    }
 
    /**
     * 任务Service,用于管理和查询任务,例如签收、办理、指派等
     *
     * @param processEngine processEngine
     * @return ApprovalTaskService
     */
    @Bean
    public TaskService taskService(ProcessEngine processEngine) {
        return processEngine.getTaskService();
    }
 
    /**
     * 历史Service,用于查询所有历史数据,例如流程实例、任务、活动、变量、附件
     *
     * @param processEngine processEngine
     * @return HistoryService
     */
    @Bean
    public HistoryService historyService(ProcessEngine processEngine) {
        return processEngine.getHistoryService();
    }
 
    /**
     * 引擎管理Service,和具体业务无关,主要可以查询引擎配置、数据库、作业等
     *
     * @param processEngine processEngine
     * @return ManagementService
     */
    @Bean
    public ManagementService managementService(ProcessEngine processEngine) {
        return processEngine.getManagementService();
    }
 
    /**
     * 身份Service,用于管理和查询用户、组之间的关系
     *
     * @param processEngine processEngine
     * @return IdentityService
     */
    @Bean
    public IdentityService identityService(ProcessEngine processEngine) {
        return processEngine.getIdentityService();
    }
 
    /**
     * 表单Service,用于读取流程、任务相关的表单数据
     *
     * @param processEngine processEngine
     * @return FormService
     */
    @Bean
    public FormService formService(ProcessEngine processEngine) {
        return processEngine.getFormService();
    }
 
    /**
     * 一个新增的服务,用于动态修改流程中的一些参数信息等,是引擎中的一个辅助的服务
     *
     * @param processEngine processEngine
     * @return DynamicBpmnService
     */
    @Bean
    public DynamicBpmnService dynamicBpmnService(ProcessEngine processEngine) {
        return processEngine.getDynamicBpmnService();
    }
}