|
@ -307,12 +307,84 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
/**
|
|
|
* TODO 调用broker接口生成camel相关文件
|
|
|
* @param flowId
|
|
|
* @param flowTempId
|
|
|
* @param newCron
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Integer genCamelFile(Integer flowId, String newCron) throws Exception {
|
|
|
public Integer genCamelFile(Integer flowTempId, String newCron) throws Exception {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
|
|
|
if (newFlowId != null){
|
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
|
|
|
if (newFlowId !=null){
|
|
|
return newFlowId;
|
|
|
}else {
|
|
|
System.out.println("生成route文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
}else {
|
|
|
System.out.println("生成processor文件失败");
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer addRouteFile(Integer tempId,Integer flowId, String newCron ,Long timestamp) throws Exception {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
|
|
|
SystemServiceFlow newFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowTempRouters.isEmpty()){
|
|
|
Map<String,String> params = null;
|
|
|
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++){
|
|
|
basePath.append(packagePath[i]).append("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//新增processor记录
|
|
|
String newClassName = flowTemp.getClassName()+timestamp;
|
|
|
String newRoutePath =null;
|
|
|
params = new HashMap<>();
|
|
|
params.put("routeId", newFlow.getCode());
|
|
|
params.put("type",Constants.FLOW_TYPE_ROUTE);
|
|
|
params.put("filePath", flowTemp.getClassPath());
|
|
|
params.put("packageName", basePath.toString());
|
|
|
params.put("oldClassName", flowTemp.getClassName());
|
|
|
params.put("newClassName",newClassName);//原文件名加当前时间戳
|
|
|
params.put("newCron",newCron);
|
|
|
HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
|
|
|
if (response.getStatusCode()==200 ){
|
|
|
Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
|
|
|
boolean succ = (boolean) body.get("successFlg");
|
|
|
if (succ){
|
|
|
newRoutePath = body.get("message").toString();
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
System.out.println(response.getBody());
|
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
|
newFlowClass.setClassName(newClassName);
|
|
|
newFlowClass.setClassPath(newRoutePath);
|
|
|
newFlowClass.setFlowId(newFlow.getId());
|
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
|
newFlowClass.setIsUpdate("1");
|
|
|
sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Integer addProcessorFile(Integer flowId, String newCron,Long timestamp) throws Exception {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
|
|
@ -330,7 +402,6 @@ public class FlowManager implements IFlowManage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//成功生成文件后,添加flow和flowclass记录
|
|
|
//生成新流程
|
|
|
SystemServiceFlow newFlow = new SystemServiceFlow();
|
|
@ -342,10 +413,7 @@ public class FlowManager implements IFlowManage {
|
|
|
newFlow.setFileType(Constants.CLASS);
|
|
|
flowDao.saveEntity(newFlow);
|
|
|
|
|
|
|
|
|
|
|
|
//新增processor记录
|
|
|
int sum = 0;
|
|
|
for (SystemServiceFlowTemp process:flowClassProces){
|
|
|
|
|
|
// String newProcessName = process.getClassName()+timestamp;
|
|
@ -359,6 +427,7 @@ public class FlowManager implements IFlowManage {
|
|
|
}
|
|
|
|
|
|
params = new HashMap<>();
|
|
|
params.put("routeId", newFlow.getCode());
|
|
|
params.put("type",Constants.FLOW_TYPE_PROCESSOR);
|
|
|
params.put("filePath", process.getClassPath());
|
|
|
params.put("packageName", proPath.toString());
|
|
@ -381,8 +450,6 @@ public class FlowManager implements IFlowManage {
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
processClass.setIsUpdate("1");
|
|
|
sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
|
|
|
sum++;
|
|
|
// copyProcessor(process.getClassPath(),proPath.toString(),process.getClassName());
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
@ -390,46 +457,6 @@ public class FlowManager implements IFlowManage {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (sum == flowClassProces.size()){
|
|
|
String newClassName = flowTemp.getClassName()+timestamp;
|
|
|
String newRoutePath =null;
|
|
|
params = new HashMap<>();
|
|
|
params.put("type",Constants.FLOW_TYPE_ROUTE);
|
|
|
params.put("filePath", flowTemp.getClassPath());
|
|
|
params.put("packageName", basePath.toString());
|
|
|
params.put("oldClassName", flowTemp.getClassName());
|
|
|
params.put("newClassName",newClassName);//原文件名加当前时间戳
|
|
|
params.put("newCron",newCron);
|
|
|
HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
|
|
|
if (response.getStatusCode()==200 ){
|
|
|
Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
|
|
|
boolean succ = (boolean) body.get("successFlg");
|
|
|
if (succ){
|
|
|
newRoutePath = body.get("message").toString();
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
System.out.println(response.getBody());
|
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
|
newFlowClass.setClassName(newClassName);
|
|
|
newFlowClass.setClassPath(newRoutePath);
|
|
|
newFlowClass.setFlowId(newFlow.getId());
|
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
|
newFlowClass.setIsUpdate("1");
|
|
|
sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
System.out.println("生成processoer过程失败");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|
|
@ -463,35 +490,108 @@ public class FlowManager implements IFlowManage {
|
|
|
basePath.append(packagePath[i]).append("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("type",Constants.FLOW_TYPE_ROUTE);
|
|
|
params.put("filePath", flowTemp.getClassPath());
|
|
|
params.put("packageName", basePath.toString());
|
|
|
params.put("oldClassName", flowTemp.getClassName());
|
|
|
params.put("newClassName", flowClass.getClassName());//原文件名加当前时间戳
|
|
|
params.put("newCron",newCron);
|
|
|
HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
|
|
|
if (response.getStatusCode()==200 ){
|
|
|
Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
|
|
|
boolean succ = (boolean) body.get("successFlg");
|
|
|
if (succ){
|
|
|
//route文件生成成功,发送消息
|
|
|
flowClass.setIsUpdate("1");
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
return flowId;
|
|
|
}else {
|
|
|
return null;
|
|
|
// flowClass.setIsUpdate("1");
|
|
|
// sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
|
|
|
|
|
|
return flowId;
|
|
|
|
|
|
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ********************* 发送消息方式生成文件 ********************************/
|
|
|
public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron, Long timestamp) throws Exception {
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
|
|
|
SystemServiceFlow newFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowTempRouters.isEmpty()) {
|
|
|
Map<String, String> params = null;
|
|
|
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++) {
|
|
|
basePath.append(packagePath[i]).append("/");
|
|
|
}
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
|
|
|
//新增processor记录
|
|
|
String newClassName = flowTemp.getClassName() + newFlow.getCode();
|
|
|
String newRoutePath = flowTemp.getClassPath().replace(".java",".class");
|
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
|
newFlowClass.setClassName(newClassName);
|
|
|
newFlowClass.setClassPath(newRoutePath);
|
|
|
newFlowClass.setFlowId(newFlow.getId());
|
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
|
newFlowClass.setIsUpdate("1");
|
|
|
serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
|
|
|
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Integer sendAddProcessore(Integer flowId, Long timestamp) throws Exception {
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
|
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowTempRouters.isEmpty()) {
|
|
|
|
|
|
//成功生成文件后,添加flow和flowclass记录
|
|
|
//生成新流程
|
|
|
SystemServiceFlow newFlow = new SystemServiceFlow();
|
|
|
newFlow.setName(oldFlow.getName() + timestamp);
|
|
|
newFlow.setCode(oldFlow.getCode() + timestamp);
|
|
|
newFlow.setChart(oldFlow.getChart());
|
|
|
newFlow.setValid(1);
|
|
|
newFlow.setCreateDate(new Date());
|
|
|
newFlow.setFileType(Constants.CLASS);
|
|
|
flowDao.saveEntity(newFlow);
|
|
|
|
|
|
//新增processor记录
|
|
|
for (SystemServiceFlowTemp process : flowTempProces) {
|
|
|
String newProcessPath = null;
|
|
|
StringBuilder proPath = new StringBuilder();
|
|
|
;
|
|
|
if (process.getPackageName() != null) {
|
|
|
String packagePath[] = process.getPackageName().split("\\.");
|
|
|
for (int i = 0; i < packagePath.length; i++) {
|
|
|
proPath.append(packagePath[i]).append("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
newProcessPath = process.getClassPath().replace(".java", ".class");
|
|
|
SystemServiceFlowClass processClass = new SystemServiceFlowClass();
|
|
|
processClass.setPackageName(process.getPackageName());
|
|
|
processClass.setClassName(process.getClassName());
|
|
|
processClass.setClassPath(newProcessPath);
|
|
|
processClass.setFlowId(newFlow.getId());
|
|
|
processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
|
|
|
processClass.setIsUpdate("1");
|
|
|
// sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
|
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), process.getClassPath());
|
|
|
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
|
|
|
}
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|