博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
activiti util (1)
阅读量:5032 次
发布时间:2019-06-12

本文共 10502 字,大约阅读时间需要 35 分钟。

一、xml

二、测试类
package com.albert.test03; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.TaskService; import org.activiti.engine.history.HistoricProcessInstance; import org.activiti.engine.history.HistoricProcessInstanceQuery; import org.activiti.engine.impl.RepositoryServiceImpl; import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity; import org.activiti.engine.impl.persistence.entity.TaskEntity; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.ArrayList; import java.util.List; import java.util.UUID; @RunWith(SpringRunner.class) @SpringBootTest public class Test03ApplicationTests {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); @Test public void contextLoads() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); System.out.println("==============" + processEngine.getName()); } @Test public void deployProcessDefinition() {
Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署相关的Service .createDeployment()//创建部署对象 .addClasspathResource("bpmn/beck.bpmn20.xml") .deploy();//完成部署 System.out.println("部署ID:" + deployment.getId());//部署ID:1 System.out.println("部署时间:" + deployment.getDeploymentTime());//部署时间 } /** * 启动流程实例 */ @Test public void startProcessInstance() {
String processDefinitionKey = "beck";//流程定义的key,也就是bpmn中存在的ID ProcessInstance pi = processEngine.getRuntimeService()//管理流程实例和执行对象,也就是表示正在执行的操作 .startProcessInstanceByKey(processDefinitionKey);按照流程定义的key启动流程实例 System.out.println("流程实例ID:" + pi.getId());//流程实例ID:101 System.out.println("流程实例ID:" + pi.getProcessInstanceId());//流程实例ID:101 System.out.println("流程实例ID:" + pi.getProcessDefinitionId());//myMyHelloWorld:1:4 } // 3.查看任务 @Test public void quertTask() {
try {
ProcessEngine processEngine = ProcessEngines .getDefaultProcessEngine(); TaskService taskService = processEngine.getTaskService(); String userId = "beck_guo"; //String userId = "fucai"; //String userId = "zhangsan"; //String userId = "xiaoxiao"; List
tasks = taskService.createTaskQuery() .taskAssignee(userId).list(); for (Task task : tasks) {
System.out.println("taskId:" + task.getId() + ",name:" + task.getName() + ",assignee:" + task.getAssignee() + ",ProcessInstanceId:" + task.getProcessInstanceId()); } System.out.println("查讯任务结束"); } catch (Exception e) {
e.printStackTrace(); } } /** * 会签操作 * * 会签人账号集合 * @throws Exception */ @Test public void jointProcess() throws Exception {
String taskId="17505"; List
userCodes=new ArrayList<>(); userCodes.add("fucai"); userCodes.add("zhangsan"); for (String userCode : userCodes) {
TaskEntity task = (TaskEntity) processEngine.getTaskService().newTask(UUID.randomUUID().toString()); task.setAssignee(userCode); task.setName(findTaskById(taskId).getName() + "-会签"); task.setProcessDefinitionId(findProcessDefinitionEntityByTaskId( taskId).getId()); task.setProcessInstanceId(findProcessInstanceByTaskId(taskId) .getId()); task.setParentTaskId(taskId); task.setDescription("jointProcess"); processEngine.getTaskService().saveTask(task); } System.out.println("taskId:" + taskId+" ==会签线束"); } // 5.办理任务 @Test public void completeTask() throws Exception {
try {
ProcessEngine processEngine = ProcessEngines .getDefaultProcessEngine(); TaskService taskService = processEngine.getTaskService(); String taskId = "7e55dc2a-a4fd-4db3-b6a2-607e5f124605"; taskService.complete(taskId); System.out.println("办理任务结束 taskId=" + taskId); } catch (Exception e) {
e.printStackTrace(); } } // 历史流程实例查看(查找按照某个规则一共执行了多少次流程) @Test public void queryHistoricProcessInstance() throws Exception {
// 获取历史流程实例的查询对象 HistoricProcessInstanceQuery historicProcessInstanceQuery = processEngine.getHistoryService().createHistoricProcessInstanceQuery(); // 设置查询参数 historicProcessInstanceQuery //过滤条件 .processDefinitionKey("beck") // 分页条件 // .listPage(firstResult, maxResults) // 排序条件 .orderByProcessInstanceStartTime().desc(); // 执行查询 List
hpis = historicProcessInstanceQuery.list(); // 遍历查看结果 System.out.print("==================="); for (HistoricProcessInstance hpi : hpis) {
System.out.print("pid:" + hpi.getId() + ","); System.out.print("pdid:" + hpi.getProcessDefinitionId() + ","); System.out.print("startTime:" + hpi.getStartTime() + ","); System.out.print("endTime:" + hpi.getEndTime() + ","); System.out.print("duration:" + hpi.getDurationInMillis() + ","); System.out.println("vars:" + hpi.getProcessVariables()); } } /** * 根据任务ID获得任务实例 * * @param taskId * 任务ID * @return * @throws Exception */ private TaskEntity findTaskById(String taskId) throws Exception {
TaskEntity task = (TaskEntity) processEngine.getTaskService().createTaskQuery().taskId( taskId).singleResult(); if (task == null) {
throw new Exception("任务实例未找到!"); } return task; } /** * 根据任务ID获取流程定义 * * @param taskId 任务ID * @return * @throws Exception */ private ProcessDefinitionEntity findProcessDefinitionEntityByTaskId( String taskId) throws Exception {
// 取得流程定义 ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) processEngine.getRepositoryService()) .getDeployedProcessDefinition(findTaskById(taskId) .getProcessDefinitionId()); if (processDefinition == null) {
throw new Exception("流程定义未找到!"); } return processDefinition; } /** * 根据任务ID获取对应的流程实例 * * @param taskId 任务ID * @return * @throws Exception */ private ProcessInstance findProcessInstanceByTaskId(String taskId) throws Exception {
// 找到流程实例 ProcessInstance processInstance = processEngine.getRuntimeService() .createProcessInstanceQuery().processInstanceId( findTaskById(taskId).getProcessInstanceId()) .singleResult(); if (processInstance == null) {
throw new Exception("流程实例未找到!"); } return processInstance; } } 三、activiti.cfg.xml
四 pom
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.5.RELEASE
com.albert.test03
test03
0.0.1-SNAPSHOT
test03
Demo project for Spring Boot
1.8
5.22.0
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
mysql
mysql-connector-java
5.1.6
org.activiti
activiti-engine
${activiti.version}
org.activiti
activiti-spring
${activiti.version}
org.activiti
activiti-modeler
${activiti.version}
org.activiti
activiti-diagram-rest
${activiti.version}
org.springframework.boot
spring-boot-maven-plugin

转载于:https://www.cnblogs.com/albert-think/p/10997591.html

你可能感兴趣的文章
Silverlight动态调用WEBSERVICE,WCF方法
查看>>
LeetCode 895. Maximum Frequency Stack
查看>>
模仿segmentfault 评论
查看>>
一个简单的日志函数C++
查看>>
Java 8 中如何优雅的处理集合
查看>>
IOS程序的启动过程
查看>>
连接Linux下 XAMPP集成环境中部署的禅道的数据库MariaDB
查看>>
Java操作Excel和Word
查看>>
Oracle 体系结构之ORACLE物理结构
查看>>
ORA-12538: TNS: no such protocol adapter
查看>>
盒子模型
查看>>
局域网协议
查看>>
[HNOI2012]永无乡 线段树合并
查看>>
Spring整合hibernate:3、使用XML进行声明式的事务管理
查看>>
SqlServer之Convert 函数应用格式化日期(转)
查看>>
软件测试领域中的10个生存和发展技巧
查看>>
Camera前后摄像头同时预览
查看>>
HDU 1856
查看>>
课堂作业01--架构师的职责
查看>>
iOS计算富文本(NSMutableAttributedString)高度
查看>>