M00002Service.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. package com.miniframe.bisiness.system;
  2. import java.util.*;
  3. import com.miniframe.core.ExecProcessFlow;
  4. import com.miniframe.core.exception.BusinessException;
  5. import com.miniframe.core.ext.UtilTools;
  6. import com.miniframe.generate.business.system.model.M00002BaseModel;
  7. import com.miniframe.model.system.*;
  8. import com.miniframe.model.system.dao.*;
  9. import com.miniframe.ptdj.AllPahtsDFS;
  10. import javax.rmi.CORBA.Util;
  11. /**
  12. * 基础系统,“平台对接预设路径”逻辑处理(重新生成不覆盖)。
  13. */
  14. public class M00002Service extends M00002BaseModel implements ExecProcessFlow {
  15. private static final long serialVersionUID = -7051358269847459502L;
  16. /**
  17. * 基础系统,“平台对接预设路径”业务核心处理
  18. */
  19. public void transExecute() throws Exception {
  20. Integer aid =this.getA_m00002().getAid();
  21. String lname =this.getA_m00002().getLname();
  22. String lnodes =this.getA_m00002().getLnodes();
  23. String personsites=this.getA_m00002().getPersonsites();
  24. // String[] persons = personsites.split(";");
  25. // for (String p:persons) {
  26. // String[] st =p.split(",");
  27. // if(st.length!=3){
  28. // throw new BusinessException("EMB00003");
  29. // }
  30. // }
  31. DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
  32. DAccidentMapper accDao = UtilTools.getBean(DAccidentMapper.class);
  33. DAccident da =accDao.selectByPrimaryKey(aid);
  34. if(da==null){
  35. throw new BusinessException("EB3000002");
  36. }
  37. DMwaySQLBuilder wsb =new DMwaySQLBuilder();
  38. DMwaySQLBuilder.Criteria wsc =wsb.createCriteria();
  39. wsc.andAidEqualTo(aid);
  40. wsc.andLnameEqualTo(lname);
  41. List<DMway> ways= wdao.selectByExample(wsb);
  42. if(ways.isEmpty()){
  43. DMway mway =new DMway();
  44. mway.setAid(aid);
  45. mway.setLname(lname);
  46. mway.setLnodes(lnodes);
  47. mway.setLevel("0");
  48. // mway.setPersonsites(personsites);
  49. wdao.insertSelective(mway);
  50. }else{
  51. DMway mway =ways.get(0);
  52. mway.setLnodes(lnodes);
  53. mway.setLevel("0");
  54. // mway.setPersonsites(personsites);
  55. wdao.updateByPrimaryKey(mway);
  56. }
  57. List<DMway> ways2= wdao.selectByExample(wsb);
  58. DMway mway =ways2.get(0);
  59. //作业地点,pipes88,pipes185,pipes184,pipes183,pipes168,pipes165,pipes166,pipes165,pipes163,pipes159,pipes162,pipes159,pipes161,pipes159,pipes160,pipes131,pipes8,主井,地面
  60. saveMayNodes(lnodes,mway);
  61. }
  62. //根据映射生成路径信息
  63. private void saveMayNodes(String lnodes,DMway way) throws BusinessException {
  64. DPtpipeassMapper ptDao = UtilTools.getBean(DPtpipeassMapper.class);
  65. DPtpipeassSQLBuilder ptsb = new DPtpipeassSQLBuilder();
  66. DPipeMapper pDao = UtilTools.getBean(DPipeMapper.class);
  67. DPipeSQLBuilder psb =new DPipeSQLBuilder();
  68. String[] lnode_s = lnodes.split(",");
  69. List<String> lnode_sl = new ArrayList<>();
  70. for (int i = 1; i < lnode_s.length-2; i++) {
  71. lnode_sl.add(lnode_s[i]);
  72. }
  73. List<DPipe> pList = getdPipes(ptDao, ptsb, pDao, lnode_sl);
  74. DPipe genp=pList.get(0);
  75. updateWayPerson(way, genp);
  76. AllPahtsDFS pathFinder = new AllPahtsDFS();
  77. DPipeSQLBuilder.Criteria psc = psb.createCriteria();
  78. DPipe genPipe = pList.get(0);
  79. List<Integer> pids = getPids(pList, pathFinder, genPipe);
  80. List<DPipe> ps = new ArrayList<>();
  81. for (Integer pid: pids) {
  82. ps.add(pDao.selectByPrimaryKey(pid));
  83. }
  84. List<Integer> nids = getNids(ps);
  85. insetWayNodes(way, nids);
  86. }
  87. /**
  88. * 更新人员定位数据
  89. * @param way
  90. * @param genp
  91. */
  92. private void updateWayPerson(DMway way, DPipe genp) {
  93. DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
  94. way.setPersonsites(genp.getCode());
  95. wdao.updateByPrimaryKey(way);
  96. }
  97. /**
  98. * 根据平台映射关系 获取 管道
  99. * @param ptDao
  100. * @param ptsb
  101. * @param pDao
  102. * @param lnode_sl
  103. * @return
  104. * @throws BusinessException
  105. */
  106. private List<DPipe> getdPipes(DPtpipeassMapper ptDao, DPtpipeassSQLBuilder ptsb, DPipeMapper pDao, List<String> lnode_sl) throws BusinessException {
  107. List<DPtpipeass> ptpList = new ArrayList<>();
  108. for (String ptcode : lnode_sl) {
  109. ptsb.clear();
  110. DPtpipeassSQLBuilder.Criteria ptsc = ptsb.createCriteria();
  111. ptsc.andPtcodeEqualTo(ptcode);
  112. List<DPtpipeass> ptpsonList = new ArrayList<>();
  113. ptpsonList= ptDao.selectByExample(ptsb);
  114. if(!ptpsonList.isEmpty()){
  115. ptpList.addAll(ptpsonList);
  116. }
  117. }
  118. List<DPipe> pList= new ArrayList<>();
  119. System.out.println("------------------");
  120. for (DPtpipeass pt: ptpList) {
  121. DPipe p = pDao.selectByPrimaryKey(pt.getPid());
  122. if(p !=null){
  123. System.out.println(p.getId());
  124. pList.add(p);
  125. }
  126. }
  127. if(pList.isEmpty()){
  128. throw new BusinessException("EMB00004");
  129. }
  130. return pList;
  131. }
  132. /**
  133. * 根据DFS 规则 获取路径
  134. * @param pList
  135. * @param pathFinder
  136. * @param genPipe
  137. * @return
  138. * @throws BusinessException
  139. */
  140. private List<Integer> getPids(List<DPipe> pList, AllPahtsDFS pathFinder, DPipe genPipe) throws BusinessException {
  141. //结果队列
  142. Queue<DPipe> queue = new LinkedList<>();
  143. queue.add(genPipe);
  144. List<Integer> notids = new ArrayList<>();
  145. notids.add(genPipe.getId());
  146. while (!queue.isEmpty()){
  147. DPipe fpipe = queue.poll();
  148. List<DPipe> sonList = getSonPipes(fpipe,notids);
  149. for (DPipe sonPipe: sonList) {
  150. pathFinder.addEdge(fpipe.getId(),sonPipe.getId());
  151. notids.add(sonPipe.getId());//已经查询的数据排除
  152. // System.out.println(fpipe.getId()+","+sonPipe.getId());
  153. }
  154. if(sonList.isEmpty()){
  155. continue;
  156. }
  157. for (DPipe sonPipe: sonList) {
  158. queue.add(sonPipe);
  159. }
  160. }
  161. System.out.println("------------------");
  162. //获取所有路径
  163. List<List<Integer>> paths= pathFinder.findAllPaths(pList.get(0).getId(), pList.get(pList.size()-1).getId());
  164. if(paths.isEmpty()){
  165. throw new BusinessException("EMB00004");
  166. }
  167. List<Integer> pids = paths.get(0);
  168. return pids;
  169. }
  170. /**
  171. * 根据节点编号保存 DMwayNode
  172. * @param way
  173. * @param nids
  174. */
  175. private void insetWayNodes(DMway way, List<Integer> nids) {
  176. //删除历史
  177. DMwaynodeMapper mwnDao =UtilTools.getBean(DMwaynodeMapper.class);
  178. DMwaynodeSQLBuilder mwnSb = new DMwaynodeSQLBuilder();
  179. DMwaynodeSQLBuilder.Criteria mwnsc = mwnSb.createCriteria();
  180. mwnsc.andMwidEqualTo(way.getId());
  181. mwnDao.deleteByExample(mwnSb);
  182. //新增
  183. DNodeMapper nodeDao =UtilTools.getBean(DNodeMapper.class);
  184. int seq =0;
  185. for (Integer nid: nids) {
  186. DNode n = nodeDao.selectByPrimaryKey(nid);
  187. DMwaynode mwaynode = new DMwaynode();
  188. mwaynode.setMwid(way.getId());
  189. mwaynode.setNcode(n.getCode());
  190. mwaynode.setNid(n.getId());
  191. mwaynode.setNname(n.getName());
  192. mwaynode.setSeq(seq++);
  193. mwnDao.insertSelective(mwaynode);
  194. }
  195. }
  196. /**
  197. * 按顺序获取 节点编号
  198. * @param ps
  199. * @return
  200. */
  201. private List<Integer> getNids(List<DPipe> ps) {
  202. List<Integer> nids = new ArrayList<>();
  203. DPipe temp =null;
  204. for (int i = 0; i< ps.size(); i++) {
  205. DPipe p = ps.get(i);
  206. if(temp==null){
  207. temp =p;
  208. }else {
  209. int x1 = temp.getSnid();
  210. int x2 = temp.getEnid();
  211. int y1 = p.getSnid();
  212. int y2 = p.getEnid();
  213. if(x1 ==y1){
  214. nids.add(x2);
  215. nids.add(x1);
  216. nids.add(y2);
  217. }else if (x1==y2){
  218. nids.add(x2);
  219. nids.add(x1);
  220. nids.add(y1);
  221. }else if(x2==y1){
  222. nids.add(x1);
  223. nids.add(x2);
  224. nids.add(y2);
  225. }else if(x2==y2){
  226. nids.add(x1);
  227. nids.add(x2);
  228. nids.add(y1);
  229. }
  230. }
  231. temp= p;
  232. }
  233. System.out.println(nids);
  234. LinkedHashSet<Integer> set = new LinkedHashSet<>(nids);
  235. nids = new ArrayList<>(set);
  236. System.out.println("------------------");
  237. System.out.println(nids);
  238. return nids;
  239. }
  240. private List<DPipe> getSonPipes(DPipe fPipe,List<Integer> notids){
  241. DPipeMapper pDao = UtilTools.getBean(DPipeMapper.class);
  242. DPipeSQLBuilder psb =new DPipeSQLBuilder();
  243. DPipeSQLBuilder.Criteria psc = psb.createCriteria();
  244. List<Integer> nids = new ArrayList<>();
  245. nids.add(fPipe.getSnid());
  246. nids.add(fPipe.getEnid());
  247. psc.andSnidIn(nids);
  248. psc.andIdNotIn(notids);
  249. List<DPipe> s1List = pDao.selectByExample(psb);
  250. psb.clear();
  251. psc = psb.createCriteria();
  252. psc.andEnidIn(nids);
  253. psc.andIdNotIn(notids);
  254. List<DPipe> s2List = pDao.selectByExample(psb);
  255. s1List.addAll(s2List);
  256. return s1List;
  257. }
  258. /**
  259. * 基础系统,“平台对接预设路径”业务前处理
  260. */
  261. public void preTransFlow() throws Exception {
  262. this.validater();
  263. }
  264. /**
  265. * 基础系统,“平台对接预设路径”业务后处理
  266. */
  267. public void afterTransFlow() throws Exception {
  268. }
  269. /**
  270. * 基础系统,“平台对接预设路径”逻辑入口处理方法
  271. */
  272. @SuppressWarnings("rawtypes")
  273. @Override
  274. public Map execute(Map vars) throws Exception {
  275. this.setTransMap(vars);
  276. preTransFlow();// 执行业务开始的规则检查和校验
  277. transExecute();// 执行核心业务段
  278. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  279. return this.getTransMap();
  280. }
  281. }