|
@ -8,8 +8,11 @@ import com.yihu.hos.core.encrypt.DES;
|
|
|
import com.yihu.hos.system.dao.AppDao;
|
|
|
import com.yihu.hos.system.dao.AppServiceDao;
|
|
|
import com.yihu.hos.system.dao.FlowProcessDao;
|
|
|
import com.yihu.hos.system.dao.ProcessorDao;
|
|
|
import com.yihu.hos.system.model.SystemApp;
|
|
|
import com.yihu.hos.system.model.SystemServiceEndpoint;
|
|
|
import com.yihu.hos.system.model.SystemServiceFlowProcess;
|
|
|
import com.yihu.hos.system.model.SystemServiceFlowProcessor;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -18,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service("ProcessManager")
|
|
@ -29,15 +33,17 @@ public class ProcessManager {
|
|
|
private AppDao appDao;
|
|
|
@Resource(name = AppServiceDao.BEAN_ID)
|
|
|
private AppServiceDao appServiceDao;
|
|
|
@Resource(name = ProcessorDao.BEAN_ID)
|
|
|
private ProcessorDao processorDao;
|
|
|
@Resource(name = FlowProcessDao.BEAN_ID)
|
|
|
private FlowProcessDao processDao;
|
|
|
|
|
|
private ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
public Result getAllApp() throws Exception {
|
|
|
String hql = "select * from SystemServiceEndpoint";
|
|
|
List<SystemServiceEndpoint> serviceEndpointList = appServiceDao.getEntityList(SystemServiceEndpoint.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(serviceEndpointList);
|
|
|
String hql = "select * from SystemApp";
|
|
|
List<SystemApp> appList = appDao.getEntityList(SystemApp.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(appList);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
@ -55,6 +61,13 @@ public class ProcessManager {
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
public Result getAllProcessor() throws Exception {
|
|
|
String hql = "select * from SystemServiceFlowProcessor";
|
|
|
List<SystemServiceFlowProcessor> processorList = processorDao.getEntityList(SystemServiceFlowProcessor.class, hql);
|
|
|
String result = objectMapper.writeValueAsString(processorList);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
public void saveProcess(String code, String name, String fileName, String positionJsonStr) throws Exception {
|
|
|
SystemServiceFlowProcess process = new SystemServiceFlowProcess();
|
|
|
process.setCode(code);
|
|
@ -98,7 +111,6 @@ public class ProcessManager {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
JsonNode flowJson = objectMapper.readValue(flowJsonStr, JsonNode.class);
|
|
|
String code = flowJson.get("code").asText();
|
|
|
String javaName = toUpperCaseFirstOne(code)+"Route";
|
|
|
//sort flow by lines
|
|
|
JsonNode lines = flowJson.get("lines");
|
|
|
Iterator<JsonNode> lineIterator = lines.iterator();
|
|
@ -145,9 +157,14 @@ public class ProcessManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
//mosaic the java code
|
|
|
//generate the java code
|
|
|
return generate(code, processorImport, nodeMap, nodeNameArray);
|
|
|
}
|
|
|
|
|
|
public String generate(String code, List<String> processorImport, Map<String, JsonNode> nodeMap, String[] nodeNameArray) throws IOException {
|
|
|
Boolean isFirstNodeFlg = true;
|
|
|
StringBuilder javaBuilder = new StringBuilder();
|
|
|
String javaName = toUpperCaseFirstOne(code)+"Route";
|
|
|
|
|
|
javaBuilder.append("package "+code+".route;\n\n");
|
|
|
javaBuilder.append("import org.apache.camel.Exchange;\n");
|
|
@ -158,7 +175,8 @@ public class ProcessManager {
|
|
|
|
|
|
javaBuilder.append("public class "+javaName+" extends RouteBuilder {\n");
|
|
|
javaBuilder.append("public void configure() throws Exception {\n");
|
|
|
for (String nodeName : nodeNameArray) {
|
|
|
for (int i=0;i<nodeNameArray.length;i++) {
|
|
|
String nodeName = nodeNameArray[i];
|
|
|
JsonNode node = nodeMap.get(nodeName);
|
|
|
String type = node.get("type").asText();
|
|
|
String value = node.get("value").asText();
|
|
@ -171,6 +189,27 @@ public class ProcessManager {
|
|
|
} else {
|
|
|
if (type.equals("processor")) {
|
|
|
javaBuilder.append("\n.process(\"new "+name+"())");
|
|
|
} else if (type.equals("judgement")) {
|
|
|
String correctNodeName = value.split(",")[1];
|
|
|
value = value.split(",")[0];
|
|
|
javaBuilder.append("\n.when("+value+")");
|
|
|
String nodeName1 = nodeNameArray[++i];
|
|
|
JsonNode node1 = nodeMap.get(nodeName1);
|
|
|
String nodeName2 = nodeNameArray[++i];
|
|
|
JsonNode node2 = nodeMap.get(nodeName2);
|
|
|
String firstValue = node1.get("value").asText();
|
|
|
String secondValue = node2.get("value").asText();
|
|
|
if (!correctNodeName.equals(nodeName1)) {
|
|
|
secondValue = node1.get("value").asText();
|
|
|
firstValue = node2.get("value").asText();
|
|
|
}
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
|
javaBuilder.append(firstValue + "\")");
|
|
|
javaBuilder.append(".otherwise()");
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
|
javaBuilder.append(secondValue + "\")");
|
|
|
} else {
|
|
|
javaBuilder.append("\n.setHeader(Exchange.HTTP_METHOD, constant(\"POST\"))");
|
|
|
javaBuilder.append("\n.to(\"");
|
|
@ -181,27 +220,26 @@ public class ProcessManager {
|
|
|
javaBuilder.append("\n}\n}");
|
|
|
|
|
|
System.out.println(javaBuilder.toString());
|
|
|
String packageFilePath = System.getProperty("user.dir");
|
|
|
|
|
|
String filePath = packageFilePath + "/" + javaName + ".java";
|
|
|
File file = new File(filePath);
|
|
|
|
|
|
FileWriter fw = new FileWriter(file);
|
|
|
fw.write(javaBuilder.toString());
|
|
|
fw.flush();
|
|
|
fw.close();//这里只是产生一个JAVA文件,简单的IO操作
|
|
|
|
|
|
//upload to mongo
|
|
|
String dbName = "upload";
|
|
|
String newFileName;
|
|
|
try {
|
|
|
newFileName = GridFSUtil.uploadFile(filePath, file.getName(), null);
|
|
|
if (!StringUtil.isEmpty(newFileName)) {
|
|
|
return newFileName;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// String packageFilePath = System.getProperty("user.dir");
|
|
|
//
|
|
|
// String filePath = packageFilePath + "/" + javaName + ".java";
|
|
|
// File file = new File(filePath);
|
|
|
//
|
|
|
// FileWriter fw = new FileWriter(file);
|
|
|
// fw.write(javaBuilder.toString());
|
|
|
// fw.flush();
|
|
|
// fw.close();//这里只是产生一个JAVA文件,简单的IO操作
|
|
|
//
|
|
|
// //upload to mongo
|
|
|
// String newFileName;
|
|
|
// try {
|
|
|
// newFileName = GridFSUtil.uploadFile(filePath, file.getName(), null);
|
|
|
// if (!StringUtil.isEmpty(newFileName)) {
|
|
|
// return newFileName;
|
|
|
// }
|
|
|
// } catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
return "";
|
|
|
}
|
|
|
|
|
@ -214,12 +252,10 @@ public class ProcessManager {
|
|
|
}
|
|
|
|
|
|
//首字母转大写
|
|
|
public String toUpperCaseFirstOne(String s)
|
|
|
{
|
|
|
public 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();
|
|
|
}
|
|
|
|
|
|
}
|