diff --git a/src/main/java/com/xydl/cac/controller/TestController.java b/src/main/java/com/xydl/cac/controller/TestController.java index 61a2a2d..3cc51e8 100644 --- a/src/main/java/com/xydl/cac/controller/TestController.java +++ b/src/main/java/com/xydl/cac/controller/TestController.java @@ -1,8 +1,8 @@ package com.xydl.cac.controller; import com.xydl.cac.iec.IecClient; -import com.xydl.cac.iec.RealTimeDataService; import com.xydl.cac.model.Response; +import com.xydl.cac.model.StaticVariable; import com.xydl.cac.service.IcdFileConfigService; import com.xydl.cac.socket.WebSocketServer; import io.swagger.annotations.Api; @@ -26,8 +26,6 @@ public class TestController extends BasicController { IcdFileConfigService configService; @Resource WebSocketServer webSocketServer; - @Resource - RealTimeDataService realTimeDataService; @GetMapping("compare61850") @ApiOperation("比对61850的不同点") @@ -45,6 +43,6 @@ public class TestController extends BasicController { @GetMapping("realTimeMap") @ApiOperation("实时订阅Map") public Response> realTimeMap() { - return Response.success(realTimeDataService.clientMap); + return Response.success(StaticVariable.realTimeClientMap); } } diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index 6b4e18e..1a2120f 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -84,6 +84,7 @@ public class IEDCollectService { StaticVariable.doneWarnMap.put(key, "1"); _webSocketServer.sendMessage(err, null); } + RealTimeDataService.onErrorCheck(ied.getId()); } finally { iecClient.disconnect(); } @@ -180,7 +181,11 @@ public class IEDCollectService { } catch (Exception ex) { String err = "61850采集文件异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", path=" + config.getPath(); log.error(err, ex); - _webSocketServer.sendMessage(err, null); + String key = ied.getName() + ied.getIp() + ied.getPort() + config.getPath(); + if (!StaticVariable.doneWarnMap.containsKey(key)) { + StaticVariable.doneWarnMap.put(key, "1"); + _webSocketServer.sendMessage(err, null); + } } } diff --git a/src/main/java/com/xydl/cac/iec/IecClient.java b/src/main/java/com/xydl/cac/iec/IecClient.java index 865aaaf..da222b3 100644 --- a/src/main/java/com/xydl/cac/iec/IecClient.java +++ b/src/main/java/com/xydl/cac/iec/IecClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.nio.charset.StandardCharsets; +import java.util.Date; import java.util.List; @Slf4j @@ -29,6 +30,7 @@ public class IecClient implements ClientEventListener { private RealTimeDataService realTimeDataService; private WebSocketServer webSocketServer; public int retry = 10; + public Date lastReportTime; public IecClient() { } @@ -84,6 +86,7 @@ public class IecClient implements ClientEventListener { clientAssociation.setServerModel(serverModel); log.info("61850订阅断线重连成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort()); retry = 10; + keep = true; } public String getValue(String paramindex, String fc) throws Exception { @@ -108,6 +111,7 @@ public class IecClient implements ClientEventListener { } } log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort()); + keep = true; } public void disableReporting() { @@ -132,6 +136,7 @@ public class IecClient implements ClientEventListener { } else { log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort()); } + keep = false; } public List listFile(String path) throws Exception { @@ -150,6 +155,7 @@ public class IecClient implements ClientEventListener { @Override public void newReport(Report report) { if (report != null) { + lastReportTime = new Date(); RealTimeDataService.processReport(report); } } @@ -157,6 +163,7 @@ public class IecClient implements ClientEventListener { @Override public void associationClosed(IOException e) { if (keep) { + keep = false; this.disableReporting(); this.disconnect(); while (retry > 0) { diff --git a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java index 43cee2c..5f850d4 100644 --- a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java +++ b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java @@ -29,7 +29,6 @@ public class RealTimeDataService { WebSocketServer webSocketServer; public static boolean inDoing = false; - public HashMap clientMap = new HashMap<>(); @PostConstruct private void init() { @@ -60,10 +59,9 @@ public class RealTimeDataService { IecClient iecClient = new IecClient(this, webSocketServer); iecClient.connect(ied, icdFile.getXml()); iecClient.enableReporting(); - iecClient.keep = true; ied.setStart(Constants.TRUE); iedRepository.save(ied); - clientMap.put(ied.getId(), iecClient); + StaticVariable.realTimeClientMap.put(ied.getId(), iecClient); } catch (Exception ex) { String err = "61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort(); log.error(err, ex); @@ -84,13 +82,19 @@ public class RealTimeDataService { } } + public static void onErrorCheck(Integer iedId) { + IecClient iecClient = StaticVariable.realTimeClientMap.get(iedId); + if (iecClient != null) { + iecClient.associationClosed(null); + } + } + private void onlyStop(Integer iedId) { - IecClient iecClient = clientMap.get(iedId); + IecClient iecClient = StaticVariable.realTimeClientMap.get(iedId); if (iecClient != null) { - iecClient.keep = false; iecClient.disableReporting(); iecClient.disconnect(); - clientMap.remove(iedId); + StaticVariable.realTimeClientMap.remove(iedId); } } @@ -98,7 +102,7 @@ public class RealTimeDataService { private void stop() { log.info("关闭61850订阅服务."); List idList = new ArrayList<>(); - Iterator it = clientMap.keySet().iterator(); + Iterator it = StaticVariable.realTimeClientMap.keySet().iterator(); while (it.hasNext()) { idList.add(it.next()); } diff --git a/src/main/java/com/xydl/cac/model/StaticVariable.java b/src/main/java/com/xydl/cac/model/StaticVariable.java index 4738165..e48abb8 100644 --- a/src/main/java/com/xydl/cac/model/StaticVariable.java +++ b/src/main/java/com/xydl/cac/model/StaticVariable.java @@ -4,6 +4,7 @@ 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.iec.IecClient; import com.xydl.cac.iec.IecServer; import java.util.HashMap; @@ -16,6 +17,7 @@ public class StaticVariable { public static HashMap> sensorLastDataMap = new HashMap<>(); public static HashMap paramRelationMap = new HashMap<>(); public static HashMap doneWarnMap = new HashMap<>(); + public static HashMap realTimeClientMap = new HashMap<>(); public static HashMap unit_Cache = new HashMap<>(); public static List modevType_Cache = null;