|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
|
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
|
|
import com.xydl.cac.entity.IcdConfigType;
|
|
|
|
import com.xydl.cac.entity.IcdConfigType;
|
|
|
|
|
|
|
|
import com.xydl.cac.entity.IcdFile;
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@ -13,7 +14,7 @@ import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
public class IcdXmlUtil {
|
|
|
|
public class IcdXmlUtil {
|
|
|
|
|
|
|
|
|
|
|
|
public static LinkedHashMap<String, IcdConfigType> loadIcdType(String xml) throws Exception {
|
|
|
|
public static IcdFile loadIcdType(String xml) throws Exception {
|
|
|
|
XmlMapper xmlMapper = XmlMapper.builder()
|
|
|
|
XmlMapper xmlMapper = XmlMapper.builder()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
JsonNode root;
|
|
|
|
JsonNode root;
|
|
|
@ -22,12 +23,16 @@ public class IcdXmlUtil {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new BusinessException("ICD文件解析失败,请上传正确的xml类型文件");
|
|
|
|
throw new BusinessException("ICD文件解析失败,请上传正确的xml类型文件");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LinkedHashMap<String, IcdConfigType> result = processTypeRoot(root);
|
|
|
|
IcdFile icdFile = IcdFile.builder()
|
|
|
|
return result;
|
|
|
|
.xml(xml)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
LinkedHashMap<String, IcdConfigType> iedMap = processTypeRoot(root);
|
|
|
|
|
|
|
|
icdFile.setConfigList(new ArrayList<>(iedMap.values()));
|
|
|
|
|
|
|
|
return icdFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static LinkedHashMap<String, IcdConfigType> processTypeRoot(JsonNode root) {
|
|
|
|
private static LinkedHashMap<String, IcdConfigType> processTypeRoot(JsonNode root) {
|
|
|
|
LinkedHashMap<String, IcdConfigType> result = new LinkedHashMap<>();
|
|
|
|
LinkedHashMap<String, IcdConfigType> iedMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, JsonNode> mapLNodeType = buildLNodeTypeMap(root);
|
|
|
|
Map<String, JsonNode> mapLNodeType = buildLNodeTypeMap(root);
|
|
|
|
Map<String, JsonNode> mapDOType = buildDOTypeMap(root);
|
|
|
|
Map<String, JsonNode> mapDOType = buildDOTypeMap(root);
|
|
|
@ -35,24 +40,46 @@ public class IcdXmlUtil {
|
|
|
|
|
|
|
|
|
|
|
|
List<JsonNode> iedList = findNodes(root, "IED");
|
|
|
|
List<JsonNode> iedList = findNodes(root, "IED");
|
|
|
|
for (JsonNode iedNode : iedList) {
|
|
|
|
for (JsonNode iedNode : iedList) {
|
|
|
|
processIEDNode(result, iedNode,
|
|
|
|
processIEDNode(iedMap, iedNode,
|
|
|
|
mapLNodeType, mapDOType, mapDAType);
|
|
|
|
mapLNodeType, mapDOType, mapDAType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
List<JsonNode> apList = findNodes(root, "ConnectedAP");
|
|
|
|
|
|
|
|
for (JsonNode apNode : apList) {
|
|
|
|
|
|
|
|
String iedName = apNode.get("iedName").asText();
|
|
|
|
|
|
|
|
IcdConfigType config = iedMap.get(iedName);
|
|
|
|
|
|
|
|
if (config != null) {
|
|
|
|
|
|
|
|
processAPNode(apNode, config);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return iedMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void processAPNode(JsonNode apNode, IcdConfigType config) {
|
|
|
|
|
|
|
|
List<JsonNode> pList = findNodes(apNode, "P");
|
|
|
|
|
|
|
|
for (JsonNode pNode : pList) {
|
|
|
|
|
|
|
|
String type = pNode.get("type").asText();
|
|
|
|
|
|
|
|
if ("IP".equalsIgnoreCase(type)) {
|
|
|
|
|
|
|
|
config.setIp(pNode.asText());
|
|
|
|
|
|
|
|
} else if ("OSI-AP-Title".equalsIgnoreCase(type)) {
|
|
|
|
|
|
|
|
config.setApTitle(pNode.asText());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void processIEDNode(LinkedHashMap<String, IcdConfigType> result, JsonNode iedNode,
|
|
|
|
private static void processIEDNode(LinkedHashMap<String, IcdConfigType> iedMap, JsonNode iedNode,
|
|
|
|
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
|
|
|
|
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
|
|
|
|
String iedName = iedNode.get("name").asText();
|
|
|
|
String iedName = iedNode.get("name").asText();
|
|
|
|
|
|
|
|
|
|
|
|
List<JsonNode> devList = findNodes(iedNode, "LDevice");
|
|
|
|
List<JsonNode> devList = findNodes(iedNode, "LDevice");
|
|
|
|
for (JsonNode dev : devList) {
|
|
|
|
for (JsonNode dev : devList) {
|
|
|
|
processTypeDeviceNode(result, iedName, dev,
|
|
|
|
processTypeDeviceNode(iedMap, iedName, dev,
|
|
|
|
mapLNodeType, mapDOType, mapDAType);
|
|
|
|
mapLNodeType, mapDOType, mapDAType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void processTypeDeviceNode(LinkedHashMap<String, IcdConfigType> result, String iedName, JsonNode deviceNode,
|
|
|
|
private static void processTypeDeviceNode(LinkedHashMap<String, IcdConfigType> iedMap, String iedName, JsonNode deviceNode,
|
|
|
|
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
|
|
|
|
Map<String, JsonNode> mapLNodeType, Map<String, JsonNode> mapDOType, Map<String, JsonNode> mapDAType) {
|
|
|
|
String ldeviceInst = deviceNode.get("inst").asText();
|
|
|
|
String ldeviceInst = deviceNode.get("inst").asText();
|
|
|
|
Map<String, JsonNode> mapLN = buildLNMap(deviceNode);
|
|
|
|
Map<String, JsonNode> mapLN = buildLNMap(deviceNode);
|
|
|
@ -84,7 +111,7 @@ public class IcdXmlUtil {
|
|
|
|
|
|
|
|
|
|
|
|
String key = iedName + ldeviceInst + "/" + lnClass;
|
|
|
|
String key = iedName + ldeviceInst + "/" + lnClass;
|
|
|
|
if ("MX".equals(fc)) {
|
|
|
|
if ("MX".equals(fc)) {
|
|
|
|
IcdConfigType config = result.get(key);
|
|
|
|
IcdConfigType config = iedMap.get(key);
|
|
|
|
if (config == null) {
|
|
|
|
if (config == null) {
|
|
|
|
config = IcdConfigType.builder()
|
|
|
|
config = IcdConfigType.builder()
|
|
|
|
.iedName(iedName)
|
|
|
|
.iedName(iedName)
|
|
|
@ -92,20 +119,20 @@ public class IcdXmlUtil {
|
|
|
|
.lnClass(lnClass)
|
|
|
|
.lnClass(lnClass)
|
|
|
|
.lnDesc(lnDesc)
|
|
|
|
.lnDesc(lnDesc)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
result.put(key, config);
|
|
|
|
iedMap.put(key, config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String param = fc + "$" + doName + "$" + lastname;
|
|
|
|
String param = fc + "$" + doName + "$" + lastname;
|
|
|
|
config.addInst(lnInst);
|
|
|
|
config.addInst(lnInst);
|
|
|
|
config.addAtt(doName, doDesc, param, lnInst);
|
|
|
|
config.addAtt(doName, doDesc, param, lnInst);
|
|
|
|
} else if ("ST".equals(fc)) {
|
|
|
|
} else if ("ST".equals(fc)) {
|
|
|
|
IcdConfigType config = result.get(key);
|
|
|
|
IcdConfigType config = iedMap.get(key);
|
|
|
|
if (config == null) {
|
|
|
|
if (config == null) {
|
|
|
|
config = IcdConfigType.builder()
|
|
|
|
config = IcdConfigType.builder()
|
|
|
|
.iedName(iedName)
|
|
|
|
.iedName(iedName)
|
|
|
|
.ldeviceInst(ldeviceInst)
|
|
|
|
.ldeviceInst(ldeviceInst)
|
|
|
|
.lnClass(lnClass)
|
|
|
|
.lnClass(lnClass)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
result.put(key, config);
|
|
|
|
iedMap.put(key, config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String param = fc + "$" + doName + "$" + lastname;
|
|
|
|
String param = fc + "$" + doName + "$" + lastname;
|
|
|
|
config.addInst(lnInst);
|
|
|
|
config.addInst(lnInst);
|
|
|
|