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

iec104
huangfeng 8 months ago
parent 96ef3aa860
commit 5d7cbdbf28

@ -1,6 +1,7 @@
package com.xydl.cac.controller;
import com.xydl.cac.entity.IcdConfigType;
import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.model.IcdAttUpdateModel;
@ -35,14 +36,22 @@ public class IcdConfigController extends BasicController {
@ApiOperation("处理icd文件")
public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) {
String filename = file.getOriginalFilename();
String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8"));
configService.upload(content);
configService.upload(content, filename);
return Response.success("OK");
} else {
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")
@ApiOperation("查询全部类型列表")
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.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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.RestController;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
@RestController
@ -24,15 +27,15 @@ public class IecServerController extends BasicController {
@Resource
RealTimeDataService realTimeDataService;
@GetMapping("start")
@PostMapping("start")
@ApiOperation("启动IEC服务端")
public Response<String> start() throws Exception {
iecServerService.startServer();
public Response<String> start(@Validated @NotNull(message = "fileId不能为空!") Integer fileId) throws Exception {
iecServerService.startServer(fileId);
realTimeDataService.start();
return Response.success("OK");
}
@GetMapping("stop")
@PostMapping("stop")
@ApiOperation("停止IEC服务端")
public Response<String> stop() throws Exception {
realTimeDataService.stop();

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

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

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

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

@ -41,7 +41,7 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
DataService dataService;
@Override
public void upload(String xml) throws Exception {
public void upload(String xml, String filename) throws Exception {
String md5 = Md5.getMD5Code(xml);
List<IcdFile> files = fileRepository.findByMd5(md5);
if (!CollectionUtils.isEmpty(files)) {
@ -50,6 +50,7 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
IcdFile icdFile = IcdXmlUtil.loadIcdType(xml);
icdFile.setMd5(md5);
icdFile.setFilename(filename);
fileRepository.save(icdFile);
for (IcdIed ied : icdFile.getIedList()) {
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) {
for (IcdIed ied : list) {
if (ied.getName().equalsIgnoreCase(name)) {

Loading…
Cancel
Save