springboot2 使用activiti6 idea插件的过程详解
更新时间:2022年03月29日 09:50:58 作者:qwer78
这篇文章主要介绍了springboot2 使用activiti6 idea插件,本文通过截图实例代码相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
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<String, Object> 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<HistoricProcessInstance> historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().startedBy(userId).list(); //根据流程定义的key,负责人assignee来实现 当前用户的 待办任务列表查询 List<Task> 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<String, Object> map = task.getProcessVariables(); for (Map.Entry<String, Object> m : map.entrySet()) { System.out.println("key:" + m.getKey() + " value:" + m.getValue()); } for (Map.Entry<String, Object> 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<HistoricTaskInstance> 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<Comment> comments = taskService.getTaskComments(hai.getId()); System.out.println("评论内容:" + JSON.toJSONString(comments)); }
到此这篇关于springboot2 使用activiti6 idea插件的文章就介绍到这了,更多相关springboot2 activiti6 idea插件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
浅谈JDK8中的Duration Period和ChronoUnit
在JDK8中,引入了三个非常有用的时间相关的API:Duration,Period和ChronoUnit。他们都是用来对时间进行统计的,本文将会详细讲解一下这三个API的使用2021-06-06JAVA基础 语句标签的合法使用,以及{}语句块到底有什么用?
以前的一个思维误区,for(){},if(){}之类的用法中,逻辑if()和语句块{}应该是相互独立的两种语法2012-08-08
最新评论