Activiti7
使用25张表 ACT_RE 流程定义和流程资源 ACT_RU 运行时,流程实例、任务、变量 ACT_HI 历史表 ACT_GE 通用表
RepositoryService 资源管理类 RuntimeService 运行时管理类 TaskService 任务管理类 HistoryService 历史数据管理类 ManagementService 流程引擎管理类
新版(我的是2021)idea安装Activiti BPMN visualizer
事件event,活动activity,网关 gateway,流向
使用repositoryService 单文件部署 把bpmn文件和png文件一个一个处理 压缩包处理 把bpmn文件和png文件打成一个zip压缩包
@Test
void deployProcessByZip() {
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream("bpmn/evection.zip");
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
Deployment deploy = repositoryService.createDeployment()
.name("部署流程通过zip")
.addZipInputStream(zipInputStream)
.deploy();
System.out.println("流程ID:"+deploy.getId());
System.out.println("流程名称:"+deploy.getName());
}`
部署过程操作的表: act_re_deployment 部署表 act_re_procdef 流程定义表 act_ge_bytearray 资源表
使用runtimeService 根据流程定义key 核心代码:
@Test
void startProcess() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("myEvection");
log.info("流程定义ID:{}",instance.getProcessDefinitionId());
log.info("流程实例ID:{}",instance.getId());
log.info("当前活动的ID:{}",instance.getActivityId());
}`
myEvection是设计流程图的时候唯一的key 操作的表: act_hi_actinst 流程实例执行历史信息 act_hi_indentitylink 流程参与用户的历史信息 act_hi_procinst 流程实例的历史信息 act_hi_taskinst 流程任务的历史信息 act_run_execution 流程执行信息 act_run_ndentitylink 流程正在参与用户信息 act_run_task 流程当前任务信息
@Test
void findPersonTaskList() {
List<Task> list = taskService.createTaskQuery().processDefinitionKey("myEvection")
.taskAssignee("zhangsan")
.list();
for (Task task : list) {
log.info("流程实例id:{}",task.getProcessInstanceId());
log.info("任务id:{}",task.getId());
log.info("任务负责人:{}",task.getAssignee());
log.info("任务名称:{}",task.getName());
}
}
@Test
void completeTask() {
taskService.complete("1f23ec23-ca8d-11ec-9b48-8e061b0cd255");
}
直接传入taskId
根据流程定义的key查询
@Test
void queryProcessDefinition() {
ProcessDefinitionQuery definitionQuery = repositoryService.createProcessDefinitionQuery();
List<ProcessDefinition> myEvection = definitionQuery.processDefinitionKey("myEvection")
.orderByProcessDefinitionVersion()
.desc()
.list();
myEvection.forEach(System.out::println);
}`
- 流程删除
根据流程部署的id
@Test
void deleteProcessDefinition() {
repositoryService.deleteDeployment("34327582-ca96-11ec-b66f-8e061b0cd255",true);
}
如果用户想要查看流程的资源文件,可以从数据库中吧资源下载到本地;
@Test
void getProcessDefinitionResource() throws IOException {
ProcessDefinitionQuery definitionQuery = repositoryService.createProcessDefinitionQuery();
ProcessDefinition myEvection = definitionQuery.processDefinitionKey("myEvection")
.singleResult();
String deploymentId = myEvection.getDeploymentId();
String pngName = myEvection.getDiagramResourceName();
String bpmnName = myEvection.getResourceName();
InputStream pngAsStream = repositoryService.getResourceAsStream(deploymentId, pngName);
InputStream bpmnAsStream = repositoryService.getResourceAsStream(deploymentId, bpmnName);
String pngPath = "/Users/macos/IdeaProjects/actibiti7/src/main/resources/bpmn/pngOut.png";
String bpmnPath = "/Users/macos/IdeaProjects/actibiti7/src/main/resources/bpmn/bpmnOut.bpmn";
FileOutputStream pngOut = new FileOutputStream(pngPath);
FileOutputStream bpmnOut = new FileOutputStream(bpmnPath);
IOUtils.copy(pngAsStream,pngOut);
IOUtils.copy(bpmnAsStream,bpmnOut);
pngAsStream.close();
bpmnAsStream.close();
pngOut.close();
bpmnOut.close();
}
maven依赖:common-io :
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
historyService:
@Test
void findHistoryInfo() {
HistoricActivityInstanceQuery instanceQuery = historyService.createHistoricActivityInstanceQuery();
HistoricActivityInstanceQuery historicActivityInstanceQuery = instanceQuery.processInstanceId("3d75da9e-ca9e-11ec-bd9d-8e061b0cd255").orderByHistoricActivityInstanceStartTime().asc();
List<HistoricActivityInstance> list = historicActivityInstanceQuery.list();
for (HistoricActivityInstance hi : list) {
System.out.println(hi.getActivityId());
System.out.println(hi.getActivityName());
System.out.println(hi.getProcessDefinitionId());
System.out.println(hi.getProcessInstanceId());
System.out.println("=====================");
}
}
一个流程定义可以对应多个流程实例 例如:公司有出差申请流程 流程定义 小郑可以申请出差 广州出差4天 流程实例 小李可以申请出差 北京出差4天 流程实例
- 业务标识:businessKey
- 可以查询自己的业务信息
- activiti中不会保存业务信息,可以通过businessKey进行关联,字段在act_ru_execution表中;
@Test
void startProcess() {
String businessKey = "1001";
ProcessInstance instance = runtimeService.startProcessInstanceByKey("myEvection",businessKey);
log.info("流程定义ID:{}",instance.getProcessDefinitionId());
log.info("流程实例ID:{}",instance.getId());
log.info("当前活动的ID:{}",instance.getActivityId());
log.info("流程实例bussinessKey:{}",instance.getBusinessKey());
}
@Test
void suspendProcess() {
ProcessDefinition myEvection = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("myEvection")
.singleResult();
boolean suspended = myEvection.isSuspended();
if (suspended) {
repositoryService.activateProcessDefinitionById(myEvection.getId(),true,null);
}else {
repositoryService.suspendProcessDefinitionById(myEvection.getId(),true,null);
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("myEvection")
.singleResult();
boolean result = processDefinition.isSuspended();
log.info("流程状态:{}",result?"挂起":"激活");
}
@Test
void suspendProcessOneInstance() {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId("e0ec589a-caa6-11ec-b579-8e061b0cd255")
.singleResult();
boolean suspended = processInstance.isSuspended();
if (suspended) {
runtimeService.activateProcessInstanceById(processInstance.getId());
}else {
runtimeService.suspendProcessInstanceById(processInstance.getId());
}
ProcessInstance instance = runtimeService.createProcessInstanceQuery()
.processInstanceId("e0ec589a-caa6-11ec-b579-8e061b0cd255")
.singleResult();
boolean result = instance.isSuspended();
log.info("流程状态:{}",result?"挂起":"激活");
}
|