feat: 增加icd文件名,启动服务器时可选用某个icd文件启动

dev
huangfeng 8 months ago
parent 96ef3aa860
commit 5d7cbdbf28

@ -1,6 +1,7 @@
package com.xydl.cac.controller; package com.xydl.cac.controller;
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 com.xydl.cac.model.ColumnModel; import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.model.IcdAttUpdateModel; import com.xydl.cac.model.IcdAttUpdateModel;
@ -35,14 +36,22 @@ public class IcdConfigController extends BasicController {
@ApiOperation("处理icd文件") @ApiOperation("处理icd文件")
public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception { public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) { if (file != null && file.getInputStream() != null) {
String filename = file.getOriginalFilename();
String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8")); String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8"));
configService.upload(content); configService.upload(content, filename);
return Response.success("OK"); return Response.success("OK");
} else { } else {
return Response.fail("缺少上传文件"); return Response.fail("缺少上传文件");
} }
} }
@GetMapping("listFile")
@ApiOperation("查询icd文件列表")
public Response<List<IcdFile>> listFile() throws Exception {
List<IcdFile> result = configService.listFile();
return Response.success(result);
}
@GetMapping("list") @GetMapping("list")
@ApiOperation("查询全部类型列表") @ApiOperation("查询全部类型列表")
public Response<List<IcdConfigType>> list(String iedName) throws Exception { public Response<List<IcdConfigType>> list(String iedName) throws Exception {

@ -6,11 +6,14 @@ import com.xydl.cac.model.Response;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.HashMap; import java.util.HashMap;
@RestController @RestController
@ -24,15 +27,15 @@ public class IecServerController extends BasicController {
@Resource @Resource
RealTimeDataService realTimeDataService; RealTimeDataService realTimeDataService;
@GetMapping("start") @PostMapping("start")
@ApiOperation("启动IEC服务端") @ApiOperation("启动IEC服务端")
public Response<String> start() throws Exception { public Response<String> start(@Validated @NotNull(message = "fileId不能为空!") Integer fileId) throws Exception {
iecServerService.startServer(); iecServerService.startServer(fileId);
realTimeDataService.start(); realTimeDataService.start();
return Response.success("OK"); return Response.success("OK");
} }
@GetMapping("stop") @PostMapping("stop")
@ApiOperation("停止IEC服务端") @ApiOperation("停止IEC服务端")
public Response<String> stop() throws Exception { public Response<String> stop() throws Exception {
realTimeDataService.stop(); realTimeDataService.stop();

@ -30,6 +30,10 @@ public class IcdFile {
@Column(name = "md5") @Column(name = "md5")
private String md5; private String md5;
@ApiModelProperty(name = "filename")
@Column(name = "filename")
private String filename;
@ApiModelProperty(name = "xml") @ApiModelProperty(name = "xml")
@Column(name = "xml") @Column(name = "xml")
private String xml; private String xml;

@ -14,6 +14,7 @@ public class IecServer implements ServerEventListener {
ServerSap serverSap = null; ServerSap serverSap = null;
ServerModel serversServerModel = null; ServerModel serversServerModel = null;
public boolean started = false; public boolean started = false;
public String filename = null;
public void start(String xml, int port) throws Exception { public void start(String xml, int port) throws Exception {
if (!started) { if (!started) {
@ -34,6 +35,7 @@ public class IecServer implements ServerEventListener {
log.info("已停止IEC61850服务端."); log.info("已停止IEC61850服务端.");
} }
started = false; started = false;
filename = null;
} }
public void updateBda(BasicDataAttribute bda) { public void updateBda(BasicDataAttribute bda) {

@ -4,12 +4,11 @@ import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.repository.IcdFileRepository; import com.xydl.cac.repository.IcdFileRepository;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.Optional;
@Service @Service
@Slf4j @Slf4j
@ -20,12 +19,13 @@ public class IecServerService {
IecServer iecServer = new IecServer(); IecServer iecServer = new IecServer();
public void startServer() { public void startServer(Integer fileId) {
List<IcdFile> icdFileList = fileRepository.findAll(); Optional<IcdFile> optional = fileRepository.findById(fileId);
if (!CollectionUtils.isEmpty(icdFileList)) { if (optional.isPresent()) {
IcdFile icdFile = icdFileList.get(0); IcdFile icdFile = optional.get();
try { try {
iecServer.start(icdFile.getXml(), 102); iecServer.start(icdFile.getXml(), 102);
iecServer.filename = icdFile.getFilename();
RealTimeDataService.iecServer = iecServer; RealTimeDataService.iecServer = iecServer;
} catch (Exception e) { } catch (Exception e) {
log.error("启动IEC61850服务端异常.", e); log.error("启动IEC61850服务端异常.", e);
@ -45,6 +45,7 @@ public class IecServerService {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("port", 102); map.put("port", 102);
map.put("started", iecServer.started); map.put("started", iecServer.started);
map.put("filename", iecServer.filename);
return map; return map;
} }
} }

@ -1,13 +1,16 @@
package com.xydl.cac.service; package com.xydl.cac.service;
import com.xydl.cac.entity.IcdConfigType; import com.xydl.cac.entity.IcdConfigType;
import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.model.IcdAttUpdateModel; import com.xydl.cac.model.IcdAttUpdateModel;
import java.util.List; import java.util.List;
public interface IcdFileConfigService { public interface IcdFileConfigService {
void upload(String xml) throws Exception; void upload(String xml, String filename) throws Exception;
List<IcdFile> listFile();
List<String> iedList(); List<String> iedList();

@ -41,7 +41,7 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
DataService dataService; DataService dataService;
@Override @Override
public void upload(String xml) throws Exception { public void upload(String xml, String filename) throws Exception {
String md5 = Md5.getMD5Code(xml); String md5 = Md5.getMD5Code(xml);
List<IcdFile> files = fileRepository.findByMd5(md5); List<IcdFile> files = fileRepository.findByMd5(md5);
if (!CollectionUtils.isEmpty(files)) { if (!CollectionUtils.isEmpty(files)) {
@ -50,6 +50,7 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
IcdFile icdFile = IcdXmlUtil.loadIcdType(xml); IcdFile icdFile = IcdXmlUtil.loadIcdType(xml);
icdFile.setMd5(md5); icdFile.setMd5(md5);
icdFile.setFilename(filename);
fileRepository.save(icdFile); fileRepository.save(icdFile);
for (IcdIed ied : icdFile.getIedList()) { for (IcdIed ied : icdFile.getIedList()) {
ied.setIcdFileId(icdFile.getId()); ied.setIcdFileId(icdFile.getId());
@ -83,6 +84,15 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
} }
} }
@Override
public List<IcdFile> listFile() {
List<IcdFile> files = fileRepository.findAll();
for (IcdFile file : files) {
file.setXml(null);
}
return files;
}
private IcdIed findIcdIed(List<IcdIed> list, String name) { private IcdIed findIcdIed(List<IcdIed> list, String name) {
for (IcdIed ied : list) { for (IcdIed ied : list) {
if (ied.getName().equalsIgnoreCase(name)) { if (ied.getName().equalsIgnoreCase(name)) {

Loading…
Cancel
Save