123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- package com.miniframe.bisiness.system;
- import java.util.*;
- import com.miniframe.core.ExecProcessFlow;
- import com.miniframe.core.exception.BusinessException;
- import com.miniframe.core.ext.UtilTools;
- import com.miniframe.generate.business.system.model.M00002BaseModel;
- import com.miniframe.model.system.*;
- import com.miniframe.model.system.dao.*;
- import com.miniframe.ptdj.AllPahtsDFS;
- import javax.rmi.CORBA.Util;
- /**
- * 基础系统,“平台对接预设路径”逻辑处理(重新生成不覆盖)。
- */
- public class M00002Service extends M00002BaseModel implements ExecProcessFlow {
-
- private static final long serialVersionUID = -7051358269847459502L;
-
- /**
- * 基础系统,“平台对接预设路径”业务核心处理
- */
- public void transExecute() throws Exception {
- Integer aid =this.getA_m00002().getAid();
- String lname =this.getA_m00002().getLname();
- String lnodes =this.getA_m00002().getLnodes();
- String personsites=this.getA_m00002().getPersonsites();
- // String[] persons = personsites.split(";");
- // for (String p:persons) {
- // String[] st =p.split(",");
- // if(st.length!=3){
- // throw new BusinessException("EMB00003");
- // }
- // }
- DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
- DAccidentMapper accDao = UtilTools.getBean(DAccidentMapper.class);
- DAccident da =accDao.selectByPrimaryKey(aid);
- if(da==null){
- throw new BusinessException("EB3000002");
- }
- DMwaySQLBuilder wsb =new DMwaySQLBuilder();
- DMwaySQLBuilder.Criteria wsc =wsb.createCriteria();
- wsc.andAidEqualTo(aid);
- wsc.andLnameEqualTo(lname);
- List<DMway> ways= wdao.selectByExample(wsb);
- if(ways.isEmpty()){
- DMway mway =new DMway();
- mway.setAid(aid);
- mway.setLname(lname);
- mway.setLnodes(lnodes);
- mway.setLevel("0");
- // mway.setPersonsites(personsites);
- wdao.insertSelective(mway);
- }else{
- DMway mway =ways.get(0);
- mway.setLnodes(lnodes);
- mway.setLevel("0");
- // mway.setPersonsites(personsites);
- wdao.updateByPrimaryKey(mway);
- }
- List<DMway> ways2= wdao.selectByExample(wsb);
- DMway mway =ways2.get(0);
- //作业地点,pipes88,pipes185,pipes184,pipes183,pipes168,pipes165,pipes166,pipes165,pipes163,pipes159,pipes162,pipes159,pipes161,pipes159,pipes160,pipes131,pipes8,主井,地面
- saveMayNodes(lnodes,mway);
- }
- //根据映射生成路径信息
- private void saveMayNodes(String lnodes,DMway way) throws BusinessException {
- DPtpipeassMapper ptDao = UtilTools.getBean(DPtpipeassMapper.class);
- DPtpipeassSQLBuilder ptsb = new DPtpipeassSQLBuilder();
- DPipeMapper pDao = UtilTools.getBean(DPipeMapper.class);
- DPipeSQLBuilder psb =new DPipeSQLBuilder();
- String[] lnode_s = lnodes.split(",");
- List<String> lnode_sl = new ArrayList<>();
- for (int i = 1; i < lnode_s.length-2; i++) {
- lnode_sl.add(lnode_s[i]);
- }
- List<DPipe> pList = getdPipes(ptDao, ptsb, pDao, lnode_sl);
- DPipe genp=pList.get(0);
- updateWayPerson(way, genp);
- AllPahtsDFS pathFinder = new AllPahtsDFS();
- DPipeSQLBuilder.Criteria psc = psb.createCriteria();
- DPipe genPipe = pList.get(0);
- List<Integer> pids = getPids(pList, pathFinder, genPipe);
- List<DPipe> ps = new ArrayList<>();
- for (Integer pid: pids) {
- ps.add(pDao.selectByPrimaryKey(pid));
- }
- List<Integer> nids = getNids(ps);
- insetWayNodes(way, nids);
- }
- /**
- * 更新人员定位数据
- * @param way
- * @param genp
- */
- private void updateWayPerson(DMway way, DPipe genp) {
- DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
- way.setPersonsites(genp.getCode());
- wdao.updateByPrimaryKey(way);
- }
- /**
- * 根据平台映射关系 获取 管道
- * @param ptDao
- * @param ptsb
- * @param pDao
- * @param lnode_sl
- * @return
- * @throws BusinessException
- */
- private List<DPipe> getdPipes(DPtpipeassMapper ptDao, DPtpipeassSQLBuilder ptsb, DPipeMapper pDao, List<String> lnode_sl) throws BusinessException {
- List<DPtpipeass> ptpList = new ArrayList<>();
- for (String ptcode : lnode_sl) {
- ptsb.clear();
- DPtpipeassSQLBuilder.Criteria ptsc = ptsb.createCriteria();
- ptsc.andPtcodeEqualTo(ptcode);
- List<DPtpipeass> ptpsonList = new ArrayList<>();
- ptpsonList= ptDao.selectByExample(ptsb);
- if(!ptpsonList.isEmpty()){
- ptpList.addAll(ptpsonList);
- }
- }
- List<DPipe> pList= new ArrayList<>();
- System.out.println("------------------");
- for (DPtpipeass pt: ptpList) {
- DPipe p = pDao.selectByPrimaryKey(pt.getPid());
- if(p !=null){
- System.out.println(p.getId());
- pList.add(p);
- }
- }
- if(pList.isEmpty()){
- throw new BusinessException("EMB00004");
- }
- return pList;
- }
- /**
- * 根据DFS 规则 获取路径
- * @param pList
- * @param pathFinder
- * @param genPipe
- * @return
- * @throws BusinessException
- */
- private List<Integer> getPids(List<DPipe> pList, AllPahtsDFS pathFinder, DPipe genPipe) throws BusinessException {
- //结果队列
- Queue<DPipe> queue = new LinkedList<>();
- queue.add(genPipe);
- List<Integer> notids = new ArrayList<>();
- notids.add(genPipe.getId());
- while (!queue.isEmpty()){
- DPipe fpipe = queue.poll();
- List<DPipe> sonList = getSonPipes(fpipe,notids);
- for (DPipe sonPipe: sonList) {
- pathFinder.addEdge(fpipe.getId(),sonPipe.getId());
- notids.add(sonPipe.getId());//已经查询的数据排除
- // System.out.println(fpipe.getId()+","+sonPipe.getId());
- }
- if(sonList.isEmpty()){
- continue;
- }
- for (DPipe sonPipe: sonList) {
- queue.add(sonPipe);
- }
- }
- System.out.println("------------------");
- //获取所有路径
- List<List<Integer>> paths= pathFinder.findAllPaths(pList.get(0).getId(), pList.get(pList.size()-1).getId());
- if(paths.isEmpty()){
- throw new BusinessException("EMB00004");
- }
- List<Integer> pids = paths.get(0);
- return pids;
- }
- /**
- * 根据节点编号保存 DMwayNode
- * @param way
- * @param nids
- */
- private void insetWayNodes(DMway way, List<Integer> nids) {
- //删除历史
- DMwaynodeMapper mwnDao =UtilTools.getBean(DMwaynodeMapper.class);
- DMwaynodeSQLBuilder mwnSb = new DMwaynodeSQLBuilder();
- DMwaynodeSQLBuilder.Criteria mwnsc = mwnSb.createCriteria();
- mwnsc.andMwidEqualTo(way.getId());
- mwnDao.deleteByExample(mwnSb);
- //新增
- DNodeMapper nodeDao =UtilTools.getBean(DNodeMapper.class);
- int seq =0;
- for (Integer nid: nids) {
- DNode n = nodeDao.selectByPrimaryKey(nid);
- DMwaynode mwaynode = new DMwaynode();
- mwaynode.setMwid(way.getId());
- mwaynode.setNcode(n.getCode());
- mwaynode.setNid(n.getId());
- mwaynode.setNname(n.getName());
- mwaynode.setSeq(seq++);
- mwnDao.insertSelective(mwaynode);
- }
- }
- /**
- * 按顺序获取 节点编号
- * @param ps
- * @return
- */
- private List<Integer> getNids(List<DPipe> ps) {
- List<Integer> nids = new ArrayList<>();
- DPipe temp =null;
- for (int i = 0; i< ps.size(); i++) {
- DPipe p = ps.get(i);
- if(temp==null){
- temp =p;
- }else {
- int x1 = temp.getSnid();
- int x2 = temp.getEnid();
- int y1 = p.getSnid();
- int y2 = p.getEnid();
- if(x1 ==y1){
- nids.add(x2);
- nids.add(x1);
- nids.add(y2);
- }else if (x1==y2){
- nids.add(x2);
- nids.add(x1);
- nids.add(y1);
- }else if(x2==y1){
- nids.add(x1);
- nids.add(x2);
- nids.add(y2);
- }else if(x2==y2){
- nids.add(x1);
- nids.add(x2);
- nids.add(y1);
- }
- }
- temp= p;
- }
- System.out.println(nids);
- LinkedHashSet<Integer> set = new LinkedHashSet<>(nids);
- nids = new ArrayList<>(set);
- System.out.println("------------------");
- System.out.println(nids);
- return nids;
- }
- private List<DPipe> getSonPipes(DPipe fPipe,List<Integer> notids){
- DPipeMapper pDao = UtilTools.getBean(DPipeMapper.class);
- DPipeSQLBuilder psb =new DPipeSQLBuilder();
- DPipeSQLBuilder.Criteria psc = psb.createCriteria();
- List<Integer> nids = new ArrayList<>();
- nids.add(fPipe.getSnid());
- nids.add(fPipe.getEnid());
- psc.andSnidIn(nids);
- psc.andIdNotIn(notids);
- List<DPipe> s1List = pDao.selectByExample(psb);
- psb.clear();
- psc = psb.createCriteria();
- psc.andEnidIn(nids);
- psc.andIdNotIn(notids);
- List<DPipe> s2List = pDao.selectByExample(psb);
- s1List.addAll(s2List);
- return s1List;
- }
- /**
- * 基础系统,“平台对接预设路径”业务前处理
- */
- public void preTransFlow() throws Exception {
- this.validater();
- }
-
- /**
- * 基础系统,“平台对接预设路径”业务后处理
- */
- public void afterTransFlow() throws Exception {
-
- }
-
- /**
- * 基础系统,“平台对接预设路径”逻辑入口处理方法
- */
- @SuppressWarnings("rawtypes")
- @Override
- public Map execute(Map vars) throws Exception {
- this.setTransMap(vars);
- preTransFlow();// 执行业务开始的规则检查和校验
- transExecute();// 执行核心业务段
- afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
- return this.getTransMap();
- }
- }
|