| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -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()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |