diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index 3478468..3014469 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -1,5 +1,6 @@ package com.xydl.cac.iec; +import com.beanit.iec61850bean.BasicDataAttribute; import com.xydl.cac.entity.*; import com.xydl.cac.repository.IcdConfigTypeAttRepository; import com.xydl.cac.repository.IcdConfigTypeInstRepository; @@ -26,6 +27,7 @@ public class IEDCollectService { WebSocketServer _webSocketServer; public static HashMap> lastDataMap = new HashMap<>(); + public static HashMap relationMap = new HashMap<>(); public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository, IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository, @@ -99,13 +101,16 @@ public class IEDCollectService { time = time.replace("T", " ").replace("Z", "").replace("z", ""); _dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value); - HashMap map = lastDataMap.get(rpt.getEqmid()); - if (map == null) { - map = new HashMap<>(); - lastDataMap.put(rpt.getEqmid(), map); - } - map.put(rpt.getColname(), value); - map.put("acquisitionTime", time); + // 更新最新数据缓存 + updateLastData(rpt.getEqmid(), rpt.getColname(), value, time); + + // 更新关联关系缓存 + String key = paramindexNew + "_" + fc; + value = rpt.getEqmid() + "," + rpt.getColname(); + relationMap.put(key, value); + key = paramindexT + "_" + fc; + value = rpt.getEqmid() + ",acquisitionTime"; + relationMap.put(key, value); } private Rptparamindex findRpt(List rptList, String paramindex) { @@ -116,4 +121,35 @@ public class IEDCollectService { } return null; } + + public static void updateLastData(Integer eqmid, String colname, String value, String time) { + HashMap map = lastDataMap.get(eqmid); + if (map == null) { + map = new HashMap<>(); + lastDataMap.put(eqmid, map); + } + map.put(colname, value); + if (time != null) { + map.put("acquisitionTime", time); + } + } + + public static void updateLastData(BasicDataAttribute bda) { + try { + String ref = bda.getReference().toString(); + String key = ref + "_" + bda.getFc().toString(); + if (IEDCollectService.relationMap.containsKey(key)) { + String value = IEDCollectService.relationMap.get(key); + String[] str = value.split(","); + Integer eqmid = Integer.parseInt(str[0]); + String colname = str[1]; + value = bda.getValueString(); + if ("acquisitionTime".equals(colname)) { + value = value.replace("T", " ").replace("Z", "").replace("z", ""); + } + updateLastData(eqmid, colname, value, null); + } + } catch (Exception ignore) { + } + } } diff --git a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java index 315b204..9f79ec1 100644 --- a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java +++ b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java @@ -135,5 +135,6 @@ public class RealTimeDataService { if (iecServer != null) { iecServer.updateBda(bda); } + IEDCollectService.updateLastData(bda); } }