Merge branch 'iec61850' into iec104

dev
huangfeng 6 months ago
commit fccb856cb6

@ -10,6 +10,7 @@ import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.ColumnModel; import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.model.IcdAttUpdateModel; import com.xydl.cac.model.IcdAttUpdateModel;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.repository.IcdIedRepository; import com.xydl.cac.repository.IcdIedRepository;
import com.xydl.cac.service.DataService; import com.xydl.cac.service.DataService;
import com.xydl.cac.service.IcdFileConfigService; import com.xydl.cac.service.IcdFileConfigService;
@ -87,6 +88,12 @@ public class IcdConfigController extends BasicController {
return Response.success(result); return Response.success(result);
} }
@GetMapping("testIed")
@ApiOperation("查询IED连接状态")
public Response<List<IcdIed>> testIed() {
return Response.success(StaticVariable.iedTestList);
}
@PostMapping("update") @PostMapping("update")
@ApiOperation("更新ICD类型配置") @ApiOperation("更新ICD类型配置")
public Response<String> update(@RequestBody IcdConfigType item) throws Exception { public Response<String> update(@RequestBody IcdConfigType item) throws Exception {

@ -15,7 +15,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.net.SocketException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -33,6 +32,7 @@ public class IEDCollectService {
String xml; String xml;
WebSocketServer _webSocketServer; WebSocketServer _webSocketServer;
BizConfig _bizConfig; BizConfig _bizConfig;
WarningRepository _warningRepository;
String folder = "/record"; String folder = "/record";
HashMap<Integer, String> eqmidTimeMap = new HashMap<>(); HashMap<Integer, String> eqmidTimeMap = new HashMap<>();
@ -41,7 +41,8 @@ public class IEDCollectService {
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository, IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
IedDlRecordService dlRecordService, DataService dataService, IedDlRecordService dlRecordService, DataService dataService,
String xml, IcdIed ied, String xml, IcdIed ied,
WebSocketServer webSocketServer, BizConfig bizConfig) { WebSocketServer webSocketServer, BizConfig bizConfig,
WarningRepository warningRepository) {
_configRepository = configRepository; _configRepository = configRepository;
_attRepository = attRepository; _attRepository = attRepository;
_instRepository = instRepository; _instRepository = instRepository;
@ -52,6 +53,7 @@ public class IEDCollectService {
this.ied = ied; this.ied = ied;
_webSocketServer = webSocketServer; _webSocketServer = webSocketServer;
_bizConfig = bizConfig; _bizConfig = bizConfig;
_warningRepository = warningRepository;
iecClient = new IecClient(); iecClient = new IecClient();
} }
@ -82,22 +84,33 @@ public class IEDCollectService {
this.doDownload(dlList); this.doDownload(dlList);
} }
} catch (Exception ex) { } 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); log.error(err, ex);
this.saveWarning(err);
String key = ied.getName() + ied.getIp() + ied.getPort(); String key = ied.getName() + ied.getIp() + ied.getPort();
if (!StaticVariable.doneWarnMap.containsKey(key)) { if (!StaticVariable.doneWarnMap.containsKey(key)) {
StaticVariable.doneWarnMap.put(key, "1"); StaticVariable.doneWarnMap.put(key, "1");
_webSocketServer.sendMessage(err, null); _webSocketServer.sendMessage(err, null);
} }
if (ex instanceof SocketException) {
NetErrorThread thread = new NetErrorThread(ied.getId());
thread.start();
}
} finally { } finally {
iecClient.disconnect(); 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<IcdConfigType> configTypeList, List<Rptparamindex> rptList) throws Exception { private void doCollectAndSave(List<IcdConfigType> configTypeList, List<Rptparamindex> rptList) throws Exception {
for (IcdConfigType configType : configTypeList) { for (IcdConfigType configType : configTypeList) {
List<IcdConfigTypeInst> instList = _instRepository.findByIcdConfigTypeId(configType.getId()); List<IcdConfigTypeInst> instList = _instRepository.findByIcdConfigTypeId(configType.getId());

@ -1,11 +1,7 @@
package com.xydl.cac.model; package com.xydl.cac.model;
import com.fazecast.jSerialComm.SerialPort;
import com.beanit.iec61850bean.BasicDataAttribute; import com.beanit.iec61850bean.BasicDataAttribute;
import com.xydl.cac.entity.Jg; import com.xydl.cac.entity.*;
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.IecClient;
import com.xydl.cac.iec.IecServer; import com.xydl.cac.iec.IecServer;
import com.xydl.cac.util.DateUtil; import com.xydl.cac.util.DateUtil;
@ -20,6 +16,7 @@ public class StaticVariable {
public static HashMap<String, String> paramRelationMap = new HashMap<>(); public static HashMap<String, String> paramRelationMap = new HashMap<>();
public static HashMap<String, String> doneWarnMap = new HashMap<>(); public static HashMap<String, String> doneWarnMap = new HashMap<>();
public static HashMap<Integer, IecClient> realTimeClientMap = new HashMap<>(); public static HashMap<Integer, IecClient> realTimeClientMap = new HashMap<>();
public static List<IcdIed> iedTestList = new ArrayList<>();
public static int shutdown = 0; public static int shutdown = 0;
public static HashMap<String, String> rptFromActiveMap = new HashMap<>(); public static HashMap<String, String> rptFromActiveMap = new HashMap<>();
public static HashMap<String, String> rptToActiveMap = new HashMap<>(); public static HashMap<String, String> rptToActiveMap = new HashMap<>();
@ -31,16 +28,6 @@ public class StaticVariable {
public static ConcurrentHashMap<Integer, WarnRule> rule_Cache = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Integer, WarnRule> 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) { public static void updateServerNodeValue(BasicDataAttribute bda) {
Iterator<Integer> it = StaticVariable.iecServerMap.keySet().iterator(); Iterator<Integer> it = StaticVariable.iecServerMap.keySet().iterator();

@ -33,6 +33,8 @@ public class AsyncTask {
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@Resource @Resource
BizConfig bizConfig; BizConfig bizConfig;
@Resource
WarningRepository warningRepository;
@Async @Async
public void collectIed(String xml, IcdIed ied, List<Rptparamindex> rptList, List<IedDlConfig> dlList) { public void collectIed(String xml, IcdIed ied, List<Rptparamindex> rptList, List<IedDlConfig> dlList) {
@ -40,7 +42,8 @@ public class AsyncTask {
instRepository, rptparamindexRepository, instRepository, rptparamindexRepository,
dlRecordService, dataService, dlRecordService, dataService,
xml, ied, xml, ied,
webSocketServer, bizConfig); webSocketServer, bizConfig,
warningRepository);
iedService.collectAndSave(rptList, dlList); iedService.collectAndSave(rptList, dlList);
} }
} }

@ -1,6 +1,9 @@
package com.xydl.cac.task; package com.xydl.cac.task;
import com.xydl.cac.entity.*; 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.repository.*;
import com.xydl.cac.service.ModevTypeService; import com.xydl.cac.service.ModevTypeService;
import lombok.extern.slf4j.Slf4j; 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<IcdIed> iedTestList = new ArrayList<>();
List<IcdFile> icdFileList = fileRepository.findAll();
if (!CollectionUtils.isEmpty(icdFileList)) {
for (IcdFile icdFile : icdFileList) {
this.testOneFile(icdFile, iedTestList);
}
}
StaticVariable.iedTestList = iedTestList;
}
private void testOneFile(IcdFile icdFile, List<IcdIed> iedTestList) {
if (shutdown == 1) {
return;
}
List<IcdIed> 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();
}
}
} }

Loading…
Cancel
Save