FlowManager.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. package com.yihu.hos.system.service;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.hos.common.constants.Constants;
  4. import com.yihu.hos.core.file.FileUtil;
  5. import com.yihu.hos.core.http.HTTPResponse;
  6. import com.yihu.hos.core.http.HttpClientKit;
  7. import com.yihu.hos.services.ServiceFlowEventService;
  8. import com.yihu.hos.system.dao.FlowClassDao;
  9. import com.yihu.hos.system.dao.FlowTempDao;
  10. import com.yihu.hos.system.dao.intf.IFlowClassDao;
  11. import com.yihu.hos.system.dao.intf.IFlowDao;
  12. import com.yihu.hos.system.dao.intf.IFlowTempDao;
  13. import com.yihu.hos.system.model.SystemServiceFlow;
  14. import com.yihu.hos.system.model.SystemServiceFlowClass;
  15. import com.yihu.hos.system.model.SystemServiceFlowTemp;
  16. import com.yihu.hos.system.service.intf.IFlowManage;
  17. import com.yihu.hos.web.framework.model.ActionResult;
  18. import com.yihu.hos.web.framework.model.DictItem;
  19. import com.yihu.hos.web.framework.model.Result;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import javax.annotation.Resource;
  26. import java.io.File;
  27. import java.io.IOException;
  28. import java.util.*;
  29. /**
  30. * 系统流程管理业务类
  31. *
  32. * @author HZY
  33. * @vsrsion 1.0
  34. * Created at 2016/8/19.
  35. */
  36. @Service("flowManager")
  37. public class FlowManager implements IFlowManage {
  38. public static final String BEAN_ID = "flowManager";
  39. @Value("${esb.genCamelUrl}")
  40. private String genCamelUrl;
  41. @Resource(name = "flowDao")
  42. private IFlowDao flowDao;
  43. @Resource(name = FlowClassDao.BEAN_ID)
  44. private IFlowClassDao flowClassDao;
  45. @Resource(name = FlowTempDao.BEAN_ID)
  46. private IFlowTempDao flowTempDao;
  47. @Autowired
  48. ServiceFlowEventService serviceFlowEventService;
  49. @Override
  50. public Result getFlowList(Map<String, Object> params) throws Exception {
  51. return flowDao.getFlowList(params);
  52. }
  53. @Override
  54. public SystemServiceFlow getFlowById(Integer id) throws Exception {
  55. return flowDao.getEntity(SystemServiceFlow.class, id);
  56. }
  57. @Transactional
  58. public Result addFlow(SystemServiceFlow obj) throws Exception {
  59. obj.setCreateDate(new Date());
  60. flowDao.saveEntity(obj);
  61. if (Constants.CLASS.equals(obj.getFileType())){
  62. List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
  63. for (SystemServiceFlowClass flowClass:flowClassList){
  64. flowClass.setFlowId(obj.getId());
  65. flowDao.saveEntity(flowClass);
  66. //发送消息到MQ对列
  67. sendUpdateMessage(obj.getCode(), flowClass, Constants.FLOW_OP_ADD);
  68. }
  69. }else if (Constants.JAVA.equals(obj.getFileType())){
  70. List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
  71. for (SystemServiceFlowTemp flowTemp:flowTempList){
  72. flowTemp.setFlowId(obj.getId());
  73. flowDao.saveEntity(flowTemp);
  74. }
  75. }
  76. return Result.success("保存成功");
  77. }
  78. @Transactional
  79. public Result updateFlow(SystemServiceFlow obj) throws Exception {
  80. SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, obj.getId());
  81. flow.setCode(obj.getCode());
  82. flow.setName(obj.getName());
  83. flow.setPath(obj.getPath());
  84. flow.setChart(obj.getChart());
  85. flow.setValid(obj.getValid());
  86. flow.setFileType(obj.getFileType());
  87. if (Constants.JAVA.equals(flow.getFileType())){
  88. List<SystemServiceFlowTemp> flowTempList = obj.getFlowTempArray();
  89. boolean succ = flowTempDao.deleteFlowTempByFlowId(obj.getId());
  90. if (succ){
  91. for (SystemServiceFlowTemp flowTemp:flowTempList){
  92. flowTempDao.saveEntity(flowTemp);
  93. }
  94. }
  95. }else if (Constants.CLASS.equals(flow.getFileType())){
  96. List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
  97. List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
  98. SystemServiceFlowClass flowClassRoute = null;
  99. String oper = "";
  100. for (SystemServiceFlowClass flowClass:flowClassList){
  101. if (flowClass.getId()!=null) {
  102. classIds.remove(flowClass.getId());
  103. flowClassDao.updateEntity(flowClass);
  104. if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
  105. sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
  106. } else {
  107. flowClassRoute = flowClass;
  108. oper = Constants.FLOW_OP_UPDATE;
  109. }
  110. }else {
  111. if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
  112. flowClassDao.saveEntity(flowClass);
  113. sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
  114. } else {
  115. flowClassRoute = flowClass;
  116. oper = Constants.FLOW_OP_ADD;
  117. }
  118. }
  119. }
  120. //删除判断
  121. if (classIds !=null && classIds.size()>0){
  122. for (Integer id:classIds){
  123. SystemServiceFlowClass flowClass = getFlowClassById(id);
  124. flowClassDao.deleteEntity(flowClass);
  125. if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
  126. sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
  127. } else {
  128. flowClassRoute = flowClass;
  129. flowClassRoute.setIsUpdate("1");
  130. oper = Constants.FLOW_OP_DELETE;
  131. }
  132. }
  133. }
  134. if (flowClassRoute != null) {
  135. sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
  136. }
  137. }
  138. flowDao.updateEntity(flow);
  139. return Result.success("更新成功");
  140. }
  141. @Transactional
  142. public Result deleteFlow(Integer id) throws Exception {
  143. SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
  144. List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
  145. SystemServiceFlowClass flowClassRoute = null;
  146. String oper = "";
  147. for (SystemServiceFlowClass flowClass:flowClassList){
  148. flowClassDao.deleteEntity(flowClass);
  149. //发送消息到MQ对列
  150. if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
  151. sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
  152. } else {
  153. flowClassRoute = flowClass;
  154. flowClassRoute.setIsUpdate("1");
  155. oper = Constants.FLOW_OP_DELETE;
  156. }
  157. }
  158. if (flowClassRoute != null) {
  159. sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
  160. }
  161. if (Constants.JAVA.equals(flow.getFileType())){
  162. flowTempDao.deleteFlowTempByFlowId(id);
  163. }
  164. flowDao.deleteEntity(flow);
  165. return Result.success("删除成功");
  166. }
  167. /* =================================== flowClass 部分================================================*/
  168. @Override
  169. public Result getFlowClassList(Map<String, Object> params) throws Exception {
  170. return null;
  171. }
  172. @Override
  173. public List<SystemServiceFlowClass> getFlowClassByFlowId(Integer flowId) throws Exception {
  174. return flowClassDao.getFlowClassByFlowId(flowId);
  175. }
  176. public SystemServiceFlowClass getFlowClassById(Integer id) throws Exception {
  177. return flowClassDao.getEntity(SystemServiceFlowClass.class, id);
  178. }
  179. @Transactional
  180. public Result addFlowClass(SystemServiceFlowClass obj) throws Exception {
  181. flowDao.saveEntity(obj);
  182. return Result.success("保存成功");
  183. }
  184. @Transactional
  185. public Result updateFlowClass(SystemServiceFlowClass obj) throws Exception {
  186. return null;
  187. }
  188. @Transactional
  189. public boolean deleteFlowClassByFlowId(Integer flowId) {
  190. boolean succ =flowClassDao.deleteFlowClassByFlowId(flowId);
  191. return succ;
  192. }
  193. @Override
  194. public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception {
  195. return flowTempDao.getFlowTempByFlowId(id);
  196. }
  197. //TODO
  198. @Override
  199. public boolean genFlewByflowTempId(Integer flowTempId) throws Exception {
  200. SystemServiceFlow flow = getFlowById(flowTempId);
  201. //生成新的route类
  202. //添加新processor记录
  203. return false;
  204. }
  205. @Override
  206. public String uploadFile(MultipartFile file, String baseSavePath) {
  207. String fileName = file.getOriginalFilename();
  208. boolean succ = false;
  209. try {
  210. succ = FileUtil.writeFile(baseSavePath + File.separator + fileName, file.getBytes(), "utf-8");
  211. if (succ){
  212. return fileName;
  213. }
  214. } catch (IOException e) {
  215. e.printStackTrace();
  216. }
  217. return null;
  218. }
  219. /**
  220. * 发送MQ消息-更新路由
  221. * @param flowCode 服务流程Code标识
  222. * @param flowClass
  223. * @param operate
  224. */
  225. public void sendUpdateMessage(String flowCode,SystemServiceFlowClass flowClass,String operate){
  226. //发送消息到MQ对列
  227. if ("1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
  228. //route
  229. switch (operate){
  230. case "add" : serviceFlowEventService.routeDefineAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
  231. case "delete" : serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName()); break;
  232. case "update" : serviceFlowEventService.routeDefineChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
  233. default : break;
  234. }
  235. } else if ("1".equals(flowClass.getIsUpdate()) && Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
  236. //processor
  237. switch (operate){
  238. case "add" : serviceFlowEventService.processorAdded(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
  239. case "delete" : serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
  240. case "update" : serviceFlowEventService.processorDataChanged(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath()); break;
  241. default : break;
  242. }
  243. }
  244. }
  245. /**
  246. * 获取流程列表
  247. * @param type 流程的文件类型
  248. * @return
  249. * @throws Exception
  250. */
  251. @Override
  252. public ActionResult getFlowList(String type) throws Exception {
  253. List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
  254. ActionResult re = new ActionResult();
  255. if(flowList!=null&&flowList.size()>0)
  256. {
  257. List<DictItem> dictList = new ArrayList<>();
  258. for(SystemServiceFlow item:flowList){
  259. DictItem dict = new DictItem();
  260. dict.setCode(item.getId().toString());
  261. dict.setValue(item.getName());
  262. dict.setExtend("");
  263. dictList.add(dict);
  264. }
  265. re.setData(dictList);
  266. }
  267. return re;
  268. }
  269. /**
  270. * TODO 调用broker接口生成camel相关文件
  271. * @param flowTempId
  272. * @param newCron
  273. * @throws Exception
  274. */
  275. public Integer genCamelFile(Integer flowTempId, String newCron) throws Exception {
  276. Long timestamp = System.currentTimeMillis();
  277. Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
  278. if (newFlowId != null){
  279. newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
  280. if (newFlowId !=null){
  281. return newFlowId;
  282. }else {
  283. System.out.println("生成route文件失败");
  284. return null;
  285. }
  286. }else {
  287. System.out.println("生成processor文件失败");
  288. return null;
  289. }
  290. }
  291. public Integer addRouteFile(Integer tempId,Integer flowId, String newCron ,Long timestamp) throws Exception {
  292. ObjectMapper objectMapper = new ObjectMapper();
  293. List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
  294. SystemServiceFlow newFlow = getFlowById(flowId);
  295. //route模板文件记录是否存在。不存在就返回。
  296. if (!flowTempRouters.isEmpty()){
  297. Map<String,String> params = null;
  298. SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
  299. StringBuilder basePath = new StringBuilder();;
  300. if (flowTemp.getPackageName()!=null){
  301. String packagePath[] = flowTemp.getPackageName().split("\\.");
  302. for (int i=0;i<packagePath.length;i++){
  303. basePath.append(packagePath[i]).append("/");
  304. }
  305. }
  306. //新增processor记录
  307. String newClassName = flowTemp.getClassName()+timestamp;
  308. String newRoutePath =null;
  309. params = new HashMap<>();
  310. params.put("routeId", newFlow.getCode());
  311. params.put("type",Constants.FLOW_TYPE_ROUTE);
  312. params.put("filePath", flowTemp.getClassPath());
  313. params.put("packageName", basePath.toString());
  314. params.put("oldClassName", flowTemp.getClassName());
  315. params.put("newClassName",newClassName);//原文件名加当前时间戳
  316. params.put("newCron",newCron);
  317. HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
  318. if (response.getStatusCode()==200 ){
  319. Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
  320. boolean succ = (boolean) body.get("successFlg");
  321. if (succ){
  322. newRoutePath = body.get("message").toString();
  323. }else {
  324. return null;
  325. }
  326. System.out.println(response.getBody());
  327. SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
  328. newFlowClass.setPackageName(flowTemp.getPackageName());
  329. newFlowClass.setClassName(newClassName);
  330. newFlowClass.setClassPath(newRoutePath);
  331. newFlowClass.setFlowId(newFlow.getId());
  332. newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
  333. flowClassDao.saveEntity(newFlowClass);
  334. newFlowClass.setIsUpdate("1");
  335. sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
  336. }else {
  337. return null;
  338. }
  339. return newFlow.getId();
  340. }
  341. return null;
  342. }
  343. public Integer addProcessorFile(Integer flowId, String newCron,Long timestamp) throws Exception {
  344. ObjectMapper objectMapper = new ObjectMapper();
  345. List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
  346. List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
  347. SystemServiceFlow oldFlow = getFlowById(flowId);
  348. //route模板文件记录是否存在。不存在就返回。
  349. if (!flowClassRouters.isEmpty()){
  350. Map<String,String> params = null;
  351. SystemServiceFlowTemp flowTemp =flowClassRouters.get(0);
  352. StringBuilder basePath = new StringBuilder();;
  353. if (flowTemp.getPackageName()!=null){
  354. String packagePath[] = flowTemp.getPackageName().split("\\.");
  355. for (int i=0;i<packagePath.length;i++){
  356. basePath.append(packagePath[i]).append("/");
  357. }
  358. }
  359. //成功生成文件后,添加flow和flowclass记录
  360. //生成新流程
  361. SystemServiceFlow newFlow = new SystemServiceFlow();
  362. newFlow.setName(oldFlow.getName()+timestamp);
  363. newFlow.setCode(oldFlow.getCode()+timestamp);
  364. newFlow.setChart(oldFlow.getChart());
  365. newFlow.setValid(1);
  366. newFlow.setCreateDate(new Date());
  367. newFlow.setFileType(Constants.CLASS);
  368. flowDao.saveEntity(newFlow);
  369. //新增processor记录
  370. for (SystemServiceFlowTemp process:flowClassProces){
  371. // String newProcessName = process.getClassName()+timestamp;
  372. String newProcessPath = null;
  373. StringBuilder proPath = new StringBuilder( );;
  374. if (process.getPackageName()!=null){
  375. String packagePath[] = process.getPackageName().split("\\.");
  376. for (int i=0;i<packagePath.length;i++){
  377. proPath.append(packagePath[i]).append("/");
  378. }
  379. }
  380. params = new HashMap<>();
  381. params.put("routeId", newFlow.getCode());
  382. params.put("type",Constants.FLOW_TYPE_PROCESSOR);
  383. params.put("filePath", process.getClassPath());
  384. params.put("packageName", proPath.toString());
  385. params.put("newClassName",process.getClassName());//原文件名加当前时间戳
  386. params.put("oldClassName", process.getClassName());
  387. params.put("newCron",newCron);
  388. HTTPResponse response = HttpClientKit.post(genCamelUrl, params);
  389. if (response.getStatusCode()==200 ){
  390. Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
  391. boolean succ = (boolean) body.get("successFlg");
  392. if (succ){
  393. newProcessPath = body.get("message").toString();
  394. System.out.println(response.getBody());
  395. SystemServiceFlowClass processClass = new SystemServiceFlowClass();
  396. processClass.setPackageName(process.getPackageName());
  397. processClass.setClassName(process.getClassName());
  398. processClass.setClassPath(newProcessPath);
  399. processClass.setFlowId(newFlow.getId());
  400. processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
  401. flowClassDao.saveEntity(processClass);
  402. processClass.setIsUpdate("1");
  403. sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
  404. }else {
  405. return null;
  406. }
  407. }else {
  408. return null;
  409. }
  410. }
  411. return newFlow.getId();
  412. }
  413. return null;
  414. }
  415. /**
  416. * 修改camel相关文件
  417. * @param flowId 流程ID
  418. * @param newCron 新cron
  419. * @return
  420. * @throws Exception
  421. */
  422. @Override
  423. public Integer updateCamelFile(Integer flowTempId,Integer flowId, String newCron) throws Exception {
  424. Long timestamp = System.currentTimeMillis();
  425. ObjectMapper objectMapper = new ObjectMapper();
  426. List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, Constants.FLOW_TYPE_ROUTE);
  427. List<SystemServiceFlowClass> flowClassRouters = flowClassDao.getFlowClass(flowId, Constants.FLOW_TYPE_ROUTE);
  428. // SystemServiceFlow oldFlow = getFlowById(flowId);
  429. SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class,flowId);
  430. //route模板文件记录是否存在。不存在就返回。
  431. if (!flowTempRouters.isEmpty()){
  432. SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
  433. SystemServiceFlowClass flowClass =flowClassRouters.get(0);
  434. StringBuilder basePath = new StringBuilder();;
  435. if (flowTemp.getPackageName()!=null){
  436. String packagePath[] = flowTemp.getPackageName().split("\\.");
  437. for (int i=0;i<packagePath.length;i++){
  438. basePath.append(packagePath[i]).append("/");
  439. }
  440. }
  441. //route文件生成成功,发送消息
  442. // flowClass.setIsUpdate("1");
  443. // sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
  444. serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
  445. return flowId;
  446. // genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
  447. }
  448. return null;
  449. }
  450. /* ********************* 发送消息方式生成文件 ********************************/
  451. public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron, Long timestamp) throws Exception {
  452. List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
  453. SystemServiceFlow newFlow = getFlowById(flowId);
  454. //route模板文件记录是否存在。不存在就返回。
  455. if (!flowTempRouters.isEmpty()) {
  456. Map<String, String> params = null;
  457. SystemServiceFlowTemp flowTemp = flowTempRouters.get(0);
  458. StringBuilder basePath = new StringBuilder();
  459. ;
  460. if (flowTemp.getPackageName() != null) {
  461. String packagePath[] = flowTemp.getPackageName().split("\\.");
  462. for (int i = 0; i < packagePath.length; i++) {
  463. basePath.append(packagePath[i]).append("/");
  464. }
  465. }
  466. //新增processor记录
  467. String newClassName = flowTemp.getClassName() + newFlow.getCode();
  468. String newRoutePath = flowTemp.getClassPath().replace(".java",".class");
  469. SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
  470. newFlowClass.setPackageName(flowTemp.getPackageName());
  471. newFlowClass.setClassName(newClassName);
  472. newFlowClass.setClassPath(newRoutePath);
  473. newFlowClass.setFlowId(newFlow.getId());
  474. newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
  475. flowClassDao.saveEntity(newFlowClass);
  476. newFlowClass.setIsUpdate("1");
  477. serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
  478. return newFlow.getId();
  479. }
  480. return null;
  481. }
  482. public Integer sendAddProcessore(Integer flowId, Long timestamp) throws Exception {
  483. List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
  484. List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
  485. SystemServiceFlow oldFlow = getFlowById(flowId);
  486. //route模板文件记录是否存在。不存在就返回。
  487. if (!flowTempRouters.isEmpty()) {
  488. //成功生成文件后,添加flow和flowclass记录
  489. //生成新流程
  490. SystemServiceFlow newFlow = new SystemServiceFlow();
  491. newFlow.setName(oldFlow.getName() + timestamp);
  492. newFlow.setCode(oldFlow.getCode() + timestamp);
  493. newFlow.setChart(oldFlow.getChart());
  494. newFlow.setValid(1);
  495. newFlow.setCreateDate(new Date());
  496. newFlow.setFileType(Constants.CLASS);
  497. flowDao.saveEntity(newFlow);
  498. //新增processor记录
  499. for (SystemServiceFlowTemp process : flowTempProces) {
  500. String newProcessPath = null;
  501. StringBuilder proPath = new StringBuilder();
  502. ;
  503. if (process.getPackageName() != null) {
  504. String packagePath[] = process.getPackageName().split("\\.");
  505. for (int i = 0; i < packagePath.length; i++) {
  506. proPath.append(packagePath[i]).append("/");
  507. }
  508. }
  509. newProcessPath = process.getClassPath().replace(".java", ".class");
  510. SystemServiceFlowClass processClass = new SystemServiceFlowClass();
  511. processClass.setPackageName(process.getPackageName());
  512. processClass.setClassName(process.getClassName());
  513. processClass.setClassPath(newProcessPath);
  514. processClass.setFlowId(newFlow.getId());
  515. processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
  516. processClass.setIsUpdate("1");
  517. // sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
  518. serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), process.getClassPath());
  519. flowClassDao.saveEntity(processClass);
  520. }
  521. return newFlow.getId();
  522. }
  523. return null;
  524. }
  525. }