feat: 把订阅到的数据更新到实时缓存

dev
huangfeng 8 months ago
parent 688225150a
commit ee41eaf575

@ -1,5 +1,6 @@
package com.xydl.cac.iec; package com.xydl.cac.iec;
import com.beanit.iec61850bean.BasicDataAttribute;
import com.xydl.cac.entity.*; import com.xydl.cac.entity.*;
import com.xydl.cac.repository.IcdConfigTypeAttRepository; import com.xydl.cac.repository.IcdConfigTypeAttRepository;
import com.xydl.cac.repository.IcdConfigTypeInstRepository; import com.xydl.cac.repository.IcdConfigTypeInstRepository;
@ -26,6 +27,7 @@ public class IEDCollectService {
WebSocketServer _webSocketServer; WebSocketServer _webSocketServer;
public static HashMap<Integer, HashMap<String, String>> lastDataMap = new HashMap<>(); public static HashMap<Integer, HashMap<String, String>> lastDataMap = new HashMap<>();
public static HashMap<String, String> relationMap = new HashMap<>();
public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository, public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository,
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository, IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
@ -99,13 +101,16 @@ public class IEDCollectService {
time = time.replace("T", " ").replace("Z", "").replace("z", ""); time = time.replace("T", " ").replace("Z", "").replace("z", "");
_dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value); _dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value);
HashMap<String, String> map = lastDataMap.get(rpt.getEqmid()); // 更新最新数据缓存
if (map == null) { updateLastData(rpt.getEqmid(), rpt.getColname(), value, time);
map = new HashMap<>();
lastDataMap.put(rpt.getEqmid(), map); // 更新关联关系缓存
} String key = paramindexNew + "_" + fc;
map.put(rpt.getColname(), value); value = rpt.getEqmid() + "," + rpt.getColname();
map.put("acquisitionTime", time); relationMap.put(key, value);
key = paramindexT + "_" + fc;
value = rpt.getEqmid() + ",acquisitionTime";
relationMap.put(key, value);
} }
private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) { private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) {
@ -116,4 +121,35 @@ public class IEDCollectService {
} }
return null; return null;
} }
public static void updateLastData(Integer eqmid, String colname, String value, String time) {
HashMap<String, String> 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) {
}
}
} }

@ -135,5 +135,6 @@ public class RealTimeDataService {
if (iecServer != null) { if (iecServer != null) {
iecServer.updateBda(bda); iecServer.updateBda(bda);
} }
IEDCollectService.updateLastData(bda);
} }
} }

Loading…
Cancel
Save