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(); + } + } }