diff --git a/src/main/java/com/xydl/cac/util/IcdXmlUtil.java b/src/main/java/com/xydl/cac/util/IcdXmlUtil.java index 7487eb5..de8197c 100644 --- a/src/main/java/com/xydl/cac/util/IcdXmlUtil.java +++ b/src/main/java/com/xydl/cac/util/IcdXmlUtil.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.xydl.cac.entity.IcdConfigType; import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; import java.util.*; @@ -22,25 +23,33 @@ public class IcdXmlUtil { private static LinkedHashMap processTypeRoot(JsonNode root) { LinkedHashMap result = new LinkedHashMap<>(); + Map mapLNodeType = buildLNodeTypeMap(root); + Map mapDOType = buildDOTypeMap(root); + Map mapDAType = buildDATypeMap(root); + List iedList = findNodes(root, "IED"); for (JsonNode iedNode : iedList) { - processIEDNode(iedNode, result); + processIEDNode(result, iedNode, + mapLNodeType, mapDOType, mapDAType); } return result; } - private static void processIEDNode(JsonNode iedNode, LinkedHashMap result) { + private static void processIEDNode(LinkedHashMap result, JsonNode iedNode, + Map mapLNodeType, Map mapDOType, Map mapDAType) { String iedName = iedNode.get("name").asText(); List devList = findNodes(iedNode, "LDevice"); for (JsonNode dev : devList) { - processTypeDeviceNode(dev, iedName, result); + processTypeDeviceNode(result, iedName, dev, + mapLNodeType, mapDOType, mapDAType); } } - private static void processTypeDeviceNode(JsonNode deviceNode, String iedName, LinkedHashMap result) { + private static void processTypeDeviceNode(LinkedHashMap result, String iedName, JsonNode deviceNode, + Map mapLNodeType, Map mapDOType, Map mapDAType) { String ldeviceInst = deviceNode.get("inst").asText(); - Map lnMap = buildLNMap(deviceNode); + Map mapLN = buildLNMap(deviceNode); List fcdaList = findNodes(deviceNode, "FCDA"); for (JsonNode fcdaNode : fcdaList) { @@ -49,11 +58,14 @@ public class IcdXmlUtil { String doName = fcdaNode.get("doName").asText(); String fc = fcdaNode.get("fc").asText(); - JsonNode lnNode = lnMap.get(lnClass + lnInst); - String dai = findLN_DOI_DAI(lnNode, doName); + JsonNode lnNode = mapLN.get(lnClass + lnInst); + String lnType = lnNode.get("lnType").asText(); + JsonNode nodeLNodeType = mapLNodeType.get(lnType); + String doType = findLNodeType_DO_Type(nodeLNodeType, doName); + JsonNode nodeDOType = mapDOType.get(doType); + String lastname = findLastname(nodeDOType, fc, mapDAType); String key = iedName + ldeviceInst + "/" + lnClass; - String param = fc + "$" + doName + "$" + dai; if ("MX".equals(fc)) { IcdConfigType config = result.get(key); if (config == null) { @@ -64,6 +76,20 @@ public class IcdXmlUtil { .build(); result.put(key, config); } + String param = fc + "$" + doName + "$" + lastname; + config.addInst(lnInst); + config.addAtt(doName, param); + } else if ("ST".equals(fc)) { + IcdConfigType config = result.get(key); + if (config == null) { + config = IcdConfigType.builder() + .iedName(iedName) + .ldeviceInst(ldeviceInst) + .lnClass(lnClass) + .build(); + result.put(key, config); + } + String param = fc + "$" + doName + "$" + lastname; config.addInst(lnInst); config.addAtt(doName, param); } @@ -72,15 +98,81 @@ public class IcdXmlUtil { private static Map buildLNMap(JsonNode deviceNode) { Map map = new LinkedHashMap<>(); - List lnList = findNodes(deviceNode, "LN"); - for (JsonNode lnNode : lnList) { - String lnClass = lnNode.get("lnClass").asText(); - String inst = lnNode.get("inst").asText(); - map.put(lnClass + inst, lnNode); + List list = findNodes(deviceNode, "LN"); + for (JsonNode node : list) { + String lnClass = node.get("lnClass").asText(); + String inst = node.get("inst").asText(); + map.put(lnClass + inst, node); + } + return map; + } + + private static Map buildDOTypeMap(JsonNode root) { + Map map = new LinkedHashMap<>(); + List list = findNodes(root, "DOType"); + for (JsonNode node : list) { + String id = node.get("id").asText(); + map.put(id, node); + } + return map; + } + + private static Map buildDATypeMap(JsonNode root) { + Map map = new LinkedHashMap<>(); + List list = findNodes(root, "DAType"); + for (JsonNode node : list) { + String id = node.get("id").asText(); + map.put(id, node); } return map; } + private static Map buildLNodeTypeMap(JsonNode root) { + Map map = new LinkedHashMap<>(); + List listLNodeType = findNodes(root, "LNodeType"); + for (JsonNode node : listLNodeType) { + String id = node.get("id").asText(); + map.put(id, node); + } + return map; + } + + private static String findLNodeType_DO_Type(JsonNode lnNode, String doName) { + String result = ""; + List doiList = findNodes(lnNode, "DO"); + for (JsonNode doiNode : doiList) { + String doiName = doiNode.get("name").asText(); + if (doiName.equals(doName)) { + result = doiNode.get("type").asText(); + break; + } + } + return result; + } + + private static String findLastname(JsonNode node, String fcname, Map mapDAType) { + String result = ""; + List daList = findNodes(node, "DA"); + for (JsonNode daNode : daList) { + JsonNode dchgNode = daNode.get("dchg"); + String fc = daNode.get("fc").asText(); + if (dchgNode != null && dchgNode.asText().equals("true") && fc.equals(fcname)) { + result = daNode.get("name").asText(); + JsonNode typeNode = daNode.get("type"); + if (typeNode != null && StringUtils.isNotBlank(typeNode.asText())) { + JsonNode nodeDAType = mapDAType.get(typeNode.asText()); + List bdaList = findNodes(nodeDAType, "BDA"); + if (!CollectionUtils.isEmpty(bdaList)) { + String name = bdaList.get(0).get("name").asText(); + result = result + "$" + name; + } + } + break; + } + } + return result; + } + private static String findLN_DOI_DAI(JsonNode lnNode, String doName) { String result = ""; List doiList = findNodes(lnNode, "DOI");