|
@ -1,7 +1,9 @@
|
|
|
package com.yihu.hos.system.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.hos.common.constants.Constants;
|
|
|
import com.yihu.hos.core.file.FileUtil;
|
|
|
import com.yihu.hos.core.http.HTTPResponse;
|
|
|
import com.yihu.hos.core.http.HttpClientKit;
|
|
|
import com.yihu.hos.services.ServiceFlowEventService;
|
|
|
import com.yihu.hos.system.dao.FlowClassDao;
|
|
@ -109,30 +111,47 @@ public class FlowManager implements IFlowManage {
|
|
|
}else if (Constants.CLASS.equals(flow.getFileType())){
|
|
|
List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
|
|
|
List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
|
|
|
SystemServiceFlowClass flowClassRoute = null;
|
|
|
String oper = "";
|
|
|
for (SystemServiceFlowClass flowClass:flowClassList){
|
|
|
if (flowClass.getId()!=null) {
|
|
|
classIds.remove(flowClass.getId());
|
|
|
flowClassDao.updateEntity(flowClass);
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
} else {
|
|
|
flowClassRoute = flowClass;
|
|
|
oper = Constants.FLOW_OP_UPDATE;
|
|
|
}
|
|
|
}else {
|
|
|
flowClassDao.saveEntity(flowClass);
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
|
flowClassDao.saveEntity(flowClass);
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
|
} else {
|
|
|
flowClassRoute = flowClass;
|
|
|
oper = Constants.FLOW_OP_ADD;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//删除判断
|
|
|
if (classIds !=null && classIds.size()>0){
|
|
|
for (Integer id:classIds){
|
|
|
SystemServiceFlowClass flowClass = getFlowClassById(id);
|
|
|
flowClassDao.deleteEntity(flowClass);
|
|
|
sendDeleteMessage(flow.getCode(), flowClass);
|
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
|
|
|
} else {
|
|
|
flowClassRoute = flowClass;
|
|
|
flowClassRoute.setIsUpdate("1");
|
|
|
oper = Constants.FLOW_OP_DELETE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (flowClassRoute != null) {
|
|
|
sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flowDao.updateEntity(flow);
|
|
|
|
|
|
|
|
@ -144,11 +163,23 @@ public class FlowManager implements IFlowManage {
|
|
|
public Result deleteFlow(Integer id) throws Exception {
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
|
|
|
List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
|
|
|
SystemServiceFlowClass flowClassRoute = null;
|
|
|
String oper = "";
|
|
|
for (SystemServiceFlowClass flowClass:flowClassList){
|
|
|
flowClassDao.deleteEntity(flowClass);
|
|
|
//发送消息到MQ对列
|
|
|
sendDeleteMessage(flow.getCode(), flowClass);
|
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
|
|
|
} else {
|
|
|
flowClassRoute = flowClass;
|
|
|
flowClassRoute.setIsUpdate("1");
|
|
|
oper = Constants.FLOW_OP_DELETE;
|
|
|
}
|
|
|
}
|
|
|
if (flowClassRoute != null) {
|
|
|
sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
|
|
|
}
|
|
|
|
|
|
boolean succ = flowTempDao.deleteFlowTempByFlowId(id);
|
|
|
flowDao.deleteEntity(flow);
|
|
|
return Result.success("删除成功");
|
|
@ -169,7 +200,7 @@ public class FlowManager implements IFlowManage {
|
|
|
}
|
|
|
|
|
|
public SystemServiceFlowClass getFlowClassById(Integer id) throws Exception {
|
|
|
return flowClassDao.getEntity(SystemServiceFlowClass.class,id);
|
|
|
return flowClassDao.getEntity(SystemServiceFlowClass.class, id);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@ -236,7 +267,7 @@ public class FlowManager implements IFlowManage {
|
|
|
case "update" : serviceFlowEventService.routeDefineChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
|
default : break;
|
|
|
}
|
|
|
} else if ( "1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
|
|
|
} else if ("1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
|
|
|
//processor
|
|
|
switch (operate){
|
|
|
case "add" : serviceFlowEventService.processorAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
|
|
@ -247,23 +278,6 @@ public class FlowManager implements IFlowManage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 发送MQ消息-删除路由
|
|
|
* @param flowCode 服务流程Code标识
|
|
|
* @param flowClass
|
|
|
*/
|
|
|
public void sendDeleteMessage(String flowCode,SystemServiceFlowClass flowClass){
|
|
|
//发送消息到MQ对列
|
|
|
if ( Constants.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
|
|
|
//route
|
|
|
serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName());
|
|
|
} else if (Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
|
|
|
//processor
|
|
|
serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取流程列表
|
|
|
* @param type 流程的文件类型
|
|
@ -296,22 +310,25 @@ public class FlowManager implements IFlowManage {
|
|
|
* @param newCron
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public boolean genCamelFile(Integer flowId, String newCron) throws Exception {
|
|
|
public Integer genCamelFile(Integer flowId, String newCron) throws Exception {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
|
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowClassRouters.isEmpty()){
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
Map<String,String> params = null;
|
|
|
SystemServiceFlowTemp flowTemp =flowClassRouters.get(0);
|
|
|
String newClassName = flowTemp.getClassName()+timestamp;
|
|
|
String newClassPath = flowTemp.getClassPath().replaceAll(flowTemp.getClassName()+".java",newClassName+".class");
|
|
|
params.put("pageName", flowTemp.getPackageName());
|
|
|
params.put("oldClassName", flowTemp.getClassName());
|
|
|
params.put("newClassName",newClassName);//原文件名加当前时间戳
|
|
|
params.put("newCron",newCron);
|
|
|
String result = HttpClientKit.post(genCamelUrl, params).getBody();
|
|
|
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("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//成功生成文件后,添加flow和flowclass记录
|
|
|
//生成新流程
|
|
@ -324,31 +341,141 @@ public class FlowManager implements IFlowManage {
|
|
|
newFlow.setFileType(Constants.CLASS);
|
|
|
flowDao.saveEntity(newFlow);
|
|
|
|
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
|
newFlowClass.setClassName(newClassName);
|
|
|
newFlowClass.setClassPath(newClassPath);
|
|
|
newFlowClass.setFlowId(newFlow.getId());
|
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
|
|
|
|
|
|
|
//新增processor记录
|
|
|
for (SystemServiceFlowTemp process:flowClassProces){
|
|
|
// String newProcessName = process.getClassName()+timestamp;
|
|
|
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("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
params = new HashMap<>();
|
|
|
params.put("type",Constants.FLOW_TYPE_PROCESSOR);
|
|
|
params.put("filePath", process.getClassPath());
|
|
|
params.put("packageName", proPath.toString());
|
|
|
params.put("newClassName",process.getClassName());//原文件名加当前时间戳
|
|
|
params.put("oldClassName", process.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){
|
|
|
newProcessPath = body.get("message").toString();
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
System.out.println(response.getBody());
|
|
|
SystemServiceFlowClass processClass = new SystemServiceFlowClass();
|
|
|
processClass.setPackageName(process.getPackageName());
|
|
|
processClass.setClassName(process.getClassName());
|
|
|
processClass.setClassPath(process.getClassPath());
|
|
|
processClass.setClassPath(newProcessPath);
|
|
|
processClass.setFlowId(newFlow.getId());
|
|
|
processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
|
|
|
|
|
|
// copyProcessor(process.getClassPath(),proPath.toString(),process.getClassName());
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
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);
|
|
|
sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
|
|
|
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
return newFlow.getId();
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改camel相关文件
|
|
|
* @param flowId 流程ID
|
|
|
* @param newCron 新cron
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, Constants.FLOW_TYPE_ROUTE);
|
|
|
List<SystemServiceFlowClass> flowClassRouters = flowClassDao.getFlowClass(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
|
// SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class,flowId);
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
if (!flowTempRouters.isEmpty()){
|
|
|
SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
|
|
|
SystemServiceFlowClass flowClass =flowClassRouters.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("/");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
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文件生成成功,发送消息
|
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
return flowId;
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|