首页 > 其他分享 >Flowable查询历史任务

Flowable查询历史任务

时间:2024-03-11 21:14:31浏览次数:24  
标签:engine task Flowable System 查询 instance 任务 println out

效果图

 历史任务主要是为了统计使用

代码部分

/**
     * 查询历史任务
     */
    @Test
    public void test007(){
        ProcessEngine engine = cfg.buildProcessEngine();
        HistoryService service = engine.getHistoryService();
        List<HistoricActivityInstance> list = service.createHistoricActivityInstanceQuery()
                .processDefinitionId("holidayRequest:3:30003")
                .finished()
                .list();
        for (HistoricActivityInstance instance : list) {
            System.out.println("instance.getActivityId() = " + instance.getActivityId());
            System.out.println("instance.getAssignee() = " + instance.getAssignee());
            System.out.println("instance.getActivityName() = " + instance.getActivityName());
            System.out.println("instance.getDurationInMillis() = " + instance.getDurationInMillis());
        }
    }

  pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.java</groupId>
    <artifactId>flowable -service</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>flowable-test</module>
    </modules>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-engine</artifactId>
            <version>6.7.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.21</version>
        </dependency>
        <!--mysql驱动5.6.17-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

  流程文件

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:flowable="http://flowable.org/bpmn"
             typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://www.flowable.org/processdef">

    <process id="holidayRequest" name="Holiday Request" isExecutable="true">

        <startEvent id="startEvent"/>
        <sequenceFlow sourceRef="startEvent" targetRef="approveTask"/>

<!--        <userTask id="approveTask" name="Approve or reject request"/>-->
        <userTask id="approveTask" name="Approve or reject request" flowable:assignee="${employee}"/>
        <sequenceFlow sourceRef="approveTask" targetRef="decision"/>

        <exclusiveGateway id="decision"/>
        <sequenceFlow sourceRef="decision" targetRef="externalSystemCall">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[
          ${approved}
        ]]>
            </conditionExpression>
        </sequenceFlow>
        <sequenceFlow  sourceRef="decision" targetRef="sendRejectionMail">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[
          ${!approved}
        ]]>
            </conditionExpression>
        </sequenceFlow>

        <serviceTask id="externalSystemCall" name="Enter holidays in external system"
                     flowable:class="org.flowable.CallExternalSystemDelegate"/>
        <sequenceFlow sourceRef="externalSystemCall" targetRef="holidayApprovedTask"/>

<!--        <userTask id="holidayApprovedTask" name="Holiday approved"/>-->
        <userTask id="holidayApprovedTask" name="Holiday approved" flowable:assignee="${employee}"/>
        <sequenceFlow sourceRef="holidayApprovedTask" targetRef="approveEnd"/>

        <serviceTask id="sendRejectionMail" name="Send out rejection email"
                     flowable:class="org.flowable.SendRejectionMail"/>
        <sequenceFlow sourceRef="sendRejectionMail" targetRef="rejectEnd"/>

        <endEvent id="approveEnd"/>

        <endEvent id="rejectEnd"/>

    </process>

</definitions>

  完整测试类

package com.java;

import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricActivityInstanceQuery;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: 喵星人
 * @Create: 2024/3/11 9:50
 */
public class HolidayRequest {

    ProcessEngineConfiguration cfg=null;

    @Before
    public void processTest(){
         cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl("jdbc:mysql://127.0.0.1:3307/public_workflow?useUnicode=true&characterEncoding=utf-8&useSSL=false")
                .setJdbcUsername("root")
                .setJdbcPassword("qweiop1992")
                .setJdbcDriver("com.mysql.jdbc.Driver")
                //表结构不存在就创建
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    }

    /**
     * 部署流程
     */
    @Test
    public void test001(){
        /**
         * 获取对象
         */
        ProcessEngine processEngine = cfg.buildProcessEngine();
        RepositoryService service = processEngine.getRepositoryService();
        /**
         * 完成流程部署
         */
        Deployment deploy = service.createDeployment()
                .addClasspathResource("holiday-request.bpmn20.xml")
                .deploy();
        System.out.println("deploy.getId() = " + deploy.getId());
        System.out.println("deploy.getName() = " + deploy.getName());
    }

    /**
     * 查询流程定义的信息
     */
    @Test
    public void test002(){
        ProcessEngine processEngine = cfg.buildProcessEngine();
        RepositoryService service = processEngine.getRepositoryService();
        ProcessDefinition definition = service.createProcessDefinitionQuery()
                .deploymentId("1")
                .singleResult();
        System.out.println("definition.getDeploymentId() = " + definition.getDeploymentId());
        System.out.println("definition.getName() = " + definition.getName());
        System.out.println("definition.getDescription() = " + definition.getDescription());
    }

    /**
     * 删除定义流程
     */
    @Test
    public void test003(){
        ProcessEngine processEngine = cfg.buildProcessEngine();
        RepositoryService service = processEngine.getRepositoryService();
        //service.deleteDeployment("2501");
        service.deleteDeployment("2501",true);
    }

    /**
     * 启动流程实例
     */
    @Test
    public void test004() {
        ProcessEngine processEngine = cfg.buildProcessEngine();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        /**
         * 构建流程变量
         */
        Map<String,Object> variable=new HashMap<String, Object>(16);
        variable.put("employee","李欣");
        variable.put("nrOfHolidays", 3);
        variable.put("description", "世界那么大,我想去浪浪...");
        /**
         * 启动流程实例
         */
        ProcessInstance request = runtimeService.startProcessInstanceByKey("holidayRequest", variable);
        System.out.println("request.getProcessDefinitionId() = " + request.getProcessDefinitionId());
        System.out.println("request.getActivityId() = " + request.getActivityId());
        System.out.println("request.getId() = " + request.getId());
    }


    /**
     * 任务查询
     */
    @Test
    public void test005(){
        ProcessEngine processEngine = cfg.buildProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery()
                .processDefinitionKey("holidayRequest")
                .taskAssignee("李欣")
                .list();
        for (Task task : tasks) {
            System.out.println("task.getProcessDefinitionId() = " + task.getProcessDefinitionId());
            System.out.println("task.getName() = " + task.getName());
            System.out.println("task.getAssignee() = " + task.getAssignee());
            System.out.println("task.getDescription() = " + task.getDescription());
            System.out.println("task.getId() = " + task.getId());
        }
    }

    /**
     * 任务完成
     */
    @Test
    public void test006(){
        ProcessEngine engine = cfg.buildProcessEngine();
        TaskService taskService = engine.getTaskService();
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holidayRequest")
                .taskAssignee("李欣")
                .singleResult();
        Map<String,Object> variable=new HashMap<String, Object>(16);
        variable.put("approved",false);
        taskService.complete(task.getId(),variable);
    }

    /**
     * 查询历史任务
     */
    @Test
    public void test007(){
        ProcessEngine engine = cfg.buildProcessEngine();
        HistoryService service = engine.getHistoryService();
        List<HistoricActivityInstance> list = service.createHistoricActivityInstanceQuery()
                .processDefinitionId("holidayRequest:3:30003")
                .finished()
                .list();
        for (HistoricActivityInstance instance : list) {
            System.out.println("instance.getActivityId() = " + instance.getActivityId());
            System.out.println("instance.getAssignee() = " + instance.getAssignee());
            System.out.println("instance.getActivityName() = " + instance.getActivityName());
            System.out.println("instance.getDurationInMillis() = " + instance.getDurationInMillis());
        }
    }

}

  

标签:engine,task,Flowable,System,查询,instance,任务,println,out
From: https://www.cnblogs.com/q202105271618/p/18065898

相关文章

  • Flowable启动流程实例和查询任务以及完成任务
    效果图 因为流程删除,所以需要  代码部分packagecom.java;importorg.flowable.engine.ProcessEngine;importorg.flowable.engine.ProcessEngineConfiguration;importorg.flowable.engine.RepositoryService;importorg.flowable.engine.RuntimeService;import......
  • 使用flowable创建工作引擎
    pom依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven......
  • C# WebApi定时任务FluentScheduler的使用
    第一步:通过NuGget包下载安装FluentScheduler包;第二步:在全局配置文件Global.asax中注册定时任务,方法如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Http;usingSystem.Web.Routing;usingFluentScheduler;......
  • 在数据库中使用UUID+自增长ID混合方式,同时满足系统安全性和查询效率
    在数据库中使用UUID+自增长ID混合方式,可以达到较好的安全性和查询效率。具体的实现方式如下:在数据库表中创建两个字段,一个是UUID字段作为全局唯一主键,另一个是自增长的整型字段作为局部有序键。例如:sql:CREATETABLE`table_name`(`uuid`CHAR(36)NOTNULL,--UUID......
  • 【Python使用】python高级进阶知识md总结第3篇:静态Web服务器-返回指定页面数据,静态We
    python高级进阶全知识知识笔记总结完整教程(附代码资料)主要内容讲述:操作系统,虚拟机软件,Ubuntu操作系统,Linux内核及发行版,查看目录命令,切换目录命令,绝对路径和相对路径,创建、删除文件及目录命令,复制、移动文件及目录命令,终端命令格式的组成,查看命令帮助。HTTP请求报文,HTTP响应报文......
  • python爬虫scrapy之如何同时执行多个scrapy爬行任务
    来源:https://www.shanhubei.com/archives/23601.html1、顺序执行:fromscrapy.cmdlineimportexecuteexecute(['scrapy','crawl','httpbin'])2、同时进行setting=get_project_settings()process=CrawlerProcess(setting)didntWo......
  • Python实现企业微信自动打卡程序二:跳过节假日,随机打卡时间,定时任务,失败通知
    一、介绍在上节Python实现企业微信上下班自动打卡程序内容之后,我们继续优化自动打卡程序。接下来增加如下内容:实现打卡时间随机范围处理节假日不打卡的情况实现定时调度打卡打卡成功或失败通知自己二、实现打卡时间随机范围既然我们程序写完后需要定时执行,那定时执行打......
  • mysql查询几天之前,或某个时间段之间的每天记录数量,不存在补全0
    直接看SQL(非常简单,通俗易懂)biz_requirement_order:业务表名create_time:业务表时间字段,依据这个字段统计数量num:数量返回值别名,可以随意改t表:查询所有符合条件的日期a表:业务表中根据日期分组,查询每天的记录数量最后使用左连接查询,将两个集合合并返回最终结果查询几天之前......
  • SqlServer常用监控查询语句
    --查询SqlServer总体的内存使用情况selecttype,sum(virtual_memory_reserved_kb)VM_Reserved,sum(virtual_memory_committed_kb)VM_Commited,sum(awe_allocated_kb)AWE_Allocated,sum(shared_memory_reserved_kb)Shared_Res......
  • sqlalchemy高级查询操作
    连接数据库准备fromsqlalchemy.ormimportsessionmakerfromsqlalchemyimportcreate_enginefromsqlalchemy.ormimportscoped_sessionfrommodelsimportUsers,Person,Hobby,Boy,Girlfromsqlalchemy.sqlimporttextengine=create_engine("mysql+pymysql://roo......