fix: 调整scd文件解析

haikang
huangfeng 1 year ago
parent 369ffc450c
commit 0737b18678

@ -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<String, IcdConfigType> processTypeRoot(JsonNode root) {
LinkedHashMap<String, IcdConfigType> result = new LinkedHashMap<>();
Map<String, JsonNode> mapLNodeType = buildLNodeTypeMap(root);
Map<String, JsonNode> mapDOType = buildDOTypeMap(root);
Map<String, JsonNode> mapDAType = buildDATypeMap(root);
List<JsonNode> 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<String, IcdConfigType> result) {
private static void processIEDNode(LinkedHashMap<String, IcdConfigType> result, JsonNode iedNode,
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
String iedName = iedNode.get("name").asText();
List<JsonNode> 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<String, IcdConfigType> result) {
private static void processTypeDeviceNode(LinkedHashMap<String, IcdConfigType> result, String iedName, JsonNode deviceNode,
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
String ldeviceInst = deviceNode.get("inst").asText();
Map<String, JsonNode> lnMap = buildLNMap(deviceNode);
Map<String, JsonNode> mapLN = buildLNMap(deviceNode);
List<JsonNode> 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<String, JsonNode> buildLNMap(JsonNode deviceNode) {
Map<String, JsonNode> map = new LinkedHashMap<>();
List<JsonNode> 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<JsonNode> 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<String, JsonNode> buildDOTypeMap(JsonNode root) {
Map<String, JsonNode> map = new LinkedHashMap<>();
List<JsonNode> list = findNodes(root, "DOType");
for (JsonNode node : list) {
String id = node.get("id").asText();
map.put(id, node);
}
return map;
}
private static Map<String, JsonNode> buildDATypeMap(JsonNode root) {
Map<String, JsonNode> map = new LinkedHashMap<>();
List<JsonNode> list = findNodes(root, "DAType");
for (JsonNode node : list) {
String id = node.get("id").asText();
map.put(id, node);
}
return map;
}
private static Map<String, JsonNode> buildLNodeTypeMap(JsonNode root) {
Map<String, JsonNode> map = new LinkedHashMap<>();
List<JsonNode> 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<JsonNode> 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<String, JsonNode> mapDAType) {
String result = "";
List<JsonNode> 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<JsonNode> 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<JsonNode> doiList = findNodes(lnNode, "DOI");

Loading…
Cancel
Save