|  | @ -3,8 +3,8 @@ package com.yihu.hos.system.service;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.JsonNode;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.hos.common.graph.DGraphImpl;
 | 
	
		
			
				|  |  | import com.yihu.hos.common.graph.IDGraph;
 | 
	
		
			
				|  |  | import com.yihu.hos.common.graph.Edge;
 | 
	
		
			
				|  |  | import com.yihu.hos.common.graph.IDGraph;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.datatype.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.AppDao;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.AppServiceDao;
 | 
	
	
		
			
				|  | @ -32,6 +32,8 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |     private ProcessorDao processorDao;
 | 
	
		
			
				|  |  |     @Resource(name = FlowProcessDao.BEAN_ID)
 | 
	
		
			
				|  |  |     private FlowProcessDao processDao;
 | 
	
		
			
				|  |  |     @Resource(name = FlowManager.BEAN_ID)
 | 
	
		
			
				|  |  |     private FlowManager flowManager;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private ObjectMapper objectMapper = new ObjectMapper();
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -79,7 +81,7 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |         for (SystemServiceFlowProcessor processor : processorList) {
 | 
	
		
			
				|  |  |             ProcessResultModel resultModel = new ProcessResultModel();
 | 
	
		
			
				|  |  |             resultModel.setName(processor.getName());
 | 
	
		
			
				|  |  |             resultModel.setValue(processor.getClassName());
 | 
	
		
			
				|  |  |             resultModel.setValue(processor.getPackageName() + "." + processor.getClassName());
 | 
	
		
			
				|  |  |             resultModelList.add(resultModel);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String result = objectMapper.writeValueAsString(resultModelList);
 | 
	
	
		
			
				|  | @ -97,7 +99,6 @@ public class ProcessManager {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static void main(String[] args) throws Exception {
 | 
	
		
			
				|  |  |         String flowJsonStr = "{\n" +
 | 
	
		
			
				|  |  |                 "    \"code\": \"crawler\",\n" +
 | 
	
		
			
				|  |  |                 "    \"nodes\": {\n" +
 | 
	
		
			
				|  |  |                 "        \"node_1\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"name\": \"Quartz\",\n" +
 | 
	
	
		
			
				|  | @ -105,7 +106,7 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"default\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"node_2\": {\n" +
 | 
	
		
			
				|  |  |                 "           \"name\": \"DefaultHttpProcessor\",\n" +
 | 
	
		
			
				|  |  |                 "           \"name\": \"常用HTTP转换器\",\n" +
 | 
	
		
			
				|  |  |                 "            \"value\": \"com.yihu.hos.broker.common.processor.DefaultHttpProcessor\",\n" +
 | 
	
		
			
				|  |  |                 "\t\t\t\"param\": \"{\\\"jobId\\\":\\\"5ad5c11655d443c30155d477a6b10000\\\"}\",\n" +
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"processor\"\n" +
 | 
	
	
		
			
				|  | @ -114,22 +115,6 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |                 "            \"name\": \"Crawler0\",\n" +
 | 
	
		
			
				|  |  |                 "            \"value\": \"http4://localhost:8088/crawler/patientList?method=post\",\n" +
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"service\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"node_4\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"name\": \"Circle\",\n" +
 | 
	
		
			
				|  |  |                 "            \"value\": \"splitJsonArray\",\n" +
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"circle\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"node_5\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"name\": \"HttpProcessor\",\n" +
 | 
	
		
			
				|  |  |                 "            \"value\": \"com.yihu.hos.broker.common.processor.HttpProcessor\",\n" +
 | 
	
		
			
				|  |  |                 "\t\t\t\"param\": \"str\",\n" +
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"processor\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"node_6\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"name\": \"Crawler2\",\n" +
 | 
	
		
			
				|  |  |                 "            \"value\": \"http4://localhost:8088/crawler/collect?method=post\",\n" +
 | 
	
		
			
				|  |  |                 "            \"nodeType\": \"service\"\n" +
 | 
	
		
			
				|  |  |                 "        }\n" +
 | 
	
		
			
				|  |  |                 "    },\n" +
 | 
	
		
			
				|  |  |                 "    \"lines\": {\n" +
 | 
	
	
		
			
				|  | @ -140,29 +125,16 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |                 "        \"line_2\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"from\": \"node_2\",\n" +
 | 
	
		
			
				|  |  |                 "            \"to\": \"node_3\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"line_3\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"from\": \"node_3\",\n" +
 | 
	
		
			
				|  |  |                 "            \"to\": \"node_4\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"line_4\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"from\": \"node_4\",\n" +
 | 
	
		
			
				|  |  |                 "            \"to\": \"node_5\"\n" +
 | 
	
		
			
				|  |  |                 "        },\n" +
 | 
	
		
			
				|  |  |                 "        \"line_5\": {\n" +
 | 
	
		
			
				|  |  |                 "            \"from\": \"node_5\",\n" +
 | 
	
		
			
				|  |  |                 "            \"to\": \"node_6\"\n" +
 | 
	
		
			
				|  |  |                 "        }\n" +
 | 
	
		
			
				|  |  |                 "    }\n" +
 | 
	
		
			
				|  |  |                 "}";
 | 
	
		
			
				|  |  |         formatJson(flowJsonStr);
 | 
	
		
			
				|  |  | //        generateFile("crawler", "业务流程图", flowJsonStr);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static String formatJson(String flowJsonStr) throws Exception {
 | 
	
		
			
				|  |  |     public String generateFile(String code, String name, String flowJsonStr) throws Exception {
 | 
	
		
			
				|  |  |         String root = "";
 | 
	
		
			
				|  |  |         ObjectMapper objectMapper = new ObjectMapper();
 | 
	
		
			
				|  |  |         JsonNode flowJson = objectMapper.readValue(flowJsonStr, JsonNode.class);
 | 
	
		
			
				|  |  |         String code = flowJson.get("code").asText();
 | 
	
		
			
				|  |  |         //sort flow by lines
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JsonNode lines = flowJson.get("lines");
 | 
	
	
		
			
				|  | @ -199,6 +171,24 @@ public class ProcessManager {
 | 
	
		
			
				|  |  |         editor.setLineMap(lineMap);
 | 
	
		
			
				|  |  |         editor.setNodeMap(nodeMap);
 | 
	
		
			
				|  |  |         //generate the java code
 | 
	
		
			
				|  |  |         return editor.generate();
 | 
	
		
			
				|  |  |         String javaName = toUpperCaseFirstOne(code)+"Route";
 | 
	
		
			
				|  |  |         String packageName = code+".route";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String fileInfo = editor.generate(javaName, packageName);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Boolean flag = flowManager.sendAddRoute(code, name, javaName, packageName, fileInfo);
 | 
	
		
			
				|  |  |         if (flag) {
 | 
	
		
			
				|  |  |             return javaName;
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //首字母转大写
 | 
	
		
			
				|  |  |     public static String toUpperCaseFirstOne(String s) {
 | 
	
		
			
				|  |  |         if(Character.isUpperCase(s.charAt(0)))
 | 
	
		
			
				|  |  |             return s;
 | 
	
		
			
				|  |  |         else
 | 
	
		
			
				|  |  |             return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |