|  | @ -2,6 +2,7 @@ package com.yihu.hos.system.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.hos.common.constants.Constants;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.file.FileUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.http.HttpClientKit;
 | 
	
		
			
				|  |  | import com.yihu.hos.services.ServiceFlowEventService;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.FlowClassDao;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.FlowTempDao;
 | 
	
	
		
			
				|  | @ -12,20 +13,19 @@ import com.yihu.hos.system.model.SystemServiceFlow;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.model.SystemServiceFlowClass;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.model.SystemServiceFlowTemp;
 | 
	
		
			
				|  |  | 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.DictionaryResult;
 | 
	
		
			
				|  |  | import com.yihu.hos.web.framework.model.Result;
 | 
	
		
			
				|  |  | 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 javax.annotation.Resource;
 | 
	
		
			
				|  |  | import java.io.File;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 系统流程管理业务类
 | 
	
	
		
			
				|  | @ -39,6 +39,9 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static final String BEAN_ID = "flowManager";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${esb.genCamelUrl}")
 | 
	
		
			
				|  |  |     private String genCamelUrl;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Resource(name = "flowDao")
 | 
	
		
			
				|  |  |     private IFlowDao flowDao;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -191,13 +194,23 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  |         return flowTempDao.getFlowTempByFlowId(id);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //TODO
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     public boolean genFlewByflowTempId(Integer flowTempId) throws Exception {
 | 
	
		
			
				|  |  |         SystemServiceFlow flow = getFlowById(flowTempId);
 | 
	
		
			
				|  |  |         //生成新的route类
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //添加新processor记录
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     public String uploadFile(MultipartFile file, String baseSavePath) {
 | 
	
		
			
				|  |  |         String fileName =  file.getOriginalFilename();
 | 
	
		
			
				|  |  |         boolean succ = false;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             succ = FileUtil.writeFile(baseSavePath +"/"+ fileName, file.getBytes(), "utf-8");
 | 
	
		
			
				|  |  |             succ = FileUtil.writeFile(baseSavePath + File.separator + fileName, file.getBytes(), "utf-8");
 | 
	
		
			
				|  |  |             if (succ){
 | 
	
		
			
				|  |  |                 return  fileName;
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -258,9 +271,9 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     public  DictionaryResult getFlowList(String type) throws Exception {
 | 
	
		
			
				|  |  |     public  ActionResult getFlowList(String type) throws Exception {
 | 
	
		
			
				|  |  |         List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
 | 
	
		
			
				|  |  |         DictionaryResult re = new DictionaryResult("FLOW_LIST");
 | 
	
		
			
				|  |  |         ActionResult re = new ActionResult();
 | 
	
		
			
				|  |  |         if(flowList!=null&&flowList.size()>0)
 | 
	
		
			
				|  |  |         {
 | 
	
		
			
				|  |  |             List<DictItem> dictList = new ArrayList<>();
 | 
	
	
		
			
				|  | @ -271,9 +284,71 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  |                 dict.setExtend("");
 | 
	
		
			
				|  |  |                 dictList.add(dict);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             re.setDetailModelList(dictList);
 | 
	
		
			
				|  |  |             re.setData(dictList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return re;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * TODO 调用broker接口生成camel相关文件
 | 
	
		
			
				|  |  |      * @param flowId
 | 
	
		
			
				|  |  |      * @param newCron
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean genCamelFile(Integer flowId, String newCron) throws Exception {
 | 
	
		
			
				|  |  |         Long timestamp = System.currentTimeMillis();
 | 
	
		
			
				|  |  |         List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
 | 
	
		
			
				|  |  |         List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
 | 
	
		
			
				|  |  |         SystemServiceFlow oldFlow = getFlowById(flowId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (!flowClassRouters.isEmpty()){
 | 
	
		
			
				|  |  |             Map<String,String> params = new HashMap<>();
 | 
	
		
			
				|  |  |             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();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //成功生成文件后,添加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);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             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){
 | 
	
		
			
				|  |  |                 SystemServiceFlowClass processClass = new SystemServiceFlowClass();
 | 
	
		
			
				|  |  |                 processClass.setPackageName(process.getPackageName());
 | 
	
		
			
				|  |  |                 processClass.setClassName(process.getClassName());
 | 
	
		
			
				|  |  |                 processClass.setClassPath(process.getClassPath());
 | 
	
		
			
				|  |  |                 processClass.setFlowId(newFlow.getId());
 | 
	
		
			
				|  |  |                 processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
 | 
	
		
			
				|  |  |                 flowClassDao.saveEntity(processClass);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return true;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |