From 21b6dce9806d9fe76a2f8b897a506a1fe25873e2 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Mon, 30 Dec 2024 17:09:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=B5=8B=E8=AF=95ied=E8=BF=9E=E6=8E=A5=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cac/controller/IcdConfigController.java | 7 ++++ .../com/xydl/cac/model/StaticVariable.java | 17 +------- .../com/xydl/cac/task/Client61850Task.java | 42 +++++++++++++++++++ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/xydl/cac/controller/IcdConfigController.java b/src/main/java/com/xydl/cac/controller/IcdConfigController.java index 9714c6f..cda1b63 100644 --- a/src/main/java/com/xydl/cac/controller/IcdConfigController.java +++ b/src/main/java/com/xydl/cac/controller/IcdConfigController.java @@ -10,6 +10,7 @@ import com.xydl.cac.iec.RealTimeDataService; import com.xydl.cac.model.ColumnModel; import com.xydl.cac.model.IcdAttUpdateModel; import com.xydl.cac.model.Response; +import com.xydl.cac.model.StaticVariable; import com.xydl.cac.repository.IcdIedRepository; import com.xydl.cac.service.DataService; import com.xydl.cac.service.IcdFileConfigService; @@ -87,6 +88,12 @@ public class IcdConfigController extends BasicController { return Response.success(result); } + @GetMapping("testIed") + @ApiOperation("查询IED连接状态") + public Response> testIed() { + return Response.success(StaticVariable.iedTestList); + } + @PostMapping("update") @ApiOperation("更新ICD类型配置") public Response update(@RequestBody IcdConfigType item) throws Exception { diff --git a/src/main/java/com/xydl/cac/model/StaticVariable.java b/src/main/java/com/xydl/cac/model/StaticVariable.java index e8baf76..021561c 100644 --- a/src/main/java/com/xydl/cac/model/StaticVariable.java +++ b/src/main/java/com/xydl/cac/model/StaticVariable.java @@ -1,11 +1,7 @@ package com.xydl.cac.model; -import com.fazecast.jSerialComm.SerialPort; import com.beanit.iec61850bean.BasicDataAttribute; -import com.xydl.cac.entity.Jg; -import com.xydl.cac.entity.ModevType; -import com.xydl.cac.entity.WarnRule; -import com.xydl.cac.entity.Zsb; +import com.xydl.cac.entity.*; import com.xydl.cac.iec.IecClient; import com.xydl.cac.iec.IecServer; import com.xydl.cac.util.DateUtil; @@ -20,6 +16,7 @@ public class StaticVariable { public static HashMap paramRelationMap = new HashMap<>(); public static HashMap doneWarnMap = new HashMap<>(); public static HashMap realTimeClientMap = new HashMap<>(); + public static List iedTestList = new ArrayList<>(); public static int shutdown = 0; public static HashMap rptFromActiveMap = new HashMap<>(); public static HashMap rptToActiveMap = new HashMap<>(); @@ -31,16 +28,6 @@ public class StaticVariable { public static ConcurrentHashMap rule_Cache = new ConcurrentHashMap<>(); - - public static void wait(int seconds) throws InterruptedException { - for (int i = 0; i < seconds; i++) { - if (shutdown == 1) { - break; - } - Thread.sleep(1000); - } - } - // 更新服务端 public static void updateServerNodeValue(BasicDataAttribute bda) { Iterator it = StaticVariable.iecServerMap.keySet().iterator(); diff --git a/src/main/java/com/xydl/cac/task/Client61850Task.java b/src/main/java/com/xydl/cac/task/Client61850Task.java index b16d749..cc2b768 100644 --- a/src/main/java/com/xydl/cac/task/Client61850Task.java +++ b/src/main/java/com/xydl/cac/task/Client61850Task.java @@ -1,6 +1,8 @@ package com.xydl.cac.task; import com.xydl.cac.entity.*; +import com.xydl.cac.iec.IecClient; +import com.xydl.cac.model.StaticVariable; import com.xydl.cac.repository.*; import com.xydl.cac.service.ModevTypeService; import lombok.extern.slf4j.Slf4j; @@ -106,4 +108,44 @@ public class Client61850Task { } } + @Scheduled(initialDelay = 60 * 1000, fixedDelay = 60 * 1000) + private void testAll() { + List iedTestList = new ArrayList<>(); + List icdFileList = fileRepository.findAll(); + if (!CollectionUtils.isEmpty(icdFileList)) { + for (IcdFile icdFile : icdFileList) { + this.testOneFile(icdFile, iedTestList); + } + } + StaticVariable.iedTestList = iedTestList; + } + + private void testOneFile(IcdFile icdFile, List iedTestList) { + if (shutdown == 1) { + return; + } + List iedList = iedRepository.findByIcdFileId(icdFile.getId()); + if (!CollectionUtils.isEmpty(iedList)) { + for (IcdIed ied : iedList) { + this.testOneIed(icdFile.getXml(), ied); + iedTestList.add(ied); + } + } + } + + private void testOneIed(String xml, IcdIed ied) { + if (shutdown == 1) { + return; + } + IecClient iecClient = new IecClient(); + try { + iecClient.init(ied, xml); + iecClient.connect(); + ied.setConnected(true); + } catch (Exception ex) { + ied.setConnected(false); + } finally { + iecClient.disconnect(); + } + } } From 27ab37caef189bdb0e1991ba9525f27932ff675f Mon Sep 17 00:00:00 2001 From: huangfeng Date: Tue, 31 Dec 2024 09:48:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=8A=8A61850=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BF=9D=E5=AD=98=E5=88=B0=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E8=A1=A8=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xydl/cac/iec/IEDCollectService.java | 27 ++++++++++++++----- .../java/com/xydl/cac/task/AsyncTask.java | 5 +++- .../com/xydl/cac/task/Client61850Task.java | 3 +++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index 5543849..3d1009c 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -15,7 +15,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; -import java.net.SocketException; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -33,6 +32,7 @@ public class IEDCollectService { String xml; WebSocketServer _webSocketServer; BizConfig _bizConfig; + WarningRepository _warningRepository; String folder = "/record"; HashMap eqmidTimeMap = new HashMap<>(); @@ -41,7 +41,8 @@ public class IEDCollectService { IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository, IedDlRecordService dlRecordService, DataService dataService, String xml, IcdIed ied, - WebSocketServer webSocketServer, BizConfig bizConfig) { + WebSocketServer webSocketServer, BizConfig bizConfig, + WarningRepository warningRepository) { _configRepository = configRepository; _attRepository = attRepository; _instRepository = instRepository; @@ -52,6 +53,7 @@ public class IEDCollectService { this.ied = ied; _webSocketServer = webSocketServer; _bizConfig = bizConfig; + _warningRepository = warningRepository; iecClient = new IecClient(); } @@ -82,22 +84,33 @@ public class IEDCollectService { this.doDownload(dlList); } } catch (Exception ex) { - String err = "61850采集数据异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort(); + String err = "61850采集数据异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort() + + ", " + ex.getMessage(); log.error(err, ex); + this.saveWarning(err); String key = ied.getName() + ied.getIp() + ied.getPort(); if (!StaticVariable.doneWarnMap.containsKey(key)) { StaticVariable.doneWarnMap.put(key, "1"); _webSocketServer.sendMessage(err, null); } - if (ex instanceof SocketException) { - NetErrorThread thread = new NetErrorThread(ied.getId()); - thread.start(); - } } finally { iecClient.disconnect(); } } + private void saveWarning(String err) { + Warning warning = Warning.builder() + .zsbName("61850采集数据") + .dTime(new Date()) + .warnLevel(2) + .state("1") + .warnDesc(err) + .warnTime(new Date()) + .processTime(new Date()) + .build(); + _warningRepository.save(warning); + } + private void doCollectAndSave(List configTypeList, List rptList) throws Exception { for (IcdConfigType configType : configTypeList) { List instList = _instRepository.findByIcdConfigTypeId(configType.getId()); diff --git a/src/main/java/com/xydl/cac/task/AsyncTask.java b/src/main/java/com/xydl/cac/task/AsyncTask.java index 12c6efe..454402e 100644 --- a/src/main/java/com/xydl/cac/task/AsyncTask.java +++ b/src/main/java/com/xydl/cac/task/AsyncTask.java @@ -33,6 +33,8 @@ public class AsyncTask { WebSocketServer webSocketServer; @Resource BizConfig bizConfig; + @Resource + WarningRepository warningRepository; @Async public void collectIed(String xml, IcdIed ied, List rptList, List dlList) { @@ -40,7 +42,8 @@ public class AsyncTask { instRepository, rptparamindexRepository, dlRecordService, dataService, xml, ied, - webSocketServer, bizConfig); + webSocketServer, bizConfig, + warningRepository); iedService.collectAndSave(rptList, dlList); } } diff --git a/src/main/java/com/xydl/cac/task/Client61850Task.java b/src/main/java/com/xydl/cac/task/Client61850Task.java index cc2b768..3bc20bc 100644 --- a/src/main/java/com/xydl/cac/task/Client61850Task.java +++ b/src/main/java/com/xydl/cac/task/Client61850Task.java @@ -2,6 +2,7 @@ package com.xydl.cac.task; import com.xydl.cac.entity.*; import com.xydl.cac.iec.IecClient; +import com.xydl.cac.iec.NetErrorThread; import com.xydl.cac.model.StaticVariable; import com.xydl.cac.repository.*; import com.xydl.cac.service.ModevTypeService; @@ -144,6 +145,8 @@ public class Client61850Task { ied.setConnected(true); } catch (Exception ex) { ied.setConnected(false); + NetErrorThread thread = new NetErrorThread(ied.getId()); + thread.start(); } finally { iecClient.disconnect(); } From acff760020259bbba2056d959e23aab046289e4c Mon Sep 17 00:00:00 2001 From: huangfeng Date: Tue, 31 Dec 2024 13:50:25 +0800 Subject: [PATCH 3/3] fix --- src/main/java/com/xydl/cac/task/Client61850Task.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/xydl/cac/task/Client61850Task.java b/src/main/java/com/xydl/cac/task/Client61850Task.java index 3bc20bc..d43f726 100644 --- a/src/main/java/com/xydl/cac/task/Client61850Task.java +++ b/src/main/java/com/xydl/cac/task/Client61850Task.java @@ -111,6 +111,9 @@ public class Client61850Task { @Scheduled(initialDelay = 60 * 1000, fixedDelay = 60 * 1000) private void testAll() { + if (!enable) { + return; + } List iedTestList = new ArrayList<>(); List icdFileList = fileRepository.findAll(); if (!CollectionUtils.isEmpty(icdFileList)) {