|
@ -53,12 +53,80 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
@Autowired
|
|
|
private MongoConfig mongoConfig;
|
|
|
|
|
|
/**
|
|
|
* 生成Route流程的java文件
|
|
|
*
|
|
|
* @param routeId 流程Id
|
|
|
* @param className 模板类名
|
|
|
* @param tempFilePath 模板文件路径
|
|
|
* @param newCron cron表达式
|
|
|
* @return
|
|
|
*/
|
|
|
public static String genRouteJavaFile(String routeId, String className, String tempFilePath, String newCron) {
|
|
|
try {
|
|
|
String newFileName = className + routeId + ".java";
|
|
|
String newFilePath = "/temp/" + newFileName;
|
|
|
String text = GridFSUtil.readFile("upload", tempFilePath);
|
|
|
if (text.contains("?cron=")) {
|
|
|
String oldStr = text.substring(text.indexOf("?cron=") + 6);
|
|
|
String cron = oldStr.substring(0, oldStr.indexOf("\""));
|
|
|
text = text.replace(cron, newCron);
|
|
|
}
|
|
|
//修改java类名
|
|
|
if (text.contains(className)) {
|
|
|
text = text.replace(className, className + routeId);//新类名规则=旧类名+routeId
|
|
|
}
|
|
|
//修改routeId;模板规则 routeId("routeId")
|
|
|
text = text.replace("routeId(\"routeId\")", "routeId(\"" + routeId + "\")");
|
|
|
boolean succ = FileUtil.writeFile(newFilePath, text, "UTF-8");
|
|
|
//TODO 上传到GridFS
|
|
|
if (succ) {
|
|
|
newFileName = GridFSUtil.uploadFile("upload", newFilePath, newFileName);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return newFileName;
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("修改Route的java文件操作出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成processor的java文件
|
|
|
*
|
|
|
* @param routeId 流程Code
|
|
|
* @param tempFilePath 模板文件名
|
|
|
* @param className 模板类名
|
|
|
* @return
|
|
|
*/
|
|
|
public static String genProcessorJavaFile(String routeId, String tempFilePath, String className) {
|
|
|
try {
|
|
|
String newFileName = className + routeId + ".java";
|
|
|
|
|
|
String newFilePath = "/temp/" + className;
|
|
|
String text = GridFSUtil.readFile("upload", tempFilePath);
|
|
|
boolean succ = FileUtil.writeFile(newFilePath, text, "UTF-8");
|
|
|
//TODO 上传到GridFS
|
|
|
if (succ) {
|
|
|
newFileName = GridFSUtil.uploadFile("upload", newFilePath, newFileName);
|
|
|
return newFileName;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("生成processor的java文件操作出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result getFlowList(Map<String, Object> params) throws Exception {
|
|
|
return flowDao.getFlowList(params);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @return List<ServiceFlow> 返回所有可运行流程
|
|
|
* @throws Exception ...
|
|
@ -142,6 +210,8 @@ public class FlowManager implements IFlowManage {
|
|
|
return Result.success("保存成功");
|
|
|
}
|
|
|
|
|
|
/* =================================== flowClass 部分================================================*/
|
|
|
|
|
|
@Transactional
|
|
|
public Result updateFlow(SystemServiceFlow obj) throws Exception {
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, obj.getId());
|
|
@ -216,10 +286,10 @@ public class FlowManager implements IFlowManage {
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
|
|
|
List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
|
|
|
List<SystemServiceFlowClass> processorFlowClassList = new ArrayList<>();
|
|
|
if (ServiceFlowConstant.JAVA.equals(flow.getFileType())){
|
|
|
if (ServiceFlowConstant.JAVA.equals(flow.getFileType())) {
|
|
|
flowTempDao.deleteFlowTempByFlowId(id);
|
|
|
} else {
|
|
|
for (SystemServiceFlowClass flowClass:flowClassList){
|
|
|
for (SystemServiceFlowClass flowClass : flowClassList) {
|
|
|
flowClassDao.deleteEntity(flowClass);
|
|
|
flowClass.setIsUpdate("1");
|
|
|
//发送消息到MQ对列
|
|
@ -239,9 +309,6 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
}
|
|
|
|
|
|
/* =================================== flowClass 部分================================================*/
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public Result getFlowClassList(Map<String, Object> params) throws Exception {
|
|
|
return null;
|
|
@ -318,33 +385,42 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
/**
|
|
|
* 发送MQ消息-更新路由
|
|
|
*
|
|
|
* @param flowCode 服务流程Code标识
|
|
|
* @param flowClass
|
|
|
* @param operate
|
|
|
*/
|
|
|
public void sendUpdateMessage(String flowCode,SystemServiceFlowClass flowClass,String operate){
|
|
|
//发送消息到MQ对列
|
|
|
if ("1".equals(flowClass.getIsUpdate()) && ServiceFlowConstant.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
|
|
|
//route
|
|
|
switch (operate){
|
|
|
case "add" : serviceFlowEventService.routeDefineAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
|
case "delete" : serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName()); break;
|
|
|
case "update" : serviceFlowEventService.routeDefineChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
|
default : break;
|
|
|
}
|
|
|
} else if ("1".equals(flowClass.getIsUpdate()) && ServiceFlowConstant.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
|
|
|
//processor
|
|
|
switch (operate){
|
|
|
case "add" : serviceFlowEventService.processorAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
|
case "delete" : serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName()); break;
|
|
|
case "update" : serviceFlowEventService.processorDataChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
|
default : break;
|
|
|
public void sendUpdateMessage(String flowCode, SystemServiceFlowClass flowClass, String operate) {
|
|
|
if ("1".equals(flowClass.getIsUpdate())) {
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
serviceFlow.setRouteCode(flowCode);
|
|
|
serviceFlow.setFlowType(ServiceFlowConstant.CLASS);
|
|
|
ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
|
|
|
handleFile.setRouteCode(flowCode);
|
|
|
handleFile.setFileType(ServiceFlowConstant.CLASS);
|
|
|
handleFile.setPackageName(flowClass.getPackageName());
|
|
|
handleFile.setClassName(flowClass.getClassName());
|
|
|
handleFile.setFilePath(flowClass.getClassPath());
|
|
|
handleFile.setUsage(flowClass.getType());
|
|
|
serviceFlow.addHandleFile(handleFile);
|
|
|
|
|
|
switch (operate) {
|
|
|
case "add":
|
|
|
case "update":
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
break;
|
|
|
case "delete":
|
|
|
serviceFlowEventService.serviceFlowModifiedReduce(serviceFlow);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取流程列表
|
|
|
*
|
|
|
* @param type 流程的文件类型
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@ -367,9 +443,9 @@ public class FlowManager implements IFlowManage {
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 发送消息到broker,生成camel相关文件
|
|
|
*
|
|
|
* @param flowTempId
|
|
|
* @param newCron
|
|
|
* @throws Exception
|
|
@ -378,16 +454,16 @@ public class FlowManager implements IFlowManage {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
//发送生成processor文件的消息
|
|
|
Integer newFlowId = sendAddProcessor(flowTempId, timestamp);
|
|
|
if (newFlowId != null){
|
|
|
if (newFlowId != null) {
|
|
|
//发送生成route文件的消息
|
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron);
|
|
|
if (newFlowId !=null){
|
|
|
if (newFlowId != null) {
|
|
|
return newFlowId;
|
|
|
}else {
|
|
|
} else {
|
|
|
System.out.println("生成route文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
}else {
|
|
|
} else {
|
|
|
System.out.println("生成processor文件失败");
|
|
|
return null;
|
|
|
}
|
|
@ -395,35 +471,46 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
/**
|
|
|
* 修改任务,修改camel相关文件
|
|
|
* @param flowId 流程ID
|
|
|
* @param newCron 新cron
|
|
|
*
|
|
|
* @param flowId 流程ID
|
|
|
* @param newCron 新cron
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
|
|
|
public Integer updateCamelFile(Integer flowTempId, Integer flowId, String newCron) throws Exception {
|
|
|
/* 修改route文件无需重新生成flowClass记录,文件名根据className+routeId 生成;*/
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowClass> flowClassRouters = flowClassDao.getFlowClass(flowId, ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class,flowId);
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, flowId);
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowTempRouters.isEmpty()){
|
|
|
SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
|
|
|
StringBuilder basePath = new StringBuilder();;
|
|
|
if (flowTemp.getPackageName()!=null){
|
|
|
if (!flowTempRouters.isEmpty()) {
|
|
|
SystemServiceFlowTemp flowTemp = flowTempRouters.get(0);
|
|
|
StringBuilder basePath = new StringBuilder();
|
|
|
;
|
|
|
if (flowTemp.getPackageName() != null) {
|
|
|
String packagePath[] = flowTemp.getPackageName().split("\\.");
|
|
|
for (int i=0;i<packagePath.length;i++){
|
|
|
for (int i = 0; i < packagePath.length; i++) {
|
|
|
basePath.append(packagePath[i]).append("/");
|
|
|
}
|
|
|
}
|
|
|
serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
|
|
|
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
serviceFlow.setRouteCode(flow.getCode());
|
|
|
serviceFlow.setFlowType(ServiceFlowConstant.JAVA);
|
|
|
ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
|
|
|
handleFile.setRouteCode(flow.getCode());
|
|
|
handleFile.setFileType(ServiceFlowConstant.JAVA);
|
|
|
handleFile.setPackageName(flowTemp.getClassPath());
|
|
|
handleFile.setClassName(flowTemp.getClassName());
|
|
|
handleFile.setFilePath(basePath.toString());
|
|
|
handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
|
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
return flowId;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ********************* 发送消息方式生成文件 ********************************/
|
|
|
public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron) throws Exception {
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
@ -453,11 +540,22 @@ public class FlowManager implements IFlowManage {
|
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
|
newFlowClass.setIsUpdate("1");
|
|
|
//生成新的route文件
|
|
|
String newFileName = genRouteJavaFile(newFlow.getCode(),flowTemp.getClassName(),deName,newCron);
|
|
|
if (newFileName!=null){
|
|
|
serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(), flowTemp.getClassName(), deName,newCron);
|
|
|
String newFileName = genRouteJavaFile(newFlow.getCode(), flowTemp.getClassName(), deName, newCron);
|
|
|
if (newFileName != 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.CLASS);
|
|
|
handleFile.setPackageName(flowTemp.getPackageName());
|
|
|
handleFile.setClassName(flowTemp.getClassName());
|
|
|
handleFile.setFilePath(newFileName);
|
|
|
handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_ROUTE);
|
|
|
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
return newFlow.getId();
|
|
|
}else {
|
|
|
} else {
|
|
|
System.out.println("生成route的java文件过程出错");
|
|
|
return null;
|
|
|
}
|
|
@ -507,12 +605,23 @@ public class FlowManager implements IFlowManage {
|
|
|
processClass.setType(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
|
|
|
processClass.setIsUpdate("1");
|
|
|
//生成新的java文件
|
|
|
String newFileName = genProcessorJavaFile(newFlow.getCode(),deName,processClass.getClassName());
|
|
|
if (newFileName!=null){
|
|
|
String newFileName = genProcessorJavaFile(newFlow.getCode(), deName, processClass.getClassName());
|
|
|
if (newFileName != null) {
|
|
|
//发送消息
|
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), deName);
|
|
|
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.CLASS);
|
|
|
handleFile.setPackageName(processClass.getPackageName());
|
|
|
handleFile.setClassName(processClass.getClassName());
|
|
|
handleFile.setFilePath(newFileName);
|
|
|
handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
|
|
|
|
|
|
serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
}else {
|
|
|
} else {
|
|
|
System.out.println("生成processor的java文件过程出错");
|
|
|
return null;
|
|
|
}
|
|
@ -524,72 +633,4 @@ public class FlowManager implements IFlowManage {
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成Route流程的java文件
|
|
|
* @param routeId 流程Id
|
|
|
* @param className 模板类名
|
|
|
* @param tempFilePath 模板文件路径
|
|
|
* @param newCron cron表达式
|
|
|
* @return
|
|
|
*/
|
|
|
public static String genRouteJavaFile(String routeId,String className,String tempFilePath,String newCron) {
|
|
|
try {
|
|
|
String newFileName = className+routeId+".java";
|
|
|
String newFilePath = "/temp/"+newFileName;
|
|
|
String text = GridFSUtil.readFile("upload",tempFilePath);
|
|
|
if (text.contains("?cron=")) {
|
|
|
String oldStr = text.substring(text.indexOf("?cron=") + 6);
|
|
|
String cron = oldStr.substring(0, oldStr.indexOf("\""));
|
|
|
text = text.replace(cron,newCron);
|
|
|
}
|
|
|
//修改java类名
|
|
|
if (text.contains(className)) {
|
|
|
text = text.replace(className, className+routeId);//新类名规则=旧类名+routeId
|
|
|
}
|
|
|
//修改routeId;模板规则 routeId("routeId")
|
|
|
text = text.replace("routeId(\"routeId\")", "routeId(\"" + routeId + "\")");
|
|
|
boolean succ = FileUtil.writeFile(newFilePath,text,"UTF-8");
|
|
|
//TODO 上传到GridFS
|
|
|
if (succ){
|
|
|
newFileName = GridFSUtil.uploadFile("upload", newFilePath, newFileName);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return newFileName;
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("修改Route的java文件操作出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生成processor的java文件
|
|
|
* @param routeId 流程Code
|
|
|
* @param tempFilePath 模板文件名
|
|
|
* @param className 模板类名
|
|
|
* @return
|
|
|
*/
|
|
|
public static String genProcessorJavaFile(String routeId ,String tempFilePath, String className) {
|
|
|
try {
|
|
|
String newFileName = className+routeId+".java";
|
|
|
|
|
|
String newFilePath = "/temp/"+className;
|
|
|
String text = GridFSUtil.readFile("upload",tempFilePath);
|
|
|
boolean succ = FileUtil.writeFile(newFilePath,text,"UTF-8");
|
|
|
//TODO 上传到GridFS
|
|
|
if (succ){
|
|
|
newFileName = GridFSUtil.uploadFile("upload", newFilePath, newFileName);
|
|
|
return newFileName;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("生成processor的java文件操作出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|