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/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/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/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 b16d749..d43f726 100644 --- a/src/main/java/com/xydl/cac/task/Client61850Task.java +++ b/src/main/java/com/xydl/cac/task/Client61850Task.java @@ -1,6 +1,9 @@ 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; import lombok.extern.slf4j.Slf4j; @@ -106,4 +109,49 @@ 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)) { + 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); + NetErrorThread thread = new NetErrorThread(ied.getId()); + thread.start(); + } finally { + iecClient.disconnect(); + } + } }