feat: 增加ied查询,调整sql

dev
huangfeng 1 year ago
parent fefd41731e
commit 758c963540

@ -4,8 +4,17 @@ CREATE TABLE `icd_file_config` (
`ldevice_inst` varchar(45) NOT NULL,
`ln_class` varchar(45) NOT NULL,
`do_name` varchar(45) NOT NULL,
`last_name` varchar(45) DEFAULT NULL,
`table_name` varchar(45) DEFAULT NULL,
`col_name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idxKey` (`ied_name`,`ldevice_inst`,`ln_class`,`do_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `icd_file_config_inst` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`config_id` int(11) NOT NULL,
`inst` varchar(45) DEFAULT NULL,
`paramindex` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idxConfigid` (`config_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

@ -48,6 +48,17 @@ public class IcdConfigController extends BasicController {
}
}
@GetMapping("iedList")
@ApiOperation("查询IED列表")
public Response<List<String>> iedList() {
try {
List<String> result = configService.iedList();
return Response.success(result);
} catch (Exception ex) {
return Response.fail(ex.getMessage());
}
}
@PostMapping("update")
@ApiOperation("更新ICD类型配置")
public Response<String> update(@RequestBody IcdFileConfig item) {

@ -1,34 +0,0 @@
package com.xydl.cac.controller;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.IcdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Api(tags = {"Icd相关接口"})
@RequestMapping("icd")
@Slf4j
public class IcdController extends BasicController {
@Resource
IcdService service;
@PostMapping("process")
@ApiOperation("处理icd文件")
public Response<List<String>> process(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) {
List<String> paramList = service.loadXml(file.getInputStream());
return Response.success(paramList);
} else {
return Response.fail("缺少上传文件");
}
}
}

@ -8,6 +8,8 @@ public interface IcdFileConfigService {
void upload(String xml) throws Exception;
List<String> iedList();
List<IcdFileConfig> list(String iedName) throws Exception;
void update(IcdFileConfig item);

@ -1,10 +0,0 @@
package com.xydl.cac.service;
import java.io.InputStream;
import java.util.List;
public interface IcdService {
List<String> loadXml(InputStream input) throws Exception;
List<String> loadXml(String xml) throws Exception;
}

@ -8,6 +8,7 @@ import com.xydl.cac.service.IcdFileConfigService;
import com.xydl.cac.util.IcdXmlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -26,6 +27,8 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
IcdFileConfigRepository repository;
@Resource
IcdFileConfigInstRepository instRepository;
@Resource
private JdbcTemplate jdbcTemplate;
@Override
public void upload(String xml) throws Exception {
@ -45,6 +48,13 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
}
}
@Override
public List<String> iedList() {
String sql = "SELECT DISTINCT ied_name FROM icd_file_config";
List<String> list = jdbcTemplate.queryForList(sql, String.class);
return list;
}
@Override
public List<IcdFileConfig> list(String iedName) throws Exception {
List<IcdFileConfig> result;

@ -1,128 +0,0 @@
package com.xydl.cac.service.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.xydl.cac.service.IcdService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.*;
@Service
@Slf4j
public class IcdServiceImpl implements IcdService {
@Override
public List<String> loadXml(InputStream input) throws Exception {
XmlMapper xmlMapper = XmlMapper.builder()
.build();
JsonNode root = xmlMapper.readTree(input);
List<String> paramList = this.processRoot(root);
return paramList;
}
@Override
public List<String> loadXml(String xml) throws Exception {
XmlMapper xmlMapper = XmlMapper.builder()
.build();
JsonNode root = xmlMapper.readTree(xml);
List<String> paramList = this.processRoot(root);
return paramList;
}
private List<String> processRoot(JsonNode root) {
List<String> paramList = new ArrayList<>();
List<JsonNode> iedList = this.findNodes(root, "IED");
for (JsonNode iedNode : iedList) {
String iedName = iedNode.get("name").asText();
List<JsonNode> devList = this.findNodes(iedNode, "LDevice");
for (JsonNode dev : devList) {
this.processDeviceNode(dev, iedName, paramList);
}
}
return paramList;
}
private void processDeviceNode(JsonNode deviceNode, String iedName, List<String> paramList) {
String inst = deviceNode.get("inst").asText();
Map<String, JsonNode> lnMap = this.buildLNMap(deviceNode);
List<JsonNode> fcdaList = this.findNodes(deviceNode, "FCDA");
for (JsonNode fcdaNode : fcdaList) {
String lnClass = fcdaNode.get("lnClass").asText();
String lnInst = fcdaNode.get("lnInst").asText();
String doName = fcdaNode.get("doName").asText();
String fc = fcdaNode.get("fc").asText();
JsonNode lnNode = lnMap.get(lnClass + lnInst);
String dai = this.findLN_DOI_DAI(lnNode, doName);
String param = iedName + inst + "/" + lnClass + lnInst + "$" + fc + "$" + doName + "$" + dai;
paramList.add(param);
}
}
private Map<String, JsonNode> buildLNMap(JsonNode deviceNode) {
Map<String, JsonNode> map = new HashMap<>();
List<JsonNode> lnList = this.findNodes(deviceNode, "LN");
for (JsonNode lnNode : lnList) {
String lnClass = lnNode.get("lnClass").asText();
String inst = lnNode.get("inst").asText();
map.put(lnClass + inst, lnNode);
}
return map;
}
private String findLN_DOI_DAI(JsonNode lnNode, String doName) {
String result = "";
List<JsonNode> doiList = this.findNodes(lnNode, "DOI");
for (JsonNode doiNode : doiList) {
String doiName = doiNode.get("name").asText();
if (doiName.equals(doName)) {
JsonNode pnode = doiNode;
List<JsonNode> sdiList = this.findNodes(doiNode, "SDI");
if (sdiList.size() > 0) {
JsonNode sdiNode = sdiList.get(0);
result = sdiNode.get("name").asText();
pnode = sdiNode;
}
List<JsonNode> daiList = this.findNodes(pnode, "DAI");
if (daiList.size() > 0) {
JsonNode daiNode = daiList.get(0);
String daiName = daiNode.get("name").asText();
if (StringUtils.isNotBlank(result)) {
result = result + "$" + daiName;
} else {
result = daiName;
}
}
break;
}
}
return result;
}
private List<JsonNode> findNodes(JsonNode root, String fieldName) {
List<JsonNode> result = new ArrayList<>();
List<JsonNode> list = root.findValues(fieldName);
for (JsonNode node : list) {
if (node instanceof ObjectNode) {
result.add(node);
}
if (node instanceof ArrayNode) {
ArrayNode array = (ArrayNode) node;
Iterator<JsonNode> elements = array.elements();
while (elements.hasNext()) {
JsonNode item = elements.next();
result.add(item);
}
}
}
return result;
}
}
Loading…
Cancel
Save