diff --git a/src/main/java/com/example/demo/controller/WorkFlowController.java b/src/main/java/com/example/demo/controller/WorkFlowController.java index ca29c32..5e784d1 100644 --- a/src/main/java/com/example/demo/controller/WorkFlowController.java +++ b/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 endEventList = model.getProcesses().get(0).findFlowElementsOfType(EndEvent.class); List 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 flowElements = model.getProcesses().get(0).getFlowElements(); - List 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 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 map = new HashMap<>(); - map.put("num",num); - ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayex",map); + Map map = new HashMap<>(); + map.put("num", num); + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayex", map); System.out.println(processInstance.getProcessDefinitionId()); System.out.println(processInstance.getId()); } diff --git a/src/main/resources/bpmn/testex1.bpmn b/src/main/resources/bpmn/testex1.bpmn index cc0f504..800b76b 100644 --- a/src/main/resources/bpmn/testex1.bpmn +++ b/src/main/resources/bpmn/testex1.bpmn @@ -1,6 +1,6 @@ - + @@ -9,18 +9,22 @@ - + + + - =7}]]> + - =3 && num<7}]]> + @@ -72,7 +76,7 @@ - + @@ -92,7 +96,7 @@ - + @@ -128,7 +132,7 @@ - +