springboot2 使用activiti6 idea插件的过程详解

springboot2 使用activiti6 idea插件的过程详解_第1张图片

springboot2 使用activiti6 idea插件的过程详解_第2张图片

springboot2 使用activiti6 idea插件的过程详解_第3张图片

springboot2 使用activiti6 idea插件的过程详解_第4张图片

springboot2 使用activiti6 idea插件的过程详解_第5张图片

Activiti BPMN visualizer插件

import com.alibaba.fastjson.JSON;
import com.schinta.util.DateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.*;
import org.activiti.engine.history.*;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Comment;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.CollectionUtils;
import java.util.*;
//spring boot2 集成activiti6 一系列异常文档  https://www.jianshu.com/p/77fa5f932f4f
@Slf4j
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class WebApplicationTests {
    @Autowired
    private ProcessEngine processEngine;
    private RepositoryService repositoryService;
    private RuntimeService runtimeService;
    private TaskService taskService;
    private HistoryService historyService;
    @Test
    public void deployProcess() {
        //部署模板
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("processes/wh.bpmn20.xml")
                .deploy();
        System.out.println(deploy.getId());
    }
    public void start() {
        String instanceKey = "wh";
        log.info("开启请假流程...");
        Map map = new HashMap<>();
        //在wh.bpmn中,填写请假单的任务办理人为动态传入的userId,此处模拟一个id
        map.put("user1", 1);
        map.put("user2", 2);
        Authentication.setAuthenticatedUserId("1");
        ProcessInstance instance = runtimeService.startProcessInstanceByKey(instanceKey, map);
        log.info("启动流程实例成功:{}", instance);
        log.info("流程实例ID:{}", instance.getId());
        log.info("流程定义ID:{}", instance.getProcessDefinitionId());
    public void taskQuery() {
        //查询自己发起的全部的审批
        //List historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedBy(userId).list();
        //根据流程定义的key,负责人assignee来实现  当前用户的 待办任务列表查询
        List list = taskService.createTaskQuery()
                .processDefinitionKey(instanceKey)
                .taskAssignee("2")
                .list();
        if (list != null && list.size() > 0) {
            for (Task task : list) {
                System.out.println("任务ID:" + task.getId());
                System.out.println("任务名称:" + task.getName());
                System.out.println("任务的创建时间:" + task.getCreateTime());
                System.out.println("任务的办理人:" + task.getAssignee());
                System.out.println("流程实例ID:" + task.getProcessInstanceId());
                System.out.println("执行对象ID:" + task.getExecutionId());
                System.out.println("流程定义ID:" + task.getProcessDefinitionId());
                System.out.println("getOwner:" + task.getOwner());
                System.out.println("getCategory:" + task.getCategory());
                System.out.println("getDescription:" + task.getDescription());
                System.out.println("getFormKey:" + task.getFormKey());
                Map map = task.getProcessVariables();
                for (Map.Entry m : map.entrySet()) {
                    System.out.println("key:" + m.getKey() + " value:" + m.getValue());
                }
                for (Map.Entry m : task.getTaskLocalVariables().entrySet()) {
            }
        }
    /**
     * 审批
     */
    public void employeeApply() {
        String instanceId = "130001"; //  执行流程实例id
        Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
        //是否同意 0 同意, 1 驳回
        map.put("status", "0");
        taskService.addComment(task.getId(), instanceId, "测试评论34");
        taskService.complete(task.getId(), map);
        log.info("流程推动到下环节");
     * 实例详情
    public void queryHistoryTask() {
        List list = historyService.createHistoricTaskInstanceQuery() // 创建历史活动实例查询
                .processInstanceId(instanceId) // 执行流程实例id
                .orderByTaskCreateTime()
                .asc()
        for (HistoricTaskInstance hai : list) {
            System.out.println("===================");
            System.out.println("活动ID:" + hai.getId());
            System.out.println("流程实例ID:" + hai.getProcessInstanceId());
            System.out.println("活动名称:" + hai.getName());
            System.out.println("办理人:" + hai.getAssignee());
            System.out.println("开始时间:" + hai.getStartTime());
            System.out.println("结束时间:" + hai.getEndTime());
            List comments = taskService.getTaskComments(hai.getId());
            System.out.println("评论内容:" + JSON.toJSONString(comments));
}

到此这篇关于springboot2 使用activiti6 idea插件的文章就介绍到这了,更多相关springboot2 activiti6 idea插件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(springboot2 使用activiti6 idea插件的过程详解)