通过ForEach生成的是并发流程
流程定义XML:
<?xml version="1.0" encoding="UTF-8"?>
<process key="FOR_EACH" name="forEach" xmlns="http://jbpm.org/4.4/jpdl">
<start g="57,196,48,48" name="start1">
<transition g="-72,-22" name="to foreach1" to="foreach1" />
</start>
<foreach g="157,194,48,48" name="foreach1" var="deptId" in="#{deptIds}">
<transition g="-45,-22" name="" to="主管" />
</foreach>
<task g="268,195,92,52" name="主管" assignee="zg#{deptId}">
<transition g="-52,-22" name="" to="经理" />
</task>
<task g="393,198,92,52" name="经理" assignee="jl#{deptId}">
<transition g="-49,-22" name="to join1" to="join1" />
</task>
<join g="562,197,48,48" name="join1" multiplicity="#{deptIds.size()}"><!-- 根据deptIds的长度,进行合并,必须 -->
<transition g="-45,-22" name="" to="总监" />
</join>
<task g="670,196,92,52" name="总监" assignee="zj">
<transition g="-50,-22" name="" to="end1" />
</task>
<end g="808,193,48,48" name="end1" />
</process>
测试类Java:
public class FlowServiceTest {
ProcessEngine processEngine;
String jdplPath;
String pdKey;
@Before
public void setUp() throws Exception {
processEngine = Configuration.getProcessEngine();// 获取流程引擎
jdplPath = "jpdl/forEach.jpdl.xml";
pdKey = "FOR_EACH";
}
/**
* @description 发布流程 no.1
*/
@Test
public void deploy() {
RepositoryService repositoryService = processEngine.getRepositoryService();
repositoryService.createDeployment().addResourceFromClasspath(jdplPath).deploy();
}
/**
* @description 提交申请 no.2
*/
@Test
public void testApply() {
Map<String, Object> values = new HashMap<String, Object>();
List<Integer> deptIds = new ArrayList<Integer>();
deptIds.add(1);
deptIds.add(2);
values.put("deptIds", deptIds);
values.put("deptIdsLenght", deptIds.size());
ExecutionService executionService = processEngine.getExecutionService();
executionService.startProcessInstanceByKey(pdKey, values);
}
/**
* @description 完成任务 no.3
*/
@Test
public void takeTask() {
String taskId = "30001"; //直接接查数据库任务表获取
TaskService taskService = processEngine.getTaskService();
taskService.completeTask(taskId);
}
}
jbpm.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.businesscalendar.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.bpmn.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
<!-- 这里设置成spring的配置文件,工作流引擎会使用默认的spring配置文件applicationContext.xml
<import resource="jbpm.tx.spring.cfg.xml" />-->
<process-engine-context>
<!-- 如果需要添加spring配置文件,可在这里添加
<string name="spring.cfg" value="applicationContext.xml" /> -->
</process-engine-context>
</jbpm-configuration>
jbpm.hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
</session-factory>
</hibernate-configuration>