仙术
-
1、设置变量
画图xml 文件:sequenceFlow 就代表了上方的双指向箭头
双指向箭头在 idea 插件外面是没有的,须要用后面说的软件,点击指向线点击设置符号就会显示
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.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" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.activiti.org/processdef" exporter="activiti Modeler" exporterVersion="3.0.0"> <process id="dd" name="testUpdate" isExecutable="true"> <startEvent id="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7" /> <userTask id="_3" name="创立出差申请" activiti:assignee="${assignee0}"> <extensionElements> <activiti:formProperty id="Property 1" /> <activiti:formProperty id="Property 2" /> </extensionElements> </userTask> <sequenceFlow id="sid-b30ee1df-6da8-4cfe-ac98-91f72c8494bc" sourceRef="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7" targetRef="_3" /> <userTask id="_4" name="部门经理审核" activiti:assignee="${assignee1}"> <extensionElements> <activiti:formProperty id="Property 1" /> </extensionElements> </userTask> <sequenceFlow id="sid-9573370a-bf0b-4003-8d51-d51c463a282c" sourceRef="_3" targetRef="_4" /> <userTask id="_5" name="总经理审批" activiti:assignee="${assignee2}"> <extensionElements> <activiti:formProperty id="Property 1" /> </extensionElements> </userTask> <userTask id="_6" name="财务审批" activiti:assignee="${assignee3}" > <extensionElements> <activiti:formProperty id="Property 1" /> </extensionElements> </userTask> **<sequenceFlow id="_11" sourceRef="_4" targetRef="_5"> <conditionExpression xsi:type="tFormalExpression">${evection.num>=3}</conditionExpression> </sequenceFlow> <sequenceFlow id="_10" sourceRef="_4" targetRef="_6"> <conditionExpression xsi:type="tFormalExpression">${!(evection.num>=3)}</conditionExpression> </sequenceFlow>** <!--<sequenceFlow id="_11" sourceRef="_4" targetRef="_5">--> <!-- <conditionExpression xsi:type="tFormalExpression">${evection.num>=3}</conditionExpression>--> <!--</sequenceFlow>--> <!--<sequenceFlow id="_10" sourceRef="_4" targetRef="_6">--> <!-- <conditionExpression xsi:type="tFormalExpression">${evection.num<3}</conditionExpression>--> <!--</sequenceFlow>--> <sequenceFlow id="sid-5566d8ce-7ce5-49c1-9bb5-3b0430b874b1" sourceRef="_5" targetRef="_6" /> <endEvent id="sid-a173a463-e580-4c50-8e37-1436c0a34950" /> <sequenceFlow id="sid-5af69afe-a2f7-4259-b953-628840a60ee2" sourceRef="_6" targetRef="sid-a173a463-e580-4c50-8e37-1436c0a34950" /> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_testUpdate"> <bpmndi:BPMNPlane id="BPMNPlane_testUpdate" bpmnElement="testUpdate"> <bpmndi:BPMNShape id="shape-da9b2c9f-2cc1-4b6d-9564-0b64729aaf1f" bpmnElement="sid-f9290572-60fe-46c8-ba1a-6d49ab85d9c7"> <omgdc:Bounds x="261" y="81" width="30" height="30" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="shape-ab0f3ec4-3b5f-493f-9e9c-8e5c402af1db" bpmnElement="_3"> <omgdc:Bounds x="231" y="126" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="edge-1d876cf9-3158-4b8c-b5b0-136f1d017ee7" bpmnElement="sid-b30ee1df-6da8-4cfe-ac98-91f72c8494bc"> <omgdi:waypoint x="283.5" y="111" /> <omgdi:waypoint x="281" y="126" /> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="shape-05c6fa49-0531-48e8-84cd-36fe3f33d9c8" bpmnElement="_4"> <omgdc:Bounds x="231" y="221" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="edge-69760489-b8bc-4419-a1fc-504694e219e9" bpmnElement="sid-9573370a-bf0b-4003-8d51-d51c463a282c"> <omgdi:waypoint x="281" y="206" /> <omgdi:waypoint x="281" y="221" /> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="shape-b444c63b-fa51-4e0a-b103-25fea15de25e" bpmnElement="_5"> <omgdc:Bounds x="156" y="326" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="shape-bb3d593f-baaa-40fd-b233-6a21ec80239d" bpmnElement="_6"> <omgdc:Bounds x="316" y="326" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="edge-15573ce2-e6a3-414c-b927-6d24214e5f6d" bpmnElement="_11"> <omgdi:waypoint x="256" y="301" /> <omgdi:waypoint x="231" y="326" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="edge-7a29c150-4f0e-48dc-8301-3fb34c3602cd" bpmnElement="_10"> <omgdi:waypoint x="306" y="301" /> <omgdi:waypoint x="341" y="326" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="edge-bb04d8dd-0c80-4dd1-82c2-d0a508f705c6" bpmnElement="sid-5566d8ce-7ce5-49c1-9bb5-3b0430b874b1"> <omgdi:waypoint x="256" y="366" /> <omgdi:waypoint x="316" y="366" /> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="shape-0b537d4f-587d-4f06-b1d7-6b21374a8f49" bpmnElement="sid-a173a463-e580-4c50-8e37-1436c0a34950"> <omgdc:Bounds x="466" y="351" width="30" height="30" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="edge-b166ebec-c69f-41ad-92b3-6b2ea2bb03ce" bpmnElement="sid-5af69afe-a2f7-4259-b953-628840a60ee2"> <omgdi:waypoint x="416" y="366" /> <omgdi:waypoint x="466" y="366.00002" /> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
而后失常流程启动:
-
1、定义
@Test public void Expression(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deploy = repositoryService.createDeployment() .name("出差申请流程 -variables") .addClasspathResource("bpmn1/testUpdate.bpmn20.xml") .deploy();}
-
2、启动
// 启动 @Test public void ExpressionStart(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); // 流程变量的 map Map<String,Object> variables = new HashMap(); // 设置流程变量 Evection evection = new Evection(); // 设置出差日期 evection.setNum(2d); // 把流程变量的 pojo 放入 map variables.put("evection",evection); // 设定工作的负责人 variables.put("assignee0","李四"); variables.put("assignee1","王经理"); variables.put("assignee2","杨总经理"); variables.put("assignee3","张财务"); // 启动流程 runtimeService.startProcessInstanceByKey("dd",variables); }
-
3、提交工作
@Test public void finshActivity1() { // 获取引擎 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取操作工作的服务 TaskService TaskService taskService = processEngine.getTaskService(); // 实现工作, 参数:工作 id, 先实现提交工作,在实现经理的首次审批工作,而后看成果会走向总经理还是间接走财务 taskService.complete("35002"); }
-
-
2、网关
-
1、排他网关
所有分支都会判断条件是否为 true,如果为 true 就执行该分支
留神:只会抉择一个 true 的分支执行,如果都满足条件,则走 flowid 最小的工作。
与上述条件变量的区别:都不满足条件,则抛出异样。
(一)创立 bpmn 文件
bug 坑:1 如果网关上面只有一条线,就不能够设置条件,因为他本人会把这个线当作默认,如果想只放一条线的话,就须要勾销默认,目前我没有找到勾销办法,所以只能先这样测试。![image_3.png](/img/bVcYEIg) 2 这个中央必须是 true,否则无奈加载流程 **(二)代码:** ```Java /** * 排他网关 */ ** 定义流程 ** @Test public void ExclusiveGetWay(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("bpmn1/getway1.bpmn20.xml") .name("出差申请流程 - 排他网关") .deploy();} ** 启动 ** @Test public void ExclusiveStart(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); Map<String, Object> map = new HashMap(); Evection evection = new Evection(); evection.setNum(3d); // 定义流程变量,把出差 pojo 对象放入 map map.put("evection",evection); // 启动流程实例,并设置流程变量的值(把 map 传入)ProcessInstance processInstance = runtimeService .startProcessInstanceByKey("定义的流程 id", map); 如果不晓得定义的流程 id 的能够会看后面的文章
} ** 实现工作 ** @Test public void finshActivity2() { // 获取引擎 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取操作工作的服务 TaskService TaskService taskService = processEngine.getTaskService(); // 实现工作, 参数:工作 id,task 表外面,如果不晓得看后面文章 taskService.complete("工作 id"); } 实现工作后,在上方设置不同的天数进行测试看流程 ```
-
2、并行网关
能够把多条分支汇聚一起,会走所有的分支、还要等多个分支实现才可持续实现。
留神:并行网关不会解析条件,即便定义了条件也会被疏忽。
图:
id 和 name 本人填就行
1 和 2 这两条线表达式相同,判断不同后果
代码:/** * 并行网关 */ // 流程定义 @Test public void ExclusiveGetWay1(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("bpmn1/getway2.bpmn20.xml") .name("出差申请流程 - 并行网关") .deploy();} @Test public void ExclusiveStart1(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); Map<String, Object> map = new HashMap(); Evection evection = new Evection(); evection.setNum(3d); // 定义流程变量,把出差 pojo 对象放入 map map.put("evection",evection); // 启动流程实例,并设置流程变量的值(把 map 传入)ProcessInstance processInstance = runtimeService .startProcessInstanceByKey("bingxing", map); } @Test public void finshActivity3() { // 获取引擎 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取操作工作的服务 TaskService TaskService taskService = processEngine.getTaskService(); // 实现工作, 参数:工作 id taskService.complete("105008"); }
都在 task 工作表 定义之后:
实现工作后
将这两个工作都实现后:
总经理工作实现后记录删除;
如果小于 3 天的话,不须要总经理审批,技术经理和项目经理工作实现后,记录间接删除。 - 3、蕴含网关
排他网关和并行网关的联合。都为 ture 的时候,都要执行工作,并且最初汇聚在一起才能够执行上来。
bpmn 文件图
id 和 name 本人设置,这三条线增设条件
2 和 3 的条件一样,1 的条件是 <3
实现 bpmn 文件后,开始进行代码流程
/** * 蕴含网关 */ @Test public void InclusiveGateway(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("bpmn1/getway3.bpmn20.xml") .name("出差申请流程 - 蕴含网关") .deploy();} // 启动 @Test public void InclusiveStart(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RuntimeService runtimeService = processEngine.getRuntimeService(); //key 能够见 bpmn 文件 <process> 标签 id String key = "InclusiveGateway"; Map<String, Object> map = new HashMap(); Evection evection = new Evection(); evection.setNum(2d); // 定义流程变量,把出差 pojo 对象放入 map map.put("evection",evection); // 启动流程实例,并设置流程变量的值(把 map 传入)ProcessInstance processInstance = runtimeService .startProcessInstanceByKey(key, map); } @Test public void finshActivity4() { // 获取引擎 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); // 获取操作工作的服务 TaskService TaskService taskService = processEngine.getTaskService(); // 实现工作, 参数:工作 id taskService.complete("17508");
-
-
我集体喜爱看 task 表来察看流程成果,也能够看 execution 表和 hi_tsakinst 表、hi_actinst 表看节点成果
到此对于 idea2019 以上版本的操作 activiti7 就临时完结了,我也是刚开始学,尽量的将我遇见的问题都写进去,看了很多文章也没有看到讲的很粗疏的有时候都是一笔带过,我做的时候会一个中央卡很长时间,所以我就写的尽力的粗疏,大家看到我的文章时也不会太费力气,先入门。