feat: 新增icd文件按类型配置的功能
parent
31a7a93585
commit
666dc613fd
@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE `icd_file_config` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`ied_name` varchar(45) NOT NULL,
|
||||||
|
`ldevice_inst` varchar(45) NOT NULL,
|
||||||
|
`ln_class` varchar(45) NOT NULL,
|
||||||
|
`do_name` varchar(45) NOT 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;
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.IcdFileConfig;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.IcdFileConfigService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(tags = {"IcdConfig相关接口"})
|
||||||
|
@RequestMapping("icdconfig")
|
||||||
|
@Slf4j
|
||||||
|
public class IcdConfigController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IcdFileConfigService configService;
|
||||||
|
|
||||||
|
@PostMapping("upload")
|
||||||
|
@ApiOperation("处理icd文件")
|
||||||
|
public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
|
||||||
|
if (file != null && file.getInputStream() != null) {
|
||||||
|
String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8"));
|
||||||
|
configService.upload(content);
|
||||||
|
return Response.success("OK");
|
||||||
|
} else {
|
||||||
|
return Response.fail("缺少上传文件");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("list")
|
||||||
|
@ApiOperation("查询全部类型列表")
|
||||||
|
public Response<List<IcdFileConfig>> list(String iedName) {
|
||||||
|
try {
|
||||||
|
List<IcdFileConfig> result = configService.list(iedName);
|
||||||
|
return Response.success(result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("update")
|
||||||
|
@ApiOperation("更新ICD类型配置")
|
||||||
|
public Response<String> update(@RequestBody IcdFileConfig item) {
|
||||||
|
try {
|
||||||
|
configService.update(item);
|
||||||
|
return Response.success("OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@ApiOperation("删除ICD类型配置")
|
||||||
|
public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) {
|
||||||
|
try {
|
||||||
|
configService.delete(id);
|
||||||
|
return Response.success("OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "icd_file_config")
|
||||||
|
@ApiModel("ICD文件配置表")
|
||||||
|
public class IcdFileConfig {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "ied_name")
|
||||||
|
private String iedName;
|
||||||
|
|
||||||
|
@Column(name = "ldevice_inst")
|
||||||
|
private String ldeviceInst;
|
||||||
|
|
||||||
|
@Column(name = "ln_class")
|
||||||
|
private String lnClass;
|
||||||
|
|
||||||
|
@Column(name = "do_name")
|
||||||
|
private String doName;
|
||||||
|
|
||||||
|
@Column(name = "table_name")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
@Column(name = "col_name")
|
||||||
|
private String colName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.IcdFileConfig;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface IcdFileConfigRepository extends JpaRepository<IcdFileConfig, Integer>, JpaSpecificationExecutor<IcdFileConfig> {
|
||||||
|
|
||||||
|
List<IcdFileConfig> findByIedName(String iedName);
|
||||||
|
|
||||||
|
List<IcdFileConfig> findByIedNameAndLdeviceInstAndLnClassAndDoName(String iedName, String ldeviceInst, String lnClass, String doName);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.IcdFileConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IcdFileConfigService {
|
||||||
|
|
||||||
|
void upload(String xml) throws Exception;
|
||||||
|
|
||||||
|
List<IcdFileConfig> list(String iedName) throws Exception;
|
||||||
|
|
||||||
|
void update(IcdFileConfig item);
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.IcdFileConfig;
|
||||||
|
import com.xydl.cac.repository.IcdFileConfigRepository;
|
||||||
|
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.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class IcdFileConfigServiceImpl implements IcdFileConfigService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IcdFileConfigRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upload(String xml) throws Exception {
|
||||||
|
LinkedHashMap<String, IcdFileConfig> result = IcdXmlUtil.loadIcdType(xml);
|
||||||
|
Collection<IcdFileConfig> configList = result.values();
|
||||||
|
for (IcdFileConfig config : configList) {
|
||||||
|
List<IcdFileConfig> list = repository.findByIedNameAndLdeviceInstAndLnClassAndDoName(
|
||||||
|
config.getIedName(), config.getLdeviceInst(), config.getLnClass(), config.getDoName());
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
repository.save(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IcdFileConfig> list(String iedName) throws Exception {
|
||||||
|
if (StringUtils.isNotBlank(iedName)) {
|
||||||
|
return repository.findByIedName(iedName);
|
||||||
|
} else {
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(IcdFileConfig item) {
|
||||||
|
repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
package com.xydl.cac.util;
|
||||||
|
|
||||||
|
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.entity.IcdFileConfig;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class IcdXmlUtil {
|
||||||
|
|
||||||
|
public static LinkedHashMap<String, IcdFileConfig> loadIcdType(String xml) throws Exception {
|
||||||
|
XmlMapper xmlMapper = XmlMapper.builder()
|
||||||
|
.build();
|
||||||
|
JsonNode root = xmlMapper.readTree(xml);
|
||||||
|
LinkedHashMap<String, IcdFileConfig> result = processTypeRoot(root);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LinkedHashMap<String, IcdFileConfig> processTypeRoot(JsonNode root) {
|
||||||
|
LinkedHashMap<String, IcdFileConfig> result = new LinkedHashMap<>();
|
||||||
|
List<JsonNode> iedList = findNodes(root, "IED");
|
||||||
|
|
||||||
|
for (JsonNode iedNode : iedList) {
|
||||||
|
String iedName = iedNode.get("name").asText();
|
||||||
|
|
||||||
|
List<JsonNode> devList = findNodes(iedNode, "LDevice");
|
||||||
|
for (JsonNode dev : devList) {
|
||||||
|
processTypeDeviceNode(dev, iedName, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void processTypeDeviceNode(JsonNode deviceNode, String iedName, LinkedHashMap<String, IcdFileConfig> result) {
|
||||||
|
String inst = deviceNode.get("inst").asText();
|
||||||
|
|
||||||
|
List<JsonNode> fcdaList = 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();
|
||||||
|
|
||||||
|
String key = iedName + "/" + inst + "/" + lnClass + "/" + doName;
|
||||||
|
if (!result.containsKey(key) && "MX".equals(fc)) {
|
||||||
|
IcdFileConfig config = IcdFileConfig.builder()
|
||||||
|
.iedName(iedName)
|
||||||
|
.ldeviceInst(inst)
|
||||||
|
.lnClass(lnClass)
|
||||||
|
.doName(doName)
|
||||||
|
.build();
|
||||||
|
result.put(key, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String findLN_DOI_DAI(JsonNode lnNode, String doName) {
|
||||||
|
String result = "";
|
||||||
|
List<JsonNode> doiList = findNodes(lnNode, "DOI");
|
||||||
|
for (JsonNode doiNode : doiList) {
|
||||||
|
String doiName = doiNode.get("name").asText();
|
||||||
|
if (doiName.equals(doName)) {
|
||||||
|
JsonNode pnode = doiNode;
|
||||||
|
List<JsonNode> sdiList = findNodes(doiNode, "SDI");
|
||||||
|
if (sdiList.size() > 0) {
|
||||||
|
JsonNode sdiNode = sdiList.get(0);
|
||||||
|
result = sdiNode.get("name").asText();
|
||||||
|
pnode = sdiNode;
|
||||||
|
}
|
||||||
|
List<JsonNode> daiList = 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 static 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…
Reference in New Issue