下面只是activiti相关的依赖文件,还有spring依赖文件可以自行选择导入
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-engineartifactId>
<version>5.15.1version>
dependency>
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-springartifactId>
<version>5.15.1version>
dependency>
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-bpmn-modelartifactId>
<version>5.15.1version>
dependency>
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-bpmn-layoutartifactId>
<version>5.15.1version>
dependency>
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-bpmn-converterartifactId>
<version>5.15.1version>
dependency>
<dependency>
<groupId>org.activitigroupId>
<artifactId>activiti-process-validationartifactId>
<version>5.15.1version>
dependency>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="databaseSchemaUpdate" value="true" />
<property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/oa?serverTimezone=UTC" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="25002500" />
bean>
beans>
@Test
public void testActivitiInit(){
ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println(defaultProcessEngine);
}
运行后会在数据库生成23张表
下面为表的相关解释
3.1 资源库流程规则表
act_re_deployment 部署信息表
act_re_model 流程设计模型部署表
act_re_procdef 流程定义数据表
3.2:运行时数据库表
act_ru_execution 运行时流程执行实例表
act_ru_identitylink 运行时流程人员表,主要存储任务节点与参与者的相关信息
act_ru_task 运行时任务节点表
act_ru_variable 运行时流程变量数据表
3.3:历史数据库表
act_hi_actinst 历史节点表
act_hi_attachment 历史附件表
act_hi_comment 历史意见表
act_hi_identitylink 历史流程人员表
act_hi_detail 历史详情表,提供历史变量的查询
act_hi_procinst 历史流程实例表
act_hi_taskinst 历史任务实例表
act_hi_varinst 历史变量表
3.4:组织机构表
act_id_group 用户组信息表
act_id_info 用户扩展信息表
act_id_membership 用户与用户组对应信息表
act_id_user 用户信息表
创建流程部署测试方法:testDeployProcess()
/**
* 部署流程图
*/
@Test
public void testDeployProcess(){
//1. 获取流程引擎对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2. 获取流程定义的service
RepositoryService repositoryService = processEngine.getRepositoryService();
//3. 创建流程部署对象
DeploymentBuilder deployment = repositoryService.createDeployment();
//4. 部署资源文件
deployment.addClasspathResource("Hello.bpmn");
deployment.addClasspathResource("Hello.png");
//5.设置部署名称
deployment.name("第三次次署流程图");
//6. 进行部署
Deployment deploy = deployment.deploy();
//7 输出信息
System.out.println("部署名称: " + deploy.getName());
System.out.println("部署id: " + deploy.getId());
System.out.println("部署时间: " + deploy.getDeploymentTime());
}
运行结果:
这时可以进入数据库进行数据查询
act_re_deployment: 部署的相关信息
act_re_procdef:
act_ge_bytearray
输入的501 为该流程的的 id 则为act_re_deployment 表中的id值
@Test
public void testDeleteDeployProcess(){
//1. 获取流程引擎对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2. 获取流程定义的service
RepositoryService repositoryService = processEngine.getRepositoryService();
//3. 调用方法进行删除
repositoryService.deleteDeployment("501");
}
相关方法:
该方法通过getResourceAsStream方法获取流程图片的二进制文件,然后转换为图片存在跟目录下
@Test
public void testFindProcessInsPng(){
//1. 获取流程引擎对象
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//2. 获取流程定义的service
RepositoryService repositoryService = processEngine.getRepositoryService();
//3. 根据部署id和资源名称
InputStream ips = repositoryService.getResourceAsStream("601", "Hello.png");
FileOutputStream ops = null;
try {
ops = new FileOutputStream("./hello.png");
IOUtils.copy(ips, ops);
System.out.println("流程图片复制成功!");
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(ops);
IOUtils.closeQuietly(ips);
}
}