Activiti学习笔记 (4)

代码:

package com.cjrj.bootactividemo; import java.util.HashMap; import java.util.Map; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; /** * 排他网关 * * @author Jamin * */ public class Test3 { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); @org.junit.Test public void test() { // 部署 Deployment deployment = processEngine.getRepositoryService().createDeployment() .addClasspathResource("reimburse/MyProcess.bpmn") .addClasspathResource("reimburse/MyProcess.png").deploy(); // 启动 ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("reimburse"); // 查询任务 Task task = processEngine.getTaskService().createTaskQuery().taskAssignee("张三") .processInstanceId(processInstance.getId()).singleResult(); System.out.println("------------------------------------------------"); System.out.println(task.getId()); System.out.println("-------------------------------------------------"); // 完成任务,附带流程定义 Map<String, Object> map = new HashMap<String, Object>(); map.put("money", 10000); processEngine.getTaskService().complete(task.getId(), map); // 李四的任务 Task lisi = processEngine.getTaskService().createTaskQuery().taskAssignee("李四") .processInstanceId(processInstance.getId()).singleResult(); Task wangwu = processEngine.getTaskService().createTaskQuery().taskAssignee("王五") .processInstanceId(processInstance.getId()).singleResult(); Task zhaoliu = processEngine.getTaskService().createTaskQuery().taskAssignee("赵六") .processInstanceId(processInstance.getId()).singleResult(); if (lisi == null) { System.out.println("李四没有任务"); } if (wangwu == null) { System.out.println("王五没有任务"); } if (zhaoliu == null) { System.out.println("赵六没有任务"); } } }

接收任务

接收任务

代码:

package com.cjrj.bootactividemo; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.Execution; import org.activiti.engine.runtime.ProcessInstance; /** * 接受任务(启动流程实例 执行查询执行对象 查询不到第一个) * * @author Jamin * @date 2019年7月16日 下午8:08:15 * */ public class Task5 { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); @org.junit.Test public void test() { // 部署 Deployment deploy = processEngine.getRepositoryService().createDeployment() .addClasspathResource("message/message.bpmn").addClasspathResource("message/message.png") .deploy(); // 启动 ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("message"); System.out.println(processInstance.getId()); // 查询执行对象 Execution execution = processEngine.getRuntimeService().createExecutionQuery() .processInstanceId(processInstance.getId()).activityId("receivetask1").singleResult(); System.out.println("当前执行对象"); System.out.println(execution.getActivityId()); System.out.println("end当前执行对象"); processEngine.getRuntimeService().signal(execution.getId()); ProcessInstance pi = processEngine.getRuntimeService().createProcessInstanceQuery() .processInstanceId(processInstance.getId()).singleResult(); System.out.println("查询实例是否结束"); System.out.println(pi); // 查询执行对象 Execution execution2 = processEngine.getRuntimeService().createExecutionQuery() .processInstanceId(processInstance.getId()).activityId("receivetask2").singleResult(); System.out.println("当前执行对象"); System.out.println(execution2.getActivityId()); System.out.println("end当前执行对象"); processEngine.getRuntimeService().signal(execution2.getId()); ProcessInstance pi2 = processEngine.getRuntimeService().createProcessInstanceQuery() .processInstanceId(processInstance.getId()).singleResult(); System.out.println("查询实例是否结束"); System.out.println(pi2); } }

20.个人任务
1.直接指定办理人
2.通过流程变量指定办理人

bpmn图

通过流程变量指定办理人

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjswz.html