|
@ -1,10 +1,7 @@
|
|
package com.yihu.hos.system.service;
|
|
package com.yihu.hos.system.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.yihu.hos.common.constants.Constants;
|
|
import com.yihu.hos.common.constants.Constants;
|
|
import com.yihu.hos.core.file.FileUtil;
|
|
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.services.ServiceFlowEventService;
|
|
import com.yihu.hos.system.dao.FlowClassDao;
|
|
import com.yihu.hos.system.dao.FlowClassDao;
|
|
import com.yihu.hos.system.dao.FlowTempDao;
|
|
import com.yihu.hos.system.dao.FlowTempDao;
|
|
@ -27,7 +24,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 系统流程管理业务类
|
|
* 系统流程管理业务类
|
|
@ -306,15 +306,17 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* TODO 调用broker接口生成camel相关文件
|
|
|
|
* @param flowTempId
|
|
|
|
|
|
* 添加任务, 发送消息到broker生成camel相关文件
|
|
|
|
* @param flowTempId 流程模板Id
|
|
* @param newCron
|
|
* @param newCron
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public Integer genCamelFile(Integer flowTempId, String newCron) throws Exception {
|
|
public Integer genCamelFile(Integer flowTempId, String newCron) throws Exception {
|
|
Long timestamp = System.currentTimeMillis();
|
|
Long timestamp = System.currentTimeMillis();
|
|
Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
|
|
|
|
|
|
//发送生成processor文件的消息
|
|
|
|
Integer newFlowId = sendAddProcessor(flowTempId, timestamp);
|
|
if (newFlowId != null){
|
|
if (newFlowId != null){
|
|
|
|
//发送生成route文件的消息
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
|
|
if (newFlowId !=null){
|
|
if (newFlowId !=null){
|
|
return newFlowId;
|
|
return newFlowId;
|
|
@ -328,143 +330,9 @@ public class FlowManager implements IFlowManage {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
|
|
if (!flowClassRouters.isEmpty()){
|
|
|
|
Map<String,String> params = null;
|
|
|
|
SystemServiceFlowTemp flowTemp =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("/");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//成功生成文件后,添加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: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("routeId", newFlow.getCode());
|
|
|
|
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();
|
|
|
|
System.out.println(response.getBody());
|
|
|
|
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);
|
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
|
processClass.setIsUpdate("1");
|
|
|
|
sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
|
|
|
|
}else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newFlow.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 修改camel相关文件
|
|
|
|
|
|
* 修改任务,修改camel相关文件
|
|
* @param flowId 流程ID
|
|
* @param flowId 流程ID
|
|
* @param newCron 新cron
|
|
* @param newCron 新cron
|
|
* @return
|
|
* @return
|
|
@ -472,17 +340,12 @@ public class FlowManager implements IFlowManage {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
|
|
public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
/* 修改route文件无需重新生成flowClass记录,文件名根据className+routeId 生成;*/
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, Constants.FLOW_TYPE_ROUTE);
|
|
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);
|
|
SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class,flowId);
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
if (!flowTempRouters.isEmpty()){
|
|
if (!flowTempRouters.isEmpty()){
|
|
SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
|
|
SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
|
|
SystemServiceFlowClass flowClass =flowClassRouters.get(0);
|
|
|
|
|
|
|
|
StringBuilder basePath = new StringBuilder();;
|
|
StringBuilder basePath = new StringBuilder();;
|
|
if (flowTemp.getPackageName()!=null){
|
|
if (flowTemp.getPackageName()!=null){
|
|
String packagePath[] = flowTemp.getPackageName().split("\\.");
|
|
String packagePath[] = flowTemp.getPackageName().split("\\.");
|
|
@ -490,15 +353,8 @@ public class FlowManager implements IFlowManage {
|
|
basePath.append(packagePath[i]).append("/");
|
|
basePath.append(packagePath[i]).append("/");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//route文件生成成功,发送消息
|
|
|
|
// flowClass.setIsUpdate("1");
|
|
|
|
// sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
|
|
|
|
serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
|
|
serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
|
|
|
|
|
|
return flowId;
|
|
return flowId;
|
|
|
|
|
|
|
|
|
|
// genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return null;
|
|
return null;
|
|
@ -526,7 +382,7 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
//新增processor记录
|
|
//新增processor记录
|
|
String newClassName = flowTemp.getClassName() + newFlow.getCode();
|
|
String newClassName = flowTemp.getClassName() + newFlow.getCode();
|
|
String newRoutePath = flowTemp.getClassPath().replace(".java",".class");
|
|
|
|
|
|
String newRoutePath = flowTemp.getClassPath().replace(".java",".class");//生成后的class应保存的地址
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
newFlowClass.setPackageName(flowTemp.getPackageName());
|
|
newFlowClass.setClassName(newClassName);
|
|
newFlowClass.setClassName(newClassName);
|
|
@ -543,16 +399,14 @@ public class FlowManager implements IFlowManage {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public Integer sendAddProcessore(Integer flowId, Long timestamp) throws Exception {
|
|
|
|
|
|
public Integer sendAddProcessor(Integer flowId, Long timestamp) throws Exception {
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
|
|
List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
|
|
List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
SystemServiceFlow oldFlow = getFlowById(flowId);
|
|
|
|
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
//route模板文件记录是否存在。不存在就返回。
|
|
if (!flowTempRouters.isEmpty()) {
|
|
if (!flowTempRouters.isEmpty()) {
|
|
|
|
|
|
//成功生成文件后,添加flow和flowclass记录
|
|
//成功生成文件后,添加flow和flowclass记录
|
|
//生成新流程
|
|
|
|
SystemServiceFlow newFlow = new SystemServiceFlow();
|
|
SystemServiceFlow newFlow = new SystemServiceFlow();
|
|
newFlow.setName(oldFlow.getName() + timestamp);
|
|
newFlow.setName(oldFlow.getName() + timestamp);
|
|
newFlow.setCode(oldFlow.getCode() + timestamp);
|
|
newFlow.setCode(oldFlow.getCode() + timestamp);
|
|
@ -566,7 +420,7 @@ public class FlowManager implements IFlowManage {
|
|
for (SystemServiceFlowTemp process : flowTempProces) {
|
|
for (SystemServiceFlowTemp process : flowTempProces) {
|
|
String newProcessPath = null;
|
|
String newProcessPath = null;
|
|
StringBuilder proPath = new StringBuilder();
|
|
StringBuilder proPath = new StringBuilder();
|
|
;
|
|
|
|
|
|
//生成“/"分割的包名
|
|
if (process.getPackageName() != null) {
|
|
if (process.getPackageName() != null) {
|
|
String packagePath[] = process.getPackageName().split("\\.");
|
|
String packagePath[] = process.getPackageName().split("\\.");
|
|
for (int i = 0; i < packagePath.length; i++) {
|
|
for (int i = 0; i < packagePath.length; i++) {
|
|
@ -582,9 +436,8 @@ public class FlowManager implements IFlowManage {
|
|
processClass.setFlowId(newFlow.getId());
|
|
processClass.setFlowId(newFlow.getId());
|
|
processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
|
|
processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
|
|
processClass.setIsUpdate("1");
|
|
processClass.setIsUpdate("1");
|
|
// sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
|
|
|
|
|
|
//发送消息
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), process.getClassPath());
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), process.getClassPath());
|
|
|
|
|
|
flowClassDao.saveEntity(processClass);
|
|
flowClassDao.saveEntity(processClass);
|
|
|
|
|
|
}
|
|
}
|