zhoupeng 1 年之前
父节点
当前提交
655da6f4cd
共有 1 个文件被更改,包括 28 次插入51 次删除
  1. 28 51
      cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

+ 28 - 51
cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -570,69 +570,45 @@ public class OpcDaUtil {
                 }
                 }
             }
             }
         }
         }
-        //将mapList第一个的满足的叶子拿出来,得到第一个满足的所有叶节点,以及叶子名称
+
         if (Blank.isNotEmpty(mapList)) {
         if (Blank.isNotEmpty(mapList)) {
+            //将mapList第一个的满足的枝节点拿出来
             Map<String, String> map = mapList.get(0);
             Map<String, String> map = mapList.get(0);
-            List<Map<String, String>> list = getFirstNodeDetails1(treeBrowser, new Branch(branch, map.get("current")), needItemStr);
-//            String prefix = map0.get("prefix");
-            //根据第一个map映射出其他所有数据项的叶节点
-            for (int i = 1; i < mapList.size(); i++) {
-//                Map<String, String> map = mapList.get(i);
-//                map.put("itemReadName", prefix + "." + map.get("current") + "." + itemstr);
-                mapAllList.addAll(mapList);
+            //得到第一个满足的所有叶节点集合
+            List<Map<String, String>> firstMapList = getFirstNodeDetails(treeBrowser, new Branch(branch, map.get("current")), needItemStr);
+            if (Blank.isNotEmpty(firstMapList)) {
+                mapAllList.addAll(firstMapList);
+                //获取第一个枝节点的,第一个叶节点
+                Map<String, String> firstMap = firstMapList.get(0);
+                //获取叶节点的前缀
+                String prefix = firstMap.get("prefix");
+                //生成其他枝节点的叶节点信息
+                for (int i = 1; i < mapList.size(); i++) {
+                    Map<String, String> map1 = mapList.get(i);
+                    List<Map<String, String>> mapList1 = new ArrayList<>();
+                    for (Map<String, String> stringMap : firstMapList) {
+                        Map<String, String> map2 = new HashMap<>();
+                        map.put("itemReadName", prefix + "." + map1.get("current") + "." + stringMap.get("itemName"));
+                        mapList1.add(map2);
+                    }
+                    if (Blank.isNotEmpty(mapList1)) {
+                        mapAllList.addAll(mapList);
+                    }
+                }
             }
             }
         }
         }
-        //通过第一个的叶子,生成其他map的叶子
-
-
         return mapAllList;
         return mapAllList;
     }
     }
 
 
     /**
     /**
-     * 获取第一个节点的详情
+     * 获取第一个节点的所有叶节点详情
      *
      *
      * @param treeBrowser
      * @param treeBrowser
      * @param branch
      * @param branch
      * @param needItemStr
      * @param needItemStr
-     * @param map
      * @return
      * @return
      */
      */
-    public static Map<String, String> getFirstNodeDetails(TreeBrowser treeBrowser, Branch branch, String needItemStr, Map<String, String> map) {
-        try {
-            treeBrowser.fillBranches(branch);
-        } catch (Exception ignored) {
-        }
-        try {
-            treeBrowser.fillLeaves(branch);
-        } catch (Exception ignored) {
-        }
-
-        Iterator iter = branch.getLeaves().iterator();
-        while (iter.hasNext()) {
-            Leaf leaf = (Leaf) iter.next();
-//            map.put(leaf.getName(), leaf.getItemId());
-            String itemName = leaf.getName();
-            if (itemName.equals(needItemStr)) {
-                String label = genFullPath(leaf);
-                map.put("label", label);
-                map.put("value", label);
-                map.put("itemName", itemName);
-                map.put("itemReadName", leaf.getItemId());
-                break;
-            }
-        }
-        String current = map.get("current");
-        String itemId1 = map.get("itemReadName");
-        if (Blank.isNotEmpty(itemId1)) {
-            int i = itemId1.lastIndexOf(current);
-            map.put("prefix", itemId1.substring(0, i));
-        } else {
-            map = new HashMap<>();
-        }
-        return map;
-    }
-
-    public static List<Map<String, String>> getFirstNodeDetails1(TreeBrowser treeBrowser, Branch branch, String needItemStr) {
+    public static List<Map<String, String>> getFirstNodeDetails(TreeBrowser treeBrowser, Branch branch, String needItemStr) {
         try {
         try {
             treeBrowser.fillBranches(branch);
             treeBrowser.fillBranches(branch);
         } catch (Exception ignored) {
         } catch (Exception ignored) {
@@ -658,6 +634,7 @@ public class OpcDaUtil {
                     map.put("value", label);
                     map.put("value", label);
                     map.put("itemName", itemName);
                     map.put("itemName", itemName);
                     map.put("itemReadName", leaf.getItemId());
                     map.put("itemReadName", leaf.getItemId());
+                    map.put("parent", leaf.getParent().getName());
                     mapList.add(map);
                     mapList.add(map);
                     break;
                     break;
                 }
                 }
@@ -667,8 +644,8 @@ public class OpcDaUtil {
             Map<String, String> map = mapList.get(0);
             Map<String, String> map = mapList.get(0);
             String itemReadName = map.get("itemReadName");
             String itemReadName = map.get("itemReadName");
             if (Blank.isNotEmpty(itemReadName)) {
             if (Blank.isNotEmpty(itemReadName)) {
-//                int i = itemReadName.lastIndexOf(current);
-//                map.put("prefix", itemReadName.substring(0, i));
+                int i = itemReadName.lastIndexOf(map.get("parent"));
+                map.put("prefix", itemReadName.substring(0, i));
             } else {
             } else {
                 map = new HashMap<>();
                 map = new HashMap<>();
             }
             }