• Activiti搭建


    Activiti搭建

    前期准备:

    JDK+Eclipse+Tomcat+Maven的安装与配置

    参考:http://blog.csdn.net/zhshulin/article/details/30779873

    创建一个Maven项目来配置环境

    参考:http://blog.csdn.net/zhshulin/article/details/37921705

    1,导入activiti包文件

     1 <activiti-version>5.18.0</activiti-version> 

    复制代码
     1 <!--         activiti依赖包 -->
     2         <dependency>
     3             <groupId>org.activiti</groupId>
     4             <artifactId>activiti-engine</artifactId>
     5             <version>${activiti-version}</version>
     6         </dependency>
     7         <dependency>
     8             <groupId>org.activiti</groupId>
     9             <artifactId>activiti-spring</artifactId>
    10             <version>${activiti-version}</version>
    11         </dependency>
    12         <dependency>
    13             <groupId>org.activiti</groupId>
    14             <artifactId>activiti-bpmn-converter</artifactId>
    15             <version>${activiti-version}</version>
    16         </dependency>
    17         <dependency>
    18             <groupId>org.activiti</groupId>
    19             <artifactId>activiti-bpmn-model</artifactId>
    20             <version>${activiti-version}</version>
    21         </dependency>
    22         <dependency>
    23             <groupId>org.activiti</groupId>
    24             <artifactId>activiti-bpmn-layout</artifactId>
    25             <version>${activiti-version}</version>
    26         </dependency>
    复制代码

    2、 eclipse安装activiti-designer插件

          打开eclipse软件,然后点击菜单栏的help选项,选择install New Software,示例如下:

          出现如下对话框:

             点击添加【Add】按钮,出现如下对话框

          输入如下地址:

    Location:http://activiti.org/designer/update/   

    Name:Activiti

          点击OK按钮出现如下窗体:

           选择Activiti BPMN Desisner,然后一直选择下一步,直到出现如下窗体:

         如果出现这个窗体,就表明eclipse正在给您下载相应的插件,但是这个办法是在有网的情况下,而且会比较慢,你得耐心等待,

    当然还有一个简单的办法,就是我们将下载好的插件放到指定文件夹下。

            如果能出现,就证明我们的工作流插件就算是安装成功了。

    3、spring-activiti.xml配置文件

    建立spring-activiti.xml配置文件

    复制代码
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">
     5     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
     6         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
     7         <property name="url" value="jdbc:mysql://localhost:3306/数据库名称" />
     8         <property name="username" value="用户名" />
     9         <property name="password" value="密码" />
    10         <property name="defaultAutoCommit" value="false" />
    11     </bean>
    12     
    13     <bean id="processEngineConfiguration"
    14         class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    15         <property name="dataSource" ref="dataSource" />
    16         <property name="databaseType" value="mysql"/>
    17         <property name="databaseSchemaUpdate" value="true" />
    18         <property name="jobExecutorActivate" value="false" />
    19     </bean>
    20     
    21     <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    22         <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    23     </bean>
    24     
    25     <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    26     <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    27     <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    28     <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    29     <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
    30     <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
    31     
    32     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    33         <property name="dataSource" ref="dataSource" />
    34     </bean>
    35 </beans>
    复制代码

    4、生成activiti数据表

    BaseTestCase.java文件,运行

    复制代码
     1 package org.projMgr.TestCase;
     2 
     3 import org.junit.Test;
     4 import org.junit.runner.RunWith;
     5 import org.springframework.test.context.ContextConfiguration;
     6 import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
     7 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     8 import org.springframework.test.context.transaction.TransactionConfiguration;
     9 import org.springframework.transaction.annotation.Transactional;
    10 
    11 
    12 
    13 @RunWith(SpringJUnit4ClassRunner.class)
    14 @ContextConfiguration({"classpath:spring-activiti.xml"})
    15 @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false)
    16 @Transactional
    17 public class BaseTestCase extends AbstractTransactionalJUnit4SpringContextTests{
    18 
    19     @Test
    20     public void test(){
    21         System.out.println ("通导test"); 
    22     }
    23     
    24 }
    复制代码

    运行结果:

    复制代码
     1 SLF4J: Class path contains multiple SLF4J bindings.
     2 SLF4J: Found binding in [jar:file:/D:/developing/eclipse/workspace/ProjectManagement/projectManagement/src/main/webapp/WEB-INF/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
     3 SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-log4j12/1.7.7/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
     4 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
     5 SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
     6 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [spring-activiti.xml]
     7 [org.springframework.context.support.GenericApplicationContext] - Refreshing org.springframework.context.support.GenericApplicationContext@5383967b: startup date [Tue Feb 28 18:32:15 CST 2017]; root of context hierarchy
     8 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
     9 [org.activiti.engine.impl.db.DbSqlSession] - performing create on engine with resource org/activiti/db/create/activiti.mysql.create.engine.sql
    10 [org.activiti.engine.impl.db.DbSqlSession] - Found MySQL: majorVersion=5 minorVersion=1
    11 [org.activiti.engine.impl.db.DbSqlSession] - performing create on history with resource org/activiti/db/create/activiti.mysql.create.history.sql
    12 [org.activiti.engine.impl.db.DbSqlSession] - Found MySQL: majorVersion=5 minorVersion=1
    13 [org.activiti.engine.impl.db.DbSqlSession] - performing create on identity with resource org/activiti/db/create/activiti.mysql.create.identity.sql
    14 [org.activiti.engine.impl.db.DbSqlSession] - Found MySQL: majorVersion=5 minorVersion=1
    15 [org.activiti.engine.impl.ProcessEngineImpl] - ProcessEngine default created
    16 [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Began transaction (1) for test context [DefaultTestContext@15eebbff testClass = BaseTestCase, testInstance = org.projMgr.TestCase.BaseTestCase@22d6f11, testMethod = test@BaseTestCase, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@30990c1b testClass = BaseTestCase, locations = '{classpath:spring-activiti.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager@2453f95d]; rollback [false]
    17 通导test
    18 [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Committed transaction after test execution for test context [DefaultTestContext@15eebbff testClass = BaseTestCase, testInstance = org.projMgr.TestCase.BaseTestCase@22d6f11, testMethod = test@BaseTestCase, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@30990c1b testClass = BaseTestCase, locations = '{classpath:spring-activiti.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]
    19 [org.springframework.context.support.GenericApplicationContext] - Closing org.springframework.context.support.GenericApplicationContext@5383967b: startup date [Tue Feb 28 18:32:15 CST 2017]; root of context hierarchy
    复制代码

    数据库自动生成25张表:

    5、测试

    在需要存放文件的文件夹右键-new-other,选择activiti diagram

     

     设置文件名-next

     activiti diagram内置了一些 流程定义模板,但是这里我们选择不使用:

     finish之后出现.bpmn文件:

    打开这个文件,输入配置信息:

    id:流程的唯一标识,建议使用纯英文

     在设计区域右边找到StartEven,拖进来:

    设置id、name(这里使用默认,没改)

    单击左下第二个图标,选择“create user task”

    设置id、name

    设置节点分配人:

    再建两个user task以及EndEvent:

    右击文件Leave.bpmn选择OpenWith-XML Editor,可查看XML格式文件,将请假申请、销假的节点分配人设置为proposer(可在上一步设置):

    设置自动生成流程图片:

    单击window菜单,选择preference,按下图设置:

    在原有流程中随意拖动一点,再次保存,即可在同目录下生成png文件:

    自动生成测试代码:

    在Leave.bpmn文件右键-activiti-generate unit test,之后会在test/java/org/activiti/test包中生成ProcessTestLeave.java文件,

    把它拉到holleworld文件夹下,修改包路径

    ProcessTestLeave.java文件代码,其中filename路径的需要修改为/:

    复制代码
     1 package org.holleworld;
     2 
     3 import static org.junit.Assert.*;
     4 
     5 import java.util.HashMap;
     6 import java.util.Map;
     7 import java.io.FileInputStream;
     8 
     9 import org.activiti.engine.RepositoryService;
    10 import org.activiti.engine.RuntimeService;
    11 import org.activiti.engine.runtime.ProcessInstance;
    12 import org.activiti.engine.test.ActivitiRule;
    13 import org.junit.Rule;
    14 import org.junit.Test;
    15 
    16 public class ProcessTestLeave {
    17 
    18     private String filename = "D:/developing/eclipse/workspace/ProjectManagement/projectManagement/src/test/java/org/holleworld/Leave.bpmn";
    19 
    20     @Rule
    21     public ActivitiRule activitiRule = new ActivitiRule();
    22 
    23     @Test
    24     public void startProcess() throws Exception {
    25         RepositoryService repositoryService = activitiRule.getRepositoryService();
    26         repositoryService.createDeployment().addInputStream("leave.bpmn20.xml",
    27                 new FileInputStream(filename)).deploy();
    28         RuntimeService runtimeService = activitiRule.getRuntimeService();
    29         Map<String, Object> variableMap = new HashMap<String, Object>();
    30         variableMap.put("name", "Activiti");
    31         ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave", variableMap);
    32         assertNotNull(processInstance.getId());
    33         System.out.println("id " + processInstance.getId() + " "
    34                 + processInstance.getProcessDefinitionId());
    35     }
    36 }
    复制代码

    run as - JUnitTest,出错......

     repositoryService.createDeployment().addInputStream("leave.bpmn20.xml",new FileInputStream(filename)).deploy();
    这步就跳出,且没有报错信息......尝试
    修改leave.bpmn20.xml变成leave.bpmn.xml或者leave.bpmn
    修改filename = "org/holleworld/Leave.bpmn";
    均无用。

     另外找到测试代码:

    TestActivitiHelloLeave.java

    复制代码
      1 package org.projMgr.TestCase;
      2   
      3 import java.util.Date;
      4 import java.util.List;
      5 
      6 import org.activiti.engine.HistoryService;
      7 import org.activiti.engine.ProcessEngine;
      8 import org.activiti.engine.ProcessEngineConfiguration;
      9 import org.activiti.engine.RepositoryService;
     10 import org.activiti.engine.RuntimeService;
     11 import org.activiti.engine.TaskService;
     12 import org.activiti.engine.history.HistoricActivityInstance;
     13 import org.activiti.engine.history.HistoricActivityInstanceQuery;
     14 import org.activiti.engine.history.HistoricProcessInstance;
     15 import org.activiti.engine.history.HistoricProcessInstanceQuery;
     16 import org.activiti.engine.history.HistoricTaskInstance;
     17 import org.activiti.engine.history.HistoricTaskInstanceQuery;
     18 import org.activiti.engine.repository.Deployment;
     19 import org.activiti.engine.repository.DeploymentBuilder;
     20 import org.activiti.engine.runtime.ProcessInstance;
     21 import org.activiti.engine.task.Task;
     22 import org.activiti.engine.task.TaskQuery;
     23 import org.junit.Before;
     24 import org.junit.Test;
     25   
     26 /**
     27  * Activiti入门程序
     28  * 
     29  */
     30 public class TestActivitiHello {
     31     ProcessEngine processEngine = null;
     32     @Before
     33     public void init(){
     34         //自动加载classpath下名为activiti.cfg.xml文件
     35         processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("spring-activiti.xml").buildProcessEngine();
     36     }
     37     
     38     
     39   
     40     /** 部署流程定义 */
     41     @Test
     42     public void deploymentProcessDefinitionTest() {
     43         /**
     44          * RepositoryService是Activiti的仓库服务类,流程定义和部署对象相关的Service
     45          * 所谓的仓库指流程定义文档的两个文件:bpmn文件和流程图片
     46          */
     47         RepositoryService repositoryService = processEngine.getRepositoryService();
     48         // 创建一个部署对象DeploymentBuilder,用来定义流程部署的相关参数
     49         DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
     50         // 添加部署的名称
     51         deploymentBuilder.name("activiti");
     52         // 添加hello.bpmn和hello.png
     53         deploymentBuilder.addClasspathResource("org/projMgr/TestCase/hello.bpmn");
     54         deploymentBuilder.addClasspathResource("org/projMgr/TestCase/hello.png");
     55         // 部署流程定义
     56         Deployment deployment = deploymentBuilder.deploy();
     57   
     58         System.out.println("部署ID:" + deployment.getId());//1
     59         System.out.println("部署名称:" + deployment.getName());//activiti入门程序
     60     }
     61     
     62 //    /** 启动流程实例 */
     63 //    @Test
     64 //    public void startHelloProcessInstanceTest() {
     65 //        // 流程定义的key
     66 //        String processDefinitionKey = "hello";
     67 //        RuntimeService service = processEngine.getRuntimeService();
     68 //        /**
     69 //         * 使用流程定义的key启动流程实例,key对应hello.bpmn文件中id的属性值,
     70 //         * 使用key值启动,默认是按照最新版本的流程定义启动
     71 //         */
     72 //        ProcessInstance pi = service.startProcessInstanceByKey(processDefinitionKey);
     73 //        System.out.println("流程实例ID:" + pi.getId());// 流程实例ID:2501
     74 //        // 流程定义ID:hello:1:4
     75 //        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
     76 //    }
     77     
     78 //            @Test  
     79 //            public void setVariables(){  
     80 //                String taskId = "342504";  
     81 //                TaskService taskService = processEngine.getTaskService();  
     82 //                taskService.setVariableLocal(taskId, "请假天数", 3);   //与任务ID绑定  
     83 //                    taskService.setVariable(taskId, "请假日期", new Date());  
     84 //                taskService.setVariable(taskId, "请假原因", "回家看亲");  
     85 //                  
     86 //                System.out.println("设置成功了");  
     87 //            }   
     88     
     89     
     90 //    /** 查看历史流程实例 */ 
     91 //    @Test
     92 //    public void queryHistoricProcessInstanceTest() throws Exception {
     93 //        HistoryService service = processEngine.getHistoryService();
     94 //      
     95 //        // 获取历史流程实例的查询对象
     96 //        HistoricProcessInstanceQuery hpiQuery = service.createHistoricProcessInstanceQuery();
     97 //        // 设置流程定义KEY
     98 //        hpiQuery.processDefinitionKey("hello");
     99 //        // 分页条件
    100 //        //hpiQuery.listPage(firstResult, maxResults);
    101 //        // 排序
    102 //        hpiQuery.orderByProcessInstanceStartTime().desc();
    103 //      
    104 //        // 执行查询
    105 //        List<HistoricProcessInstance> hpis = hpiQuery.list();
    106 //        // 遍历查看结果
    107 //        for (HistoricProcessInstance hpi : hpis) {
    108 //            System.out.print("pid:" + hpi.getId() + ",");
    109 //            System.out.print("pdid:" + hpi.getProcessDefinitionId() + ",");
    110 //            System.out.print("startTime:" + hpi.getStartTime() + ",");
    111 //            System.out.print("endTime:" + hpi.getEndTime() + ",");
    112 //            System.out.print("duration:" + hpi.getDurationInMillis() + ",");
    113 //            System.out.println("vars:" + hpi.getProcessVariables());
    114 //        }
    115 //    }  
    116 //    
    117 //    /** 查看历史活动实例 */
    118 //    @Test
    119 //    public void queryHistoricActivityInstanceTest() throws Exception {
    120 //        HistoryService service = processEngine.getHistoryService();
    121 //        HistoricActivityInstanceQuery haiq=service.createHistoricActivityInstanceQuery();
    122 //        //过滤条件
    123 //        haiq.processInstanceId("45001");
    124 //        // 分页条件
    125 //        //haiq.listPage(firstResult, maxResults);
    126 //        //排序
    127 //        haiq.orderByHistoricActivityInstanceEndTime().asc();
    128 //        List<HistoricActivityInstance> hais = haiq.list();
    129 //      
    130 //        for (HistoricActivityInstance hai : hais) {
    131 //            System.out.print("activitiId:" + hai.getActivityId() + ",");
    132 //            System.out.print("name:" + hai.getActivityName() + ",");
    133 //            System.out.print("type:" + hai.getActivityType() + ",");
    134 //            System.out.print("pid:" + hai.getProcessInstanceId() + ",");
    135 //            System.out.print("assignee:" + hai.getAssignee() + ",");
    136 //            System.out.print("startTime:" + hai.getStartTime() + ",");
    137 //            System.out.print("endTime:" + hai.getEndTime() + ",");
    138 //            System.out.println("duration:" + hai.getDurationInMillis());
    139 //        }
    140 //    }
    141     
    142 //    /** 查看历史任务实例 */
    143 //    @Test
    144 //    public void queryHistoricTaskInstanceTest() throws Exception {
    145 //        HistoryService service = processEngine.getHistoryService();
    146 //        HistoricTaskInstanceQuery htiq = service.createHistoricTaskInstanceQuery();
    147 //        htiq.taskAssignee("李四");
    148 //        List<HistoricTaskInstance> tasks = htiq.list();
    149 //      
    150 //        for (HistoricTaskInstance hti : tasks) {
    151 //            System.out.print("pid:" + hti.getProcessInstanceId() + ",");
    152 //            System.out.print("assignee:" + hti.getAssignee() + ",");
    153 //            System.out.print("startTime:" + hti.getStartTime() + ",");
    154 //            System.out.print("endTime:" + hti.getEndTime() + ",");
    155 //            System.out.println("duration:" + hti.getDurationInMillis());
    156 //        }
    157 //    }
    158     
    159 //    /**查询当前人的个人任务*/
    160 //    @Test
    161 //    public void queryAssigneeTaskTest(){
    162 //        //与正在执行的任务管理相关的Service
    163 //        TaskService service = processEngine.getTaskService();
    164 //        //创建任务查询对象
    165 //        TaskQuery query = service.createTaskQuery();
    166 //        //指定个人任务查询,指定办理人
    167 //        query.taskAssignee("王五");
    168 //        List<Task> list = query.list();
    169 //        if(list!=null && list.size()>0){
    170 //            for(Task task:list){
    171 //                System.out.println("任务ID:"+task.getId());
    172 //                System.out.println("任务名称:"+task.getName());
    173 //                System.out.println("任务的创建时间:"+task.getCreateTime());
    174 //                System.out.println("任务的办理人:"+task.getAssignee());
    175 //                System.out.println("流程实例ID:"+task.getProcessInstanceId());
    176 //                System.out.println("执行对象ID:"+task.getExecutionId());
    177 //                System.out.println("流程定义ID:"+task.getProcessDefinitionId());
    178 //            }
    179 //        }
    180 //    }
    181     
    182 //    /**完成个人任务*/
    183 //    @Test
    184 //    public void completeTaskTest(){
    185 //        //任务ID
    186 //        String taskId = "50002"; //        需改id
    187 //        processEngine.getTaskService()
    188 //                    .complete(taskId);
    189 //        System.out.println("完成任务:任务ID:"+taskId);
    190 //    }
    191     
    192     
    193     
    194 //    /** 删除流程定义 */
    195 //    @Test
    196 //    public void deleteProcessDefinition() {
    197 //        // 使用部署ID,完成删除
    198 //        String deploymentId = "27501";
    199 //      
    200 //        //不带级联的删除 只能删除没有启动的流程,如果流程启动,就会抛出异常
    201 //        // processEngine.getRepositoryService().deleteDeployment(deploymentId);
    202 //      
    203 //        /**
    204 //         * 级联删除 不管流程是否启动,都能可以删除
    205 //         */
    206 //        processEngine.getRepositoryService().deleteDeployment(deploymentId, true);
    207 //        System.out.println("删除成功!");
    208 //    }
    209     
    210     
    211     
    212     
    213 }
    复制代码

    分步骤测试:

    复制代码
     1     /** 部署流程定义 */
     2     @Test
     3     public void deploymentProcessDefinitionTest() {
     4         /**
     5          * RepositoryService是Activiti的仓库服务类,流程定义和部署对象相关的Service
     6          * 所谓的仓库指流程定义文档的两个文件:bpmn文件和流程图片
     7          */
     8         RepositoryService repositoryService = processEngine.getRepositoryService();
     9         // 创建一个部署对象DeploymentBuilder,用来定义流程部署的相关参数
    10         DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
    11         // 添加部署的名称
    12         deploymentBuilder.name("holleworld");
    13         // 添加hello.bpmn和hello.png
    14         deploymentBuilder.addClasspathResource("org/holleworld/Leave.bpmn");
    15         deploymentBuilder.addClasspathResource("org/holleworld/Leave.png");
    16         // 部署流程定义
    17         Deployment deployment = deploymentBuilder.deploy();
    18   
    19         System.out.println("部署ID:" + deployment.getId());//1
    20         System.out.println("部署名称:" + deployment.getName());//activiti入门程序
    21     }
    复制代码

    运行结果:

    复制代码
     1     /** 启动流程实例 */
     2     @Test
     3     public void startHelloProcessInstanceTest() {
     4         // 流程定义的key
     5         String processDefinitionKey = "leave";
     6         RuntimeService service = processEngine.getRuntimeService();
     7         /**
     8          * 使用流程定义的key启动流程实例,key对应hello.bpmn文件中id的属性值,
     9          * 使用key值启动,默认是按照最新版本的流程定义启动
    10          */
    11         ProcessInstance pi = service.startProcessInstanceByKey(processDefinitionKey);
    12         System.out.println("流程实例ID:" + pi.getId());// 流程实例ID
    13         // 流程定义ID:hello:1:4
    14         System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
    15     }
    复制代码

    运行结果:

    复制代码
     1     /** 查看历史流程实例 */ 
     2     @Test
     3     public void queryHistoricProcessInstanceTest() throws Exception {
     4         HistoryService service = processEngine.getHistoryService();
     5       
     6         // 获取历史流程实例的查询对象
     7         HistoricProcessInstanceQuery hpiQuery = service.createHistoricProcessInstanceQuery();
     8         // 设置流程定义KEY
     9         hpiQuery.processDefinitionKey("leave");
    10         // 分页条件
    11         //hpiQuery.listPage(firstResult, maxResults);
    12         // 排序
    13         hpiQuery.orderByProcessInstanceStartTime().desc();
    14       
    15         // 执行查询
    16         List<HistoricProcessInstance> hpis = hpiQuery.list();
    17         // 遍历查看结果
    18         for (HistoricProcessInstance hpi : hpis) {
    19             System.out.print("pid:" + hpi.getId() + ",");
    20             System.out.print("pdid:" + hpi.getProcessDefinitionId() + ",");
    21             System.out.print("startTime:" + hpi.getStartTime() + ",");
    22             System.out.print("endTime:" + hpi.getEndTime() + ",");
    23             System.out.print("duration:" + hpi.getDurationInMillis() + ",");
    24             System.out.println("vars:" + hpi.getProcessVariables());
    25         }
    26     }  
    复制代码

    运行结果:

    复制代码
     1     /** 查看历史活动实例 */
     2     @Test
     3     public void queryHistoricActivityInstanceTest() throws Exception {
     4         HistoryService service = processEngine.getHistoryService();
     5         HistoricActivityInstanceQuery haiq=service.createHistoricActivityInstanceQuery();
     6         //过滤条件
     7         haiq.processInstanceId("70001");
     8         // 分页条件
     9         //haiq.listPage(firstResult, maxResults);
    10         //排序
    11         haiq.orderByHistoricActivityInstanceEndTime().asc();
    12         List<HistoricActivityInstance> hais = haiq.list();
    13       
    14         for (HistoricActivityInstance hai : hais) {
    15             System.out.print("activitiId:" + hai.getActivityId() + ",");
    16             System.out.print("name:" + hai.getActivityName() + ",");
    17             System.out.print("type:" + hai.getActivityType() + ",");
    18             System.out.print("pid:" + hai.getProcessInstanceId() + ",");
    19             System.out.print("assignee:" + hai.getAssignee() + ",");
    20             System.out.print("startTime:" + hai.getStartTime() + ",");
    21             System.out.print("endTime:" + hai.getEndTime() + ",");
    22             System.out.println("duration:" + hai.getDurationInMillis());
    23         }
    24     }
    复制代码

    运行结果

    复制代码
     1     /**查询当前人的个人任务*/
     2     @Test
     3     public void queryAssigneeTaskTest(){
     4         //与正在执行的任务管理相关的Service
     5         TaskService service = processEngine.getTaskService();
     6         //创建任务查询对象
     7         TaskQuery query = service.createTaskQuery();
     8         //指定个人任务查询,指定办理人
     9         query.taskAssignee("proposer");
    10         List<Task> list = query.list();
    11         if(list!=null && list.size()>0){
    12             for(Task task:list){
    13                 System.out.println("任务ID:"+task.getId());
    14                 System.out.println("任务名称:"+task.getName());
    15                 System.out.println("任务的创建时间:"+task.getCreateTime());
    16                 System.out.println("任务的办理人:"+task.getAssignee());
    17                 System.out.println("流程实例ID:"+task.getProcessInstanceId());
    18                 System.out.println("执行对象ID:"+task.getExecutionId());
    19                 System.out.println("流程定义ID:"+task.getProcessDefinitionId());
    20             }
    21         }
    22     }
    复制代码

    运行结果:

    复制代码
     1     /** 查看历史任务实例 */
     2     @Test
     3     public void queryHistoricTaskInstanceTest() throws Exception {
     4         HistoryService service = processEngine.getHistoryService();
     5         HistoricTaskInstanceQuery htiq = service.createHistoricTaskInstanceQuery();
     6 //        htiq.taskAssignee("null");
     7         List<HistoricTaskInstance> tasks = htiq.list();
     8       
     9         for (HistoricTaskInstance hti : tasks) {
    10             System.out.print("pid:" + hti.getProcessInstanceId() + ",");
    11             System.out.print("assignee:" + hti.getAssignee() + ",");
    12             System.out.print("startTime:" + hti.getStartTime() + ",");
    13             System.out.print("endTime:" + hti.getEndTime() + ",");
    14             System.out.println("duration:" + hti.getDurationInMillis());
    15         }
    16     }
    复制代码

    运行结果:

    复制代码
    1     /**完成个人任务*/
    2     @Test
    3     public void completeTaskTest(){
    4         //任务ID
    5         String taskId = "70004"; //        需改id
    6         processEngine.getTaskService()
    7                     .complete(taskId);
    8         System.out.println("完成任务:任务ID:"+taskId);
    9     }
    复制代码

    运行结果:

    原文地址:https://www.cnblogs.com/sucia-panda/p/6437943.html
  • 相关阅读:
    Python学习笔记--列表
    jmeter适用python来处理接口加密
    pytest-fixture参数化params(重要)
    Python38+Robot Framework 安装ExcelLibrary一直报错,提示“dist.py:267: userwarning: unknown distribution option: ‘inst’”
    robotframework之RIED运行测试用例报错Suite ‘XXX‘ contains no tests matching name ‘XXX‘ in sin suite
    在win10上安装python3.8 + Robotframework +RIDE报错
    Pytest自动化测试 断言失败后续代码继续执行
    学习pytest+allureUI自动化记录(示例代码)
    接口测试 Pytest断言处理_assert和异常断言
    selenium有界面下正常,无界面下报错:Message: element not interactable (Session info: headless chrome)
  • 原文地址:https://www.cnblogs.com/jpfss/p/11083564.html
Copyright © 2020-2023  润新知