流程在审批的过程中需要进行一些判断然后再看下一步怎么走,完成判断逻辑的是网关,排他网关就是其中的一种。
排他网关(也叫异或(XOR)网关,或更技术性的叫法 基于数据的排他网关), 用来在流程中实现决策。 当流程执行到这个网关,所有外出顺序流都会被处理一遍。 其中条件解析为true的顺序流(或者没有设置条件,概念上在顺序流上定义了一个’true’) 会被选中,让流程继续运行。简单理解条件为True继续执行,False将不执行。
我们在Modeler中给我们的流程配置一个排他网关,添加后流程如下:
在排他网关的到结束的连接线上配置好网关是否通过的条件,比如审核通过我们设置为${outcome==‘通过’},当走到这里流程变量outcome为通过的时候将会走审核通过这个流程,等于拒绝的时候走下面的流程,参数配置如下图所示:
流程文件内容如下:
<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:flowable="http://flowable.org/bpmn" 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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
<process id="test_bpmn" name="测试BPMN模型" isExecutable="true">
<documentation>测试BPMN模型documentation>
<startEvent id="start" name="开始">startEvent>
<endEvent id="end" name="通过结束">endEvent>
<userTask id="testUser" name="用户任务测试" flowable:assignee="admin">
<extensionElements>
<flowable:taskListener event="create" class="com.hyj.flowlistener.CommonUserStartListener">flowable:taskListener>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler">modeler:initiator-can-complete>
extensionElements>
userTask>
<sequenceFlow id="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" sourceRef="start" targetRef="testUser">sequenceFlow>
<exclusiveGateway id="ex_gateway_check" name="审核结果">exclusiveGateway>
<sequenceFlow id="sid-50731902-EF37-4E07-9DED-2E83F7EB54B7" sourceRef="testUser" targetRef="ex_gateway_check">sequenceFlow>
<endEvent id="end_fail" name="失败结束">endEvent>
<sequenceFlow id="check_fail" name="审核拒绝" sourceRef="ex_gateway_check" targetRef="end_fail">
<conditionExpression xsi:type="tFormalExpression">conditionExpression>
sequenceFlow>
<sequenceFlow id="check_ok" name="审核通过" sourceRef="ex_gateway_check" targetRef="end">
<conditionExpression xsi:type="tFormalExpression">conditionExpression>
sequenceFlow>
process>
<bpmndi:BPMNDiagram id="BPMNDiagram_test_bpmn">
<bpmndi:BPMNPlane bpmnElement="test_bpmn" id="BPMNPlane_test_bpmn">
<bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
<omgdc:Bounds height="30.0" width="30.0" x="210.0" y="120.0">omgdc:Bounds>
bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
<omgdc:Bounds height="28.0" width="28.0" x="630.0" y="60.0">omgdc:Bounds>
bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="testUser" id="BPMNShape_testUser">
<omgdc:Bounds height="80.0" width="100.0" x="315.0" y="95.0">omgdc:Bounds>
bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="ex_gateway_check" id="BPMNShape_ex_gateway_check">
<omgdc:Bounds height="40.0" width="40.0" x="480.0" y="115.0">omgdc:Bounds>
bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end_fail" id="BPMNShape_end_fail">
<omgdc:Bounds height="28.0" width="28.0" x="630.0" y="180.0">omgdc:Bounds>
bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="check_fail" id="BPMNEdge_check_fail">
<omgdi:waypoint x="500.5" y="154.4338310580205">omgdi:waypoint>
<omgdi:waypoint x="500.5" y="194.0">omgdi:waypoint>
<omgdi:waypoint x="630.0" y="194.0">omgdi:waypoint>
bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" id="BPMNEdge_sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002">
<omgdi:waypoint x="239.94999779398907" y="135.0">omgdi:waypoint>
<omgdi:waypoint x="315.0" y="135.0">omgdi:waypoint>
bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-50731902-EF37-4E07-9DED-2E83F7EB54B7" id="BPMNEdge_sid-50731902-EF37-4E07-9DED-2E83F7EB54B7">
<omgdi:waypoint x="414.95000000000005" y="135.0">omgdi:waypoint>
<omgdi:waypoint x="480.0" y="135.0">omgdi:waypoint>
bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="check_ok" id="BPMNEdge_check_ok">
<omgdi:waypoint x="500.5" y="115.5">omgdi:waypoint>
<omgdi:waypoint x="500.5" y="74.0">omgdi:waypoint>
<omgdi:waypoint x="630.0" y="74.0">omgdi:waypoint>
bpmndi:BPMNEdge>
bpmndi:BPMNPlane>
bpmndi:BPMNDiagram>
definitions>
控制器原来直接是个完成任务现在,我们方便起见拆分为2个一个是通过任务,一个是拒绝任务,如果你的排他网关使用的都是该参数那么就可以通用。
@RequestMapping("/accept")
@ResponseBody
public Map<String,Object> acceptTask(@RequestBody @RequestParam(required = false) Map<String,String> paras){
Map<String,Object> res =new HashMap<>();
Map<String,String> data = new HashMap<>();
if (MapUtils.isEmpty(paras)){
res.put("msg","请输入任务参数");
res.put("res","0");
res.put("data",data);
return res;
}
String taskId = paras.get("taskId");
if (StringUtils.isEmpty(taskId)){
res.put("msg","请输入任务ID");
res.put("res","0");
res.put("data",data);
return res;
}
Map<String,Object> flowParas=new HashMap<>();
flowParas.putAll(paras);
flowParas.put("outcome","通过");
boolean bok = flowService.completeTask(taskId,flowParas);
if (bok){
data.put("taskId",taskId);
res.put("msg","通过任务成功");
res.put("res","1");
}
else {
data.put("taskId",taskId);
res.put("msg","通过任务失败");
res.put("res","0");
}
res.put("data",data);
return res;
}
@RequestMapping("/reject")
@ResponseBody
public Map<String,Object> rejectTask(@RequestBody @RequestParam(required = false) Map<String,String> paras){
Map<String,Object> res =new HashMap<>();
Map<String,String> data = new HashMap<>();
if (MapUtils.isEmpty(paras)){
res.put("msg","请输入任务参数");
res.put("res","0");
res.put("data",data);
return res;
}
String taskId = paras.get("taskId");
if (StringUtils.isEmpty(taskId)){
res.put("msg","请输入任务ID");
res.put("res","0");
res.put("data",data);
return res;
}
Map<String,Object> flowParas=new HashMap<>();
flowParas.putAll(paras);
flowParas.put("outcome","拒绝");
boolean bok = flowService.completeTask(taskId,flowParas);
if (bok){
data.put("taskId",taskId);
res.put("msg","拒绝任务成功");
res.put("res","1");
}
else {
data.put("taskId",taskId);
res.put("msg","拒绝任务失败");
res.put("res","0");
}
res.put("data",data);
return res;
}
下载内容已经放到我的CSDN的资源页面,https://download.csdn.net/download/houyj1986/10943791
版权所有,侵权必究,代码与文章,使用、copy、转载请联系作者。由书山登峰人创作。