feat: 采集的数据也更新到服务端

main
huangfeng 6 months ago
parent 734747240c
commit 1ae46c69ae

@ -116,23 +116,30 @@ public class IEDCollectService {
} }
private void collectAndSaveValue(String paramindexNew, String paramindexT, String fc, Rptparamindex rpt) throws Exception { private void collectAndSaveValue(String paramindexNew, String paramindexT, String fc, Rptparamindex rpt) throws Exception {
String value = iecClient.getValue(paramindexNew, fc); // 更新关联关系缓存
String time = iecClient.getValue(paramindexT, fc); String key = paramindexNew + "_" + fc;
String value = rpt.getEqmid() + "," + rpt.getColname();
StaticVariable.paramRelationMap.put(key, value);
key = paramindexT + "_" + fc;
value = rpt.getEqmid() + ",acquisitionTime";
StaticVariable.paramRelationMap.put(key, value);
// 采集数据
BasicDataAttribute valueNode = iecClient.getNode(paramindexNew, fc);
BasicDataAttribute timeNode = iecClient.getNode(paramindexT, fc);
value = valueNode.getValueString();
String time = timeNode.getValueString();
log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time); log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time);
time = DateUtil.fromZoneUTCToLocal(time); time = DateUtil.fromZoneUTCToLocal(time);
time = this.makeSameTime(rpt.getEqmid(), time); time = this.makeSameTime(rpt.getEqmid(), time);
_dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value); _dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value);
// 更新最新数据缓存 // 更新最新数据缓存
updateLastData(rpt.getEqmid(), rpt.getColname(), value, time); StaticVariable.updateLastData(rpt.getEqmid(), rpt.getColname(), value, time);
// 更新关联关系缓存 // 更新服务端
String key = paramindexNew + "_" + fc; StaticVariable.updateServerNodeValue(valueNode);
value = rpt.getEqmid() + "," + rpt.getColname(); StaticVariable.updateServerNodeValue(timeNode);
StaticVariable.paramRelationMap.put(key, value);
key = paramindexT + "_" + fc;
value = rpt.getEqmid() + ",acquisitionTime";
StaticVariable.paramRelationMap.put(key, value);
} }
private String makeSameTime(Integer eqmid, String time) { private String makeSameTime(Integer eqmid, String time) {
@ -229,34 +236,4 @@ public class IEDCollectService {
} }
} }
public static void updateLastData(Integer eqmid, String colname, String value, String time) {
HashMap<String, String> map = StaticVariable.sensorLastDataMap.get(eqmid);
if (map == null) {
map = new HashMap<>();
StaticVariable.sensorLastDataMap.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 (StaticVariable.paramRelationMap.containsKey(key)) {
String value = StaticVariable.paramRelationMap.get(key);
String[] str = value.split(",");
Integer eqmid = Integer.parseInt(str[0]);
String colname = str[1];
value = bda.getValueString();
if ("acquisitionTime".equals(colname)) {
value = DateUtil.fromZoneUTCToLocal(value);
}
updateLastData(eqmid, colname, value, null);
}
} catch (Exception ignore) {
}
}
} }

@ -95,14 +95,21 @@ public class IecClient implements ClientEventListener {
} }
public String getValue(String paramindex, String fc) throws Exception { public String getValue(String paramindex, String fc) throws Exception {
BasicDataAttribute node = this.getNode(paramindex, fc);
if (node != null) {
return node.getValueString();
}
return null;
}
public BasicDataAttribute getNode(String paramindex, String fc) throws Exception {
FcModelNode node = (FcModelNode) serverModel.findModelNode(paramindex, Fc.valueOf(fc)); FcModelNode node = (FcModelNode) serverModel.findModelNode(paramindex, Fc.valueOf(fc));
if (node == null) { if (node == null) {
throw new BusinessException("icd文件里未找到该节点, " + fc + " " + paramindex); throw new BusinessException("icd文件里未找到该节点, " + fc + " " + paramindex);
} }
clientAssociation.getDataValues(node); clientAssociation.getDataValues(node);
if (node instanceof BasicDataAttribute) { if (node instanceof BasicDataAttribute) {
String value = ((BasicDataAttribute) node).getValueString(); return (BasicDataAttribute) node;
return value;
} }
return null; return null;
} }

@ -131,14 +131,16 @@ public class RealTimeDataService {
for (ModelNode child : fcnode.getChildren()) { for (ModelNode child : fcnode.getChildren()) {
if (child instanceof BasicDataAttribute) { if (child instanceof BasicDataAttribute) {
BasicDataAttribute bda = (BasicDataAttribute) child; BasicDataAttribute bda = (BasicDataAttribute) child;
processBdaNodeValue(bda); StaticVariable.updateServerNodeValue(bda);
StaticVariable.updateLastData(bda);
} else if (child instanceof ConstructedDataAttribute) { } else if (child instanceof ConstructedDataAttribute) {
ConstructedDataAttribute cda = (ConstructedDataAttribute) child; ConstructedDataAttribute cda = (ConstructedDataAttribute) child;
if (!CollectionUtils.isEmpty(cda.getChildren())) { if (!CollectionUtils.isEmpty(cda.getChildren())) {
for (ModelNode cchild : cda.getChildren()) { for (ModelNode cchild : cda.getChildren()) {
if (cchild instanceof BasicDataAttribute) { if (cchild instanceof BasicDataAttribute) {
BasicDataAttribute bda = (BasicDataAttribute) cchild; BasicDataAttribute bda = (BasicDataAttribute) cchild;
processBdaNodeValue(bda); StaticVariable.updateServerNodeValue(bda);
StaticVariable.updateLastData(bda);
} }
} }
} }
@ -148,13 +150,4 @@ public class RealTimeDataService {
} }
} }
private static void processBdaNodeValue(BasicDataAttribute bda) {
Iterator<Integer> it = StaticVariable.iecServerMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
IecServer iecServer = StaticVariable.iecServerMap.get(key);
iecServer.updateBda(bda);
}
IEDCollectService.updateLastData(bda);
}
} }

@ -1,13 +1,16 @@
package com.xydl.cac.model; package com.xydl.cac.model;
import com.beanit.iec61850bean.BasicDataAttribute;
import com.xydl.cac.entity.Jg; import com.xydl.cac.entity.Jg;
import com.xydl.cac.entity.ModevType; import com.xydl.cac.entity.ModevType;
import com.xydl.cac.entity.WarnRule; import com.xydl.cac.entity.WarnRule;
import com.xydl.cac.entity.Zsb; 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 java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -34,4 +37,47 @@ public class StaticVariable {
Thread.sleep(1000); Thread.sleep(1000);
} }
} }
// 更新服务端
public static void updateServerNodeValue(BasicDataAttribute bda) {
Iterator<Integer> it = StaticVariable.iecServerMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
IecServer iecServer = StaticVariable.iecServerMap.get(key);
iecServer.updateBda(bda);
}
}
// 更新最新数据缓存
public static void updateLastData(Integer eqmid, String colname, String value, String time) {
HashMap<String, String> map = StaticVariable.sensorLastDataMap.get(eqmid);
if (map == null) {
map = new HashMap<>();
StaticVariable.sensorLastDataMap.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 (StaticVariable.paramRelationMap.containsKey(key)) {
String value = StaticVariable.paramRelationMap.get(key);
String[] str = value.split(",");
Integer eqmid = Integer.parseInt(str[0]);
String colname = str[1];
value = bda.getValueString();
if ("acquisitionTime".equals(colname)) {
value = DateUtil.fromZoneUTCToLocal(value);
}
updateLastData(eqmid, colname, value, null);
}
} catch (Exception ignore) {
}
}
} }

Loading…
Cancel
Save