|  | @ -3,6 +3,7 @@ package com.yihu.hos.system.service;
 | 
	
		
			
				|  |  | import com.yihu.hos.config.MongoConfig;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.datatype.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.encrypt.DES;
 | 
	
		
			
				|  |  | import com.yihu.hos.core.file.FileUtil;
 | 
	
		
			
				|  |  | import com.yihu.hos.services.ServiceFlowEventService;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.FlowClassDao;
 | 
	
		
			
				|  |  | import com.yihu.hos.system.dao.FlowDao;
 | 
	
	
		
			
				|  | @ -451,9 +452,15 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  |             newFlowClass.setType(ServiceFlowConstant.FLOW_TYPE_ROUTE);
 | 
	
		
			
				|  |  |             flowClassDao.saveEntity(newFlowClass);
 | 
	
		
			
				|  |  |             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;
 | 
	
	
		
			
				|  | @ -499,15 +506,88 @@ public class FlowManager implements IFlowManage {
 | 
	
		
			
				|  |  |                 processClass.setFlowId(newFlow.getId());
 | 
	
		
			
				|  |  |                 processClass.setType(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
 | 
	
		
			
				|  |  |                 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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 |