diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index 5d81d77..ba525e6 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -116,23 +116,30 @@ public class IEDCollectService { } 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); time = DateUtil.fromZoneUTCToLocal(time); time = this.makeSameTime(rpt.getEqmid(), time); _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; - value = rpt.getEqmid() + "," + rpt.getColname(); - StaticVariable.paramRelationMap.put(key, value); - key = paramindexT + "_" + fc; - value = rpt.getEqmid() + ",acquisitionTime"; - StaticVariable.paramRelationMap.put(key, value); + // 更新服务端 + StaticVariable.updateServerNodeValue(valueNode); + StaticVariable.updateServerNodeValue(timeNode); } 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 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) { - } - } } diff --git a/src/main/java/com/xydl/cac/iec/IecClient.java b/src/main/java/com/xydl/cac/iec/IecClient.java index 025aeca..bb76c7a 100644 --- a/src/main/java/com/xydl/cac/iec/IecClient.java +++ b/src/main/java/com/xydl/cac/iec/IecClient.java @@ -95,14 +95,21 @@ public class IecClient implements ClientEventListener { } 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)); if (node == null) { throw new BusinessException("icd文件里未找到该节点, " + fc + " " + paramindex); } clientAssociation.getDataValues(node); if (node instanceof BasicDataAttribute) { - String value = ((BasicDataAttribute) node).getValueString(); - return value; + return (BasicDataAttribute) node; } return null; } diff --git a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java index 65d5378..f12f63c 100644 --- a/src/main/java/com/xydl/cac/iec/RealTimeDataService.java +++ b/src/main/java/com/xydl/cac/iec/RealTimeDataService.java @@ -131,14 +131,16 @@ public class RealTimeDataService { for (ModelNode child : fcnode.getChildren()) { if (child instanceof BasicDataAttribute) { BasicDataAttribute bda = (BasicDataAttribute) child; - processBdaNodeValue(bda); + StaticVariable.updateServerNodeValue(bda); + StaticVariable.updateLastData(bda); } else if (child instanceof ConstructedDataAttribute) { ConstructedDataAttribute cda = (ConstructedDataAttribute) child; if (!CollectionUtils.isEmpty(cda.getChildren())) { for (ModelNode cchild : cda.getChildren()) { if (cchild instanceof BasicDataAttribute) { 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 it = StaticVariable.iecServerMap.keySet().iterator(); - while (it.hasNext()) { - Integer key = it.next(); - IecServer iecServer = StaticVariable.iecServerMap.get(key); - iecServer.updateBda(bda); - } - IEDCollectService.updateLastData(bda); - } } diff --git a/src/main/java/com/xydl/cac/model/StaticVariable.java b/src/main/java/com/xydl/cac/model/StaticVariable.java index 7789776..a890995 100644 --- a/src/main/java/com/xydl/cac/model/StaticVariable.java +++ b/src/main/java/com/xydl/cac/model/StaticVariable.java @@ -1,13 +1,16 @@ package com.xydl.cac.model; +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.iec.IecClient; import com.xydl.cac.iec.IecServer; +import com.xydl.cac.util.DateUtil; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -34,4 +37,47 @@ public class StaticVariable { Thread.sleep(1000); } } + + // 更新服务端 + public static void updateServerNodeValue(BasicDataAttribute bda) { + Iterator 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 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) { + } + } }