并行网关使用:并行网关开始,创建多个分支,每个分支都要执行,最后再汇聚到并行网关。
并行网关中不能设置流条件,设置了也被忽略。
用户创建申请流程,先经过组长审批,组长审批未通过就发送拒绝邮件,然后结束,组长审批通过,则有项目组长和部门经理审批,必须二人都同意,才通过,有一人不同意则发送拒绝邮件。
项目组长审批:如果审批通过,则设置参数 projectZZAgree == true,否则设置为false
部门经理审批:如果审批通过,则设置参数 bmAgree == true,否则设置为false
在排它网关结束后面进行流条件判断
- import org.flowable.engine.RuntimeService;
- import org.flowable.engine.TaskService;
- import org.flowable.engine.runtime.ProcessInstance;
- import org.flowable.task.api.Task;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RestController;
-
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- @RestController
- public class ParallelController {
- @Autowired
- private RuntimeService runtimeService;
-
- @Autowired
- private TaskService taskService;
-
- /**
- * 创建流程实例
- */
- @GetMapping("/createInstance/{username}/{day}")
- public String createInstance(@PathVariable String username, @PathVariable Integer day) {
- // 创建流程要携带的参数
- Map
variables = new HashMap<>(); - variables.put("people", username); // 报销申请人
- variables.put("reason", "有事情"); // 报销原因
- variables.put("day", day); // 请假天数
- ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("请假流程", variables);
- // 输出相关的流程实例信息
- System.out.println("流程实例的ID:" + processInstance.getId());// 流程实例的Id --> 5001
- System.out.println("流程创建成功");
- return username + "创建流程实例成功";
- }
-
- /**
- * 组长同意
- */
- @GetMapping("/agree/headman/{username}")
- public String completeTaskZZ(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - variable.put("zzAgree", true);
- System.out.println("组长同意");
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "同意";
- }
-
- /**
- * 项目组长同意
- */
- @GetMapping("/agree/manager/{username}")
- public String completeTaskJL(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - variable.put("projectZZAgree", true);
- System.out.println("项目组长同意");
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "同意";
- }
-
- /**
- * 部门经理同意
- */
- @GetMapping("/agree/boss/{username}")
- public String completeTask(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - variable.put("bmAgree", true);
- System.out.println("部门经理同意");
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "同意";
- }
-
- /**
- * 组长拒绝
- */
- @GetMapping("/reject/headman/{username}")
- public String rejectTask(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - variable.put("zzAgree", false);
- System.out.println("组长拒绝");
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "拒绝";
- }
-
- /**
- * 项目组长拒绝
- */
- @GetMapping("/reject/manager/{username}")
- public String rejectTaskJL(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - variable.put("projectZZAgree", false);
- System.out.println("项目组长拒绝");
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "拒绝";
- }
-
- /**
- * 部门经理拒绝
- */
- @GetMapping("/reject/boss/{username}")
- public String rejectTaskLB(@PathVariable String username) {
- List
l = taskService.createTaskQuery() - .processDefinitionKey("请假流程")
- .taskAssignee(username)
- .list();
- Task task = l.get(0);
- Map
variable = new HashMap<>(); - System.out.println("部门经理拒绝");
- variable.put("bmAgree", false);
- // 完成任务
- taskService.complete(task.getId(), variable);
- return username + "拒绝";
- }
- }
http://localhost:8081/createInstance/%E6%9D%8E%E6%98%BE%E8%B5%AB/3
http://localhost:8081/agree/headman/%E6%9D%8E%E6%98%BE%E8%B5%AB1%E5%8F%B7
ehttp://localhost:8081/reject/manager/%E6%9D%8E%E6%98%BE%E8%B5%AB2%E5%8F%B7
http://localhost:8081/agree/boss/%E6%9D%8E%E6%98%BE%E8%B5%AB3%E5%8F%B7
- 流程实例的ID:7557
- 流程创建成功
- 组长同意
- 项目组长拒绝
- 部门经理同意
- 发送拒绝邮件