|
@@ -0,0 +1,240 @@
|
|
|
+package com.miniframe;
|
|
|
+
|
|
|
+import com.miniframe.core.exception.BusinessException;
|
|
|
+import com.miniframe.core.ext.UtilTools;
|
|
|
+import com.miniframe.model.system.*;
|
|
|
+import com.miniframe.model.system.dao.*;
|
|
|
+import com.miniframe.ptdj.AllPahtsDFS;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+@SpringBootTest
|
|
|
+public class PtdjTest {
|
|
|
+ public void tf(){
|
|
|
+ DMwaynodeMapper mwnDao = UtilTools.getBean(DMwaynodeMapper.class);
|
|
|
+ DMwaynodeSQLBuilder mwnsb = new DMwaynodeSQLBuilder();
|
|
|
+ DMwaynodeSQLBuilder.Criteria mwnsc = mwnsb.createCriteria();
|
|
|
+ mwnsc.andMwidEqualTo(51);
|
|
|
+ mwnsb.setOrderByClause("seq ASC");
|
|
|
+ List<DMwaynode> mwnList = mwnDao.selectByExample(mwnsb);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void t() throws BusinessException {
|
|
|
+ DMwaySQLBuilder wsb =new DMwaySQLBuilder();
|
|
|
+ DMwaySQLBuilder.Criteria wsc =wsb.createCriteria();
|
|
|
+ wsc.andAidEqualTo(1039);
|
|
|
+ wsc.andLnameEqualTo("3");
|
|
|
+ DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
|
|
|
+ List<DMway> ways= wdao.selectByExample(wsb);
|
|
|
+ DMway mway = ways.get(0);
|
|
|
+ saveMayNodes(mway.getLnodes(),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);
|
|
|
+ com.miniframe.ptdj.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));
|
|
|
+ }
|
|
|
+ DPipe gp=ps.get(0);
|
|
|
+ updateWayPerson(way, gp);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据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");
|
|
|
+ }
|
|
|
+ for (List<Integer> pids:paths ) {
|
|
|
+ System.out.println(pids);
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|