|
@ -4,15 +4,15 @@ import com.yihu.hos.common.constants.Constants;
|
|
import com.yihu.hos.config.MongoConfig;
|
|
import com.yihu.hos.config.MongoConfig;
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
|
|
import com.yihu.hos.core.file.FileUtil;
|
|
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.FlowDao;
|
|
import com.yihu.hos.system.dao.FlowTempDao;
|
|
import com.yihu.hos.system.dao.FlowTempDao;
|
|
import com.yihu.hos.system.dao.intf.IFlowClassDao;
|
|
|
|
import com.yihu.hos.system.dao.intf.IFlowDao;
|
|
|
|
import com.yihu.hos.system.dao.intf.IFlowTempDao;
|
|
|
|
import com.yihu.hos.system.model.SystemServiceFlow;
|
|
import com.yihu.hos.system.model.SystemServiceFlow;
|
|
import com.yihu.hos.system.model.SystemServiceFlowClass;
|
|
import com.yihu.hos.system.model.SystemServiceFlowClass;
|
|
import com.yihu.hos.system.model.SystemServiceFlowTemp;
|
|
import com.yihu.hos.system.model.SystemServiceFlowTemp;
|
|
|
|
import com.yihu.hos.system.model.bo.ServiceFlow;
|
|
import com.yihu.hos.system.service.intf.IFlowManage;
|
|
import com.yihu.hos.system.service.intf.IFlowManage;
|
|
import com.yihu.hos.web.framework.model.ActionResult;
|
|
import com.yihu.hos.web.framework.model.ActionResult;
|
|
import com.yihu.hos.web.framework.model.DictItem;
|
|
import com.yihu.hos.web.framework.model.DictItem;
|
|
@ -41,17 +41,16 @@ import java.util.Map;
|
|
public class FlowManager implements IFlowManage {
|
|
public class FlowManager implements IFlowManage {
|
|
|
|
|
|
public static final String BEAN_ID = "flowManager";
|
|
public static final String BEAN_ID = "flowManager";
|
|
|
|
@Autowired
|
|
|
|
ServiceFlowEventService serviceFlowEventService;
|
|
|
|
|
|
@Resource(name = "flowDao")
|
|
@Resource(name = "flowDao")
|
|
private IFlowDao flowDao;
|
|
|
|
|
|
|
|
|
|
private FlowDao flowDao;
|
|
@Resource(name = FlowClassDao.BEAN_ID)
|
|
@Resource(name = FlowClassDao.BEAN_ID)
|
|
private IFlowClassDao flowClassDao;
|
|
|
|
|
|
|
|
|
|
private FlowClassDao flowClassDao;
|
|
@Resource(name = FlowTempDao.BEAN_ID)
|
|
@Resource(name = FlowTempDao.BEAN_ID)
|
|
private IFlowTempDao flowTempDao;
|
|
|
|
@Autowired
|
|
|
|
ServiceFlowEventService serviceFlowEventService;
|
|
|
|
|
|
private FlowTempDao flowTempDao;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private MongoConfig mongoConfig;
|
|
private MongoConfig mongoConfig;
|
|
@Override
|
|
@Override
|
|
@ -59,6 +58,61 @@ public class FlowManager implements IFlowManage {
|
|
return flowDao.getFlowList(params);
|
|
return flowDao.getFlowList(params);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return List<ServiceFlow> 返回所有可运行流程
|
|
|
|
* @throws Exception ...
|
|
|
|
*/
|
|
|
|
public List<ServiceFlow> getServiceFlowList() throws Exception {
|
|
|
|
List<ServiceFlow> serviceFlowList = new ArrayList<>();
|
|
|
|
List<SystemServiceFlow> classFlowList = flowDao.getFlowList(Constants.CLASS);
|
|
|
|
for (SystemServiceFlow systemServiceFlow : classFlowList) {
|
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
|
serviceFlow.setRouteCode(systemServiceFlow.getCode());
|
|
|
|
serviceFlow.setFlowType(systemServiceFlow.getFileType());
|
|
|
|
|
|
|
|
List<SystemServiceFlowClass> classList = flowClassDao.getFlowClassByFlowId(systemServiceFlow.getId());
|
|
|
|
ArrayList<ServiceFlow.HandleFile> handleFileList = new ArrayList<>();
|
|
|
|
for (SystemServiceFlowClass flowClass : classList) {
|
|
|
|
ServiceFlow.HandleFile handleFile = serviceFlow.new HandleFile();
|
|
|
|
handleFile.setFileType(Constants.CLASS);
|
|
|
|
handleFile.setClassName(flowClass.getClassName());
|
|
|
|
handleFile.setPackageName(flowClass.getPackageName());
|
|
|
|
handleFile.setFilePath(flowClass.getClassPath());
|
|
|
|
handleFile.setUsage(flowClass.getType());
|
|
|
|
|
|
|
|
handleFileList.add(handleFile);
|
|
|
|
}
|
|
|
|
serviceFlow.setHandleFiles(handleFileList);
|
|
|
|
|
|
|
|
serviceFlowList.add(serviceFlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<SystemServiceFlow> javaFlowList = flowDao.getFlowList(Constants.JAVA);
|
|
|
|
for (SystemServiceFlow systemServiceFlow : javaFlowList) {
|
|
|
|
ServiceFlow serviceFlow = new ServiceFlow();
|
|
|
|
serviceFlow.setRouteCode(systemServiceFlow.getCode());
|
|
|
|
|
|
|
|
List<SystemServiceFlowTemp> tempList = flowTempDao.getFlowTempByFlowId(systemServiceFlow.getId());
|
|
|
|
ArrayList<ServiceFlow.HandleFile> handleFileList = new ArrayList<>();
|
|
|
|
for (SystemServiceFlowTemp flowTemp : tempList) {
|
|
|
|
ServiceFlow.HandleFile handleFile = serviceFlow.new HandleFile();
|
|
|
|
handleFile.setFileType(Constants.JAVA);
|
|
|
|
handleFile.setClassName(flowTemp.getClassName());
|
|
|
|
handleFile.setPackageName(flowTemp.getPackageName());
|
|
|
|
handleFile.setFilePath(flowTemp.getClassPath());
|
|
|
|
handleFile.setUsage(flowTemp.getType());
|
|
|
|
|
|
|
|
handleFileList.add(handleFile);
|
|
|
|
}
|
|
|
|
serviceFlow.setHandleFiles(handleFileList);
|
|
|
|
|
|
|
|
serviceFlowList.add(serviceFlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return serviceFlowList;
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public SystemServiceFlow getFlowById(Integer id) throws Exception {
|
|
public SystemServiceFlow getFlowById(Integer id) throws Exception {
|
|
return flowDao.getEntity(SystemServiceFlow.class, id);
|
|
return flowDao.getEntity(SystemServiceFlow.class, id);
|
|
@ -69,17 +123,17 @@ public class FlowManager implements IFlowManage {
|
|
obj.setCreateDate(new Date());
|
|
obj.setCreateDate(new Date());
|
|
flowDao.saveEntity(obj);
|
|
flowDao.saveEntity(obj);
|
|
|
|
|
|
if (Constants.CLASS.equals(obj.getFileType())){
|
|
|
|
|
|
if (Constants.CLASS.equals(obj.getFileType())) {
|
|
List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
|
|
List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
|
|
for (SystemServiceFlowClass flowClass:flowClassList){
|
|
|
|
|
|
for (SystemServiceFlowClass flowClass : flowClassList) {
|
|
flowClass.setFlowId(obj.getId());
|
|
flowClass.setFlowId(obj.getId());
|
|
flowDao.saveEntity(flowClass);
|
|
flowDao.saveEntity(flowClass);
|
|
//发送消息到MQ对列
|
|
//发送消息到MQ对列
|
|
sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
}
|
|
}
|
|
}else if (Constants.JAVA.equals(obj.getFileType())){
|
|
|
|
|
|
} else if (Constants.JAVA.equals(obj.getFileType())) {
|
|
List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
|
|
List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
|
|
for (SystemServiceFlowTemp flowTemp:flowTempList){
|
|
|
|
|
|
for (SystemServiceFlowTemp flowTemp : flowTempList) {
|
|
flowTemp.setFlowId(obj.getId());
|
|
flowTemp.setFlowId(obj.getId());
|
|
flowDao.saveEntity(flowTemp);
|
|
flowDao.saveEntity(flowTemp);
|
|
}
|
|
}
|
|
@ -99,21 +153,21 @@ public class FlowManager implements IFlowManage {
|
|
flow.setFileType(obj.getFileType());
|
|
flow.setFileType(obj.getFileType());
|
|
|
|
|
|
|
|
|
|
if (Constants.JAVA.equals(flow.getFileType())){
|
|
|
|
|
|
if (Constants.JAVA.equals(flow.getFileType())) {
|
|
List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
|
|
List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
|
|
boolean succ = flowTempDao.deleteFlowTempByFlowId(obj.getId());
|
|
boolean succ = flowTempDao.deleteFlowTempByFlowId(obj.getId());
|
|
if (succ){
|
|
|
|
for (SystemServiceFlowTemp flowTemp:flowTempList){
|
|
|
|
|
|
if (succ) {
|
|
|
|
for (SystemServiceFlowTemp flowTemp : flowTempList) {
|
|
flowTempDao.saveEntity(flowTemp);
|
|
flowTempDao.saveEntity(flowTemp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else if (Constants.CLASS.equals(flow.getFileType())){
|
|
|
|
|
|
} else if (Constants.CLASS.equals(flow.getFileType())) {
|
|
List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
|
|
List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
|
|
List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
|
|
List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
|
|
SystemServiceFlowClass flowClassRoute = null;
|
|
SystemServiceFlowClass flowClassRoute = null;
|
|
String oper = "";
|
|
String oper = "";
|
|
for (SystemServiceFlowClass flowClass:flowClassList){
|
|
|
|
if (flowClass.getId()!=null) {
|
|
|
|
|
|
for (SystemServiceFlowClass flowClass : flowClassList) {
|
|
|
|
if (flowClass.getId() != null) {
|
|
classIds.remove(flowClass.getId());
|
|
classIds.remove(flowClass.getId());
|
|
flowClassDao.updateEntity(flowClass);
|
|
flowClassDao.updateEntity(flowClass);
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
@ -122,7 +176,7 @@ public class FlowManager implements IFlowManage {
|
|
flowClassRoute = flowClass;
|
|
flowClassRoute = flowClass;
|
|
oper = Constants.FLOW_OP_UPDATE;
|
|
oper = Constants.FLOW_OP_UPDATE;
|
|
}
|
|
}
|
|
}else {
|
|
|
|
|
|
} else {
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
flowClassDao.saveEntity(flowClass);
|
|
flowClassDao.saveEntity(flowClass);
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
|
|
@ -133,8 +187,8 @@ public class FlowManager implements IFlowManage {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//删除判断
|
|
//删除判断
|
|
if (classIds !=null && classIds.size()>0){
|
|
|
|
for (Integer id:classIds){
|
|
|
|
|
|
if (classIds != null && classIds.size() > 0) {
|
|
|
|
for (Integer id : classIds) {
|
|
SystemServiceFlowClass flowClass = getFlowClassById(id);
|
|
SystemServiceFlowClass flowClass = getFlowClassById(id);
|
|
flowClassDao.deleteEntity(flowClass);
|
|
flowClassDao.deleteEntity(flowClass);
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
|
|
@ -154,7 +208,6 @@ public class FlowManager implements IFlowManage {
|
|
flowDao.updateEntity(flow);
|
|
flowDao.updateEntity(flow);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success("更新成功");
|
|
return Result.success("更新成功");
|
|
}
|
|
}
|
|
|
|
|
|
@ -216,7 +269,7 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
public boolean deleteFlowClassByFlowId(Integer flowId) {
|
|
public boolean deleteFlowClassByFlowId(Integer flowId) {
|
|
boolean succ =flowClassDao.deleteFlowClassByFlowId(flowId);
|
|
|
|
|
|
boolean succ = flowClassDao.deleteFlowClassByFlowId(flowId);
|
|
return succ;
|
|
return succ;
|
|
}
|
|
}
|
|
|
|
|
|
@ -297,13 +350,12 @@ public class FlowManager implements IFlowManage {
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public ActionResult getFlowList(String type) throws Exception {
|
|
|
|
|
|
public ActionResult getFlowList(String type) throws Exception {
|
|
List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
|
|
List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
|
|
ActionResult re = new ActionResult();
|
|
ActionResult re = new ActionResult();
|
|
if(flowList!=null&&flowList.size()>0)
|
|
|
|
{
|
|
|
|
|
|
if (flowList != null && flowList.size() > 0) {
|
|
List<DictItem> dictList = new ArrayList<>();
|
|
List<DictItem> dictList = new ArrayList<>();
|
|
for(SystemServiceFlow item:flowList){
|
|
|
|
|
|
for (SystemServiceFlow item : flowList) {
|
|
DictItem dict = new DictItem();
|
|
DictItem dict = new DictItem();
|
|
dict.setCode(item.getId().toString());
|
|
dict.setCode(item.getId().toString());
|
|
dict.setValue(item.getName());
|
|
dict.setValue(item.getName());
|
|
@ -400,9 +452,15 @@ public class FlowManager implements IFlowManage {
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
flowClassDao.saveEntity(newFlowClass);
|
|
newFlowClass.setIsUpdate("1");
|
|
newFlowClass.setIsUpdate("1");
|
|
serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(), flowTemp.getClassName(), deName,newCron);
|
|
|
|
|
|
|
|
return newFlow.getId();
|
|
|
|
|
|
//生成新的route文件
|
|
|
|
String newFileName = genRouteJavaFile(newFlow.getCode(),flowTemp.getClassName(),deName,newCron);
|
|
|
|
if (newFileName!=null){
|
|
|
|
serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(), flowTemp.getClassName(), deName,newCron);
|
|
|
|
return newFlow.getId();
|
|
|
|
}else {
|
|
|
|
System.out.println("生成route的java文件过程出错");
|
|
|
|
return null;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return null;
|
|
return null;
|
|
@ -448,15 +506,88 @@ 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");
|
|
//发送消息
|
|
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), deName);
|
|
|
|
|
|
//生成新的java文件
|
|
|
|
String newFileName = genProcessorJavaFile(newFlow.getCode(),deName,processClass.getClassName());
|
|
|
|
if (newFileName!=null){
|
|
|
|
//发送消息
|
|
|
|
serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), deName);
|
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
|
}else {
|
|
|
|
System.out.println("生成processor的java文件过程出错");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newFlow.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
flowClassDao.saveEntity(processClass);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成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);
|
|
}
|
|
}
|
|
return newFlow.getId();
|
|
|
|
|
|
//修改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;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|