Browse Source

success

master
燕鹏 4 years ago
parent
commit
74e9fee2f2
  1. 31
      src/main/java/com/example/demo/controller/WorkFlowController.java
  2. 18
      src/main/resources/bpmn/testex1.bpmn

31
src/main/java/com/example/demo/controller/WorkFlowController.java

@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;
@ -52,7 +53,7 @@ public class WorkFlowController {
public void model() {
RepositoryService repositoryService = processEngine.getRepositoryService();
Model model = repositoryService.newModel();
model.setName("请假工作流");
model.setName("请假工作流市场部");
model.setKey("holidayex");
repositoryService.saveModel(model);
System.out.println(model.getId());
@ -98,6 +99,7 @@ public class WorkFlowController {
JsonNode modelNode = new ObjectMapper().readTree(bytes);
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
model.getProcesses().get(0).setName(modelData.getName());
model.getProcesses().get(0).setId(modelData.getKey());
//校验有没有开始结束节点-
List<EndEvent> endEventList = model.getProcesses().get(0).findFlowElementsOfType(EndEvent.class);
List<StartEvent> startEventList = model.getProcesses().get(0).findFlowElementsOfType(StartEvent.class);
@ -106,19 +108,9 @@ public class WorkFlowController {
for (ExclusiveGateway gateway : gateways) {
System.out.println(gateway.getId());
Collection<FlowElement> flowElements = model.getProcesses().get(0).getFlowElements();
List<SequenceFlow> collect = model.getProcesses().get(0).findFlowElementsOfType(SequenceFlow.class).stream().filter(x -> {
flowElements.remove(x);
return x.getSourceRef().equals(gateway.getId());
}).collect(Collectors.toList());
Collections.sort(collect, (x1, x2) -> {
if (x1.getConditionExpression() == null && x2.getConditionExpression() != null) {
return 1;
}
if (x1.getConditionExpression() != null && x2.getConditionExpression() == null) {
return -1;
}
return 0;
});
List<SequenceFlow> collect = model.getProcesses().get(0).findFlowElementsOfType(SequenceFlow.class).stream().filter(x -> x.getSourceRef().equals(gateway.getId())).collect(Collectors.toList());
flowElements.removeAll(collect);
Collections.sort(collect, (x1, x2) -> x1.getConditionExpression() == null && x2.getConditionExpression() != null ? 1 : x1.getConditionExpression() != null && x2.getConditionExpression() == null ? -1 : 0);
flowElements.addAll(collect);
System.out.println(collect);
}
@ -133,13 +125,12 @@ public class WorkFlowController {
byte[] bpmnByates = new BpmnXMLConverter().convertToXML(model);
//发布流程
String processName = modelData.getName() + ".bpmn20.xml";
String convertToXML = new String(bpmnByates);
String convertToXML = new String(bpmnByates, "UTF-8");
System.out.println(convertToXML);
DeploymentBuilder deployment = repositoryService.createDeployment();
deployment.name(modelData.getName());
deployment.addString(processName, convertToXML);
// deployment.key(modelData.getKey());
deployment.key("holidayex");
deployment.key(modelData.getKey());
Deployment deploy = deployment.deploy();
modelData.setDeploymentId(deploy.getId());
System.out.println(deploy.getId());
@ -151,9 +142,9 @@ public class WorkFlowController {
@GetMapping("start")
public void start(Integer num) {
RuntimeService runtimeService = processEngine.getRuntimeService();
Map<String,Object> map = new HashMap<>();
map.put("num",num);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayex",map);
Map<String, Object> map = new HashMap<>();
map.put("num", num);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayex", map);
System.out.println(processInstance.getProcessDefinitionId());
System.out.println(processInstance.getId());
}

18
src/main/resources/bpmn/testex1.bpmn

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/testm1604633800390" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1604633800390" name="" targetNamespace="http://www.activiti.org/testm1604633800390" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="holiday请假" isClosed="false" isExecutable="true" processType="None">
<process id="holiday请假" isClosed="true" isExecutable="true" processType="None">
<startEvent id="_2" name="StartEvent"/>
<userTask activiti:exclusive="true" id="_5" name="启动任务"/>
<endEvent id="_12" name="EndEvent"/>
@ -9,18 +9,22 @@
<sequenceFlow id="_6" sourceRef="_2" targetRef="_5"/>
<userTask activiti:exclusive="true" id="_7" name="第一分支"/>
<userTask activiti:exclusive="true" id="_9" name="第三分支"/>
<userTask activiti:exclusive="true" id="_20" name="默认分支"/>
<userTask activiti:exclusive="true" id="_20" name="默认分支">
<multiInstanceLoopCharacteristics isSequential="false"/>
</userTask>
<userTask activiti:exclusive="true" id="_10" name="结束节点"/>
<sequenceFlow id="_11" sourceRef="_10" targetRef="_12"/>
<sequenceFlow id="_13" sourceRef="_4" targetRef="_7">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${num>=7}]]>
<![CDATA[
]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_8" sourceRef="_4" targetRef="_20"/>
<sequenceFlow id="_3" sourceRef="_4" targetRef="_9">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${num>=3 && num<7}]]>
<![CDATA[
]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_15" sourceRef="_7" targetRef="_10"/>
@ -72,7 +76,7 @@
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_20" id="Shape-_20">
<dc:Bounds height="55.0" width="85.0" x="440.0" y="155.0"/>
<dc:Bounds height="55.0" width="85.0" x="440.0" y="145.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
@ -92,7 +96,7 @@
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_20" targetElement="_10">
<di:waypoint x="525.0" y="182.5"/>
<di:waypoint x="525.0" y="172.5"/>
<di:waypoint x="675.0" y="162.5"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
@ -128,7 +132,7 @@
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_4" targetElement="_20">
<di:waypoint x="327.0" y="166.0"/>
<di:waypoint x="440.0" y="182.5"/>
<di:waypoint x="440.0" y="172.5"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>

Loading…
Cancel
Save