|
@ -3,7 +3,6 @@ package com.yihu.hos.system.service;
|
|
|
import com.yihu.hos.common.constants.ContextAttributes;
|
|
|
import com.yihu.hos.config.BeanConfig;
|
|
|
import com.yihu.hos.core.datatype.ClassFileUtil;
|
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
|
import com.yihu.hos.core.file.FileUtil;
|
|
|
import com.yihu.hos.interceptor.LocalContext;
|
|
|
import com.yihu.hos.services.ServiceFlowEventService;
|
|
@ -19,6 +18,7 @@ import com.yihu.hos.web.framework.model.DictItem;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import com.yihu.hos.web.framework.model.bo.ServiceFlow;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -51,6 +51,8 @@ public class FlowManager {
|
|
|
private FlowClassDao flowClassDao;
|
|
|
@Resource(name = FlowTempDao.BEAN_ID)
|
|
|
private FlowTempDao flowTempDao;
|
|
|
@Value("${hos.filesystem.url}")
|
|
|
private String fsUrl;
|
|
|
|
|
|
/**
|
|
|
* 生成Route流程的java文件
|
|
@ -61,11 +63,13 @@ public class FlowManager {
|
|
|
* @param newCron cron表达式
|
|
|
* @return
|
|
|
*/
|
|
|
public String genRouteJavaFile(String routeId, String className, String tempFilePath, String newCron) {
|
|
|
public String genRouteJavaFile(String jobId,String routeId, String className, String tempFilePath, String newCron) {
|
|
|
try {
|
|
|
//TODO 临时文件夹
|
|
|
String newFileName = className + routeId + ".java";
|
|
|
String newFilePath = "/temp/" + newFileName;
|
|
|
byte[] content = ClassFileUtil.down(tempFilePath);
|
|
|
String newFilePath = "D:/temp/" + newFileName;
|
|
|
String uploadUrl = fsUrl + "/" + tempFilePath;
|
|
|
byte[] content = ClassFileUtil.down(uploadUrl);
|
|
|
if (content == null) {
|
|
|
return null;
|
|
|
}
|
|
@ -82,9 +86,11 @@ public class FlowManager {
|
|
|
}
|
|
|
//修改routeId;模板规则 routeId("routeId")
|
|
|
text = text.replace("routeId(\"routeId\")", "routeId(\"" + routeId + "\")");
|
|
|
//修改jobId;模板规则 "{\"jobId\": \"jobId\"}"
|
|
|
text = text.replace("{\\\"jobId\\\": \\\"jobId\\\"}", "{\\\"jobId\\\": \\\""+ jobId +"\\\"}");
|
|
|
boolean succ = FileUtil.writeFile(newFilePath, text, "UTF-8");
|
|
|
if (succ) {
|
|
|
newFileName = ClassFileUtil.uploadFile(beanConfig.getFsUrl(), new File(newFilePath + newFileName), newFileName);
|
|
|
newFileName = ClassFileUtil.uploadFile(beanConfig.getFsUrl(), new File(newFilePath), newFileName);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
@ -109,9 +115,10 @@ public class FlowManager {
|
|
|
public String genProcessorJavaFile(String jobId, String routeId, String tempFilePath, String className) {
|
|
|
try {
|
|
|
String newFileName = className + routeId + ".java";
|
|
|
|
|
|
String newFilePath = "/temp/" + className;
|
|
|
byte[] content = ClassFileUtil.down(tempFilePath);
|
|
|
//TODO 临时文件夹设置
|
|
|
String newFilePath = "D:/temp/" + newFileName;
|
|
|
String uploadUrl = fsUrl + "/" + tempFilePath;
|
|
|
byte[] content = ClassFileUtil.down(uploadUrl);
|
|
|
if (content == null) {
|
|
|
return null;
|
|
|
}
|
|
@ -121,7 +128,7 @@ public class FlowManager {
|
|
|
boolean succ = FileUtil.writeFile(newFilePath, text, "UTF-8");
|
|
|
//TODO 上传到GridFS
|
|
|
if (succ) {
|
|
|
newFileName = ClassFileUtil.uploadFile(beanConfig.getFsUrl(), new File(newFilePath + newFileName), newFileName);
|
|
|
newFileName = ClassFileUtil.uploadFile(beanConfig.getFsUrl(), new File(newFilePath), newFileName);
|
|
|
return newFileName;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@ -437,16 +444,17 @@ public class FlowManager {
|
|
|
public Integer genCamelFile(String jobId, Integer flowTempId, String newCron) throws Exception {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
//发送生成processor文件的消息
|
|
|
Integer newFlowId = sendAddProcessor(jobId, flowTempId, timestamp);
|
|
|
Integer newFlowId = sendAddProcessor(jobId, flowTempId, timestamp, newCron);
|
|
|
if (newFlowId != null) {
|
|
|
//发送生成route文件的消息
|
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron);
|
|
|
if (newFlowId != null) {
|
|
|
return newFlowId;
|
|
|
} else {
|
|
|
System.out.println("生成route文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
// newFlowId = sendAddRoute(flowTempId, newFlowId, newCron);
|
|
|
// if (newFlowId != null) {
|
|
|
// return newFlowId;
|
|
|
// } else {
|
|
|
// System.out.println("生成route文件失败");
|
|
|
// return null;
|
|
|
// }
|
|
|
return newFlowId;
|
|
|
} else {
|
|
|
System.out.println("生成processor文件失败");
|
|
|
return null;
|
|
@ -496,7 +504,7 @@ public class FlowManager {
|
|
|
}
|
|
|
|
|
|
//生成新的route文件
|
|
|
String newPath = genRouteJavaFile(flow.getCode(), flowTemp.getClassName(), flowTemp.getClassPath(), newCron);
|
|
|
String newPath = genRouteJavaFile(jobId,flow.getCode(), flowTemp.getClassName(), flowTemp.getClassPath(), newCron);
|
|
|
serviceFlow.setRouteCode(flow.getCode());
|
|
|
serviceFlow.setFlowType(ServiceFlowConstant.JAVA);
|
|
|
ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
|
|
@ -532,7 +540,7 @@ public class FlowManager {
|
|
|
}
|
|
|
|
|
|
//新增processor记录
|
|
|
String newPath = genRouteJavaFile(newFlow.getCode(), flowTemp.getClassName(), flowTemp.getClassPath(), newCron);
|
|
|
String newPath = genRouteJavaFile("" ,newFlow.getCode(), flowTemp.getClassName(), flowTemp.getClassPath(), newCron);
|
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
|
newFlowClass.setClassName(flowTemp.getClassName() + newFlow.getCode());
|
|
@ -620,9 +628,9 @@ public class FlowManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer sendAddProcessor(String jobId, Integer flowId, Long timestamp) throws Exception {
|
|
|
public Integer sendAddProcessor(String jobId, Integer flowId, Long timestamp, String newCron) throws Exception {
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
|
|
|
List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTempByFlowId(flowId);
|
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
@ -640,9 +648,11 @@ public class FlowManager {
|
|
|
ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
|
|
|
|
|
|
//新增processor记录
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
serviceFlow.setRouteCode(newFlow.getCode());
|
|
|
serviceFlow.setFlowType(ServiceFlowConstant.JAVA);
|
|
|
for (SystemServiceFlowTemp process : flowTempProces) {
|
|
|
StringBuilder proPath = new StringBuilder();
|
|
|
|
|
|
if (process.getPackageName() != null) {
|
|
|
//生成“/"分割的包名
|
|
|
String packagePath[] = process.getPackageName().split("\\.");
|
|
@ -651,37 +661,44 @@ public class FlowManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
String newPath = genProcessorJavaFile(jobId, newFlow.getCode(), process.getClassPath(), process.getClassName());
|
|
|
|
|
|
SystemServiceFlowClass processClass = new SystemServiceFlowClass();
|
|
|
processClass.setPackageName(process.getPackageName());
|
|
|
processClass.setClassName(process.getClassName());
|
|
|
processClass.setClassPath(processClass.getClassPath());
|
|
|
processClass.setFlowId(newFlow.getId());
|
|
|
processClass.setType(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
|
|
|
processClass.setType(process.getType());
|
|
|
processClass.setIsUpdate("1");
|
|
|
|
|
|
if (newPath != null) {
|
|
|
//发送消息
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
serviceFlow.setRouteCode(newFlow.getCode());
|
|
|
serviceFlow.setFlowType(ServiceFlowConstant.CLASS);
|
|
|
ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
|
|
|
handleFile.setRouteCode(newFlow.getCode());
|
|
|
handleFile.setFileType(ServiceFlowConstant.JAVA);
|
|
|
handleFile.setPackageName(processClass.getPackageName());
|
|
|
//发送消息
|
|
|
ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
|
|
|
handleFile.setRouteCode(newFlow.getCode());
|
|
|
handleFile.setFileType(ServiceFlowConstant.JAVA);
|
|
|
handleFile.setPackageName(processClass.getPackageName());
|
|
|
handleFile.setUsage(processClass.getType());
|
|
|
|
|
|
String newPath = null;
|
|
|
if (ServiceFlowConstant.FLOW_TYPE_PROCESSOR.equals(process.getType())) {
|
|
|
newPath = genProcessorJavaFile(jobId, newFlow.getCode(), process.getClassPath(), process.getClassName());
|
|
|
handleFile.setClassName(processClass.getClassName());
|
|
|
} else {
|
|
|
newPath = genRouteJavaFile(jobId,newFlow.getCode(), process.getClassName(), process.getClassPath(), newCron);
|
|
|
handleFile.setClassName(processClass.getClassName() + newFlow.getCode());
|
|
|
}
|
|
|
|
|
|
if (newPath != null) {
|
|
|
handleFile.setFilePath(newPath);
|
|
|
handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
|
|
|
handleFiles.add(handleFile);
|
|
|
serviceFlow.setHandleFiles(handleFiles);
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
processClass.setClassPath(newPath);
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
} else {
|
|
|
System.out.println("生成processor的java文件过程出错");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
serviceFlow.setHandleFiles(handleFiles);
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|