|
@ -2,9 +2,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.config.MongoConfig;
|
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
|
import com.yihu.hos.services.ServiceFlowEventService;
|
|
|
import com.yihu.hos.system.dao.FlowClassDao;
|
|
|
import com.yihu.hos.system.dao.FlowTempDao;
|
|
@ -18,16 +18,18 @@ import com.yihu.hos.system.service.intf.IFlowManage;
|
|
|
import com.yihu.hos.web.framework.model.ActionResult;
|
|
|
import com.yihu.hos.web.framework.model.DictItem;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 系统流程管理业务类
|
|
@ -41,9 +43,6 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
public static final String BEAN_ID = "flowManager";
|
|
|
|
|
|
@Value("${esb.genCamelUrl}")
|
|
|
private String genCamelUrl;
|
|
|
|
|
|
@Resource(name = "flowDao")
|
|
|
private IFlowDao flowDao;
|
|
|
|
|
@ -54,7 +53,8 @@ public class FlowManager implements IFlowManage {
|
|
|
private IFlowTempDao flowTempDao;
|
|
|
@Autowired
|
|
|
ServiceFlowEventService serviceFlowEventService;
|
|
|
|
|
|
@Autowired
|
|
|
private MongoConfig mongoConfig;
|
|
|
@Override
|
|
|
public Result getFlowList(Map<String, Object> params) throws Exception {
|
|
|
return flowDao.getFlowList(params);
|
|
@ -236,20 +236,32 @@ public class FlowManager implements IFlowManage {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public String uploadFile(MultipartFile file, String baseSavePath) {
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
boolean succ = false;
|
|
|
public Result uploadFile(CommonsMultipartFile file) {
|
|
|
String dbName = "upload";
|
|
|
String newFileName;
|
|
|
try {
|
|
|
succ = FileUtil.writeFile(baseSavePath + File.separator + fileName, file.getBytes(), "utf-8");
|
|
|
if (succ){
|
|
|
return fileName;
|
|
|
newFileName = GridFSUtil.uploadFile(mongoConfig.mongoClient().getDatabase(dbName), file);
|
|
|
if (!StringUtil.isEmpty(newFileName)) {
|
|
|
return Result.success(DES.encrypt(newFileName, DES.COMMON_PASSWORD));
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
return Result.error("上传失败");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result readFile(OutputStream os, String fileName) {
|
|
|
String dbName = "upload";
|
|
|
try {
|
|
|
fileName = DES.decrypt(fileName, DES.COMMON_PASSWORD);
|
|
|
GridFSUtil.readFile(mongoConfig.mongoClient().getDatabase(dbName), os, fileName);
|
|
|
return Result.success("获取成功");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return Result.error("获取失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -315,7 +327,7 @@ public class FlowManager implements IFlowManage {
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
|
|
|
if (newFlowId != null){
|
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
|
|
|
newFlowId = sendAddRoute(flowTempId, newFlowId, newCron);
|
|
|
if (newFlowId !=null){
|
|
|
return newFlowId;
|
|
|
}else {
|
|
@ -328,141 +340,6 @@ 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相关文件
|
|
|
* @param flowId 流程ID
|
|
@ -472,8 +349,6 @@ public class FlowManager implements IFlowManage {
|
|
|
*/
|
|
|
@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);
|
|
@ -507,13 +382,12 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
|
|
|
/* ********************* 发送消息方式生成文件 ********************************/
|
|
|
public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron, Long timestamp) throws Exception {
|
|
|
public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron) 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();
|
|
|
;
|
|
@ -564,7 +438,7 @@ public class FlowManager implements IFlowManage {
|
|
|
|
|
|
//新增processor记录
|
|
|
for (SystemServiceFlowTemp process : flowTempProces) {
|
|
|
String newProcessPath = null;
|
|
|
String newProcessPath;
|
|
|
StringBuilder proPath = new StringBuilder();
|
|
|
;
|
|
|
if (process.getPackageName() != null) {
|