feat: 缓存采集的最新数据给查询使用

dev
huangfeng 8 months ago
parent 262f0dfcc4
commit cf99f3122d

@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
import javax.persistence.*; import javax.persistence.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ -85,6 +86,9 @@ public class NSensor {
@Transient @Transient
N103Sensor n103Sensor; N103Sensor n103Sensor;
@Transient
HashMap<String, String> lastData;
public String addPoint(NPoint point) { public String addPoint(NPoint point) {
if (points == null) { if (points == null) {
points = new ArrayList<>(); points = new ArrayList<>();

@ -9,6 +9,7 @@ import com.xydl.cac.service.DataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
@ -22,6 +23,8 @@ public class IEDCollectService {
IcdIed ied; IcdIed ied;
String xml; String xml;
public static HashMap<Integer, HashMap<String, String>> lastDataMap = new HashMap<>();
public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository, public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository,
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository, IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
DataService dataService, String xml, IcdIed ied) { DataService dataService, String xml, IcdIed ied) {
@ -89,6 +92,14 @@ public class IEDCollectService {
log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time); log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time);
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) {
map = new HashMap<>();
lastDataMap.put(rpt.getEqmid(), map);
}
map.put(rpt.getColname(), value);
map.put("acquisitionTime", time);
} }
private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) { private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) {

@ -27,7 +27,6 @@ public class RealTimeDataService {
@Resource @Resource
IcdIedRepository iedRepository; IcdIedRepository iedRepository;
public static HashMap<String, String> dataMap = new HashMap<>();
public static IecServer iecServer = null; public static IecServer iecServer = null;
public static boolean inDoing = false; public static boolean inDoing = false;
HashMap<Integer, IecClient> clientMap = new HashMap<>(); HashMap<Integer, IecClient> clientMap = new HashMap<>();
@ -133,9 +132,6 @@ public class RealTimeDataService {
} }
private static void processBdaNodeValue(BasicDataAttribute bda) { private static void processBdaNodeValue(BasicDataAttribute bda) {
String ref = bda.getReference().toString();
String value = bda.getValueString();
dataMap.put(ref, value);
if (iecServer != null) { if (iecServer != null) {
iecServer.updateBda(bda); iecServer.updateBda(bda);
} }

@ -3,6 +3,7 @@ package com.xydl.cac.service.impl;
import com.xydl.cac.entity.*; import com.xydl.cac.entity.*;
import com.xydl.cac.entity.constants.Constants; import com.xydl.cac.entity.constants.Constants;
import com.xydl.cac.exception.BusinessException; import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.iec.IEDCollectService;
import com.xydl.cac.model.ConditionModel; import com.xydl.cac.model.ConditionModel;
import com.xydl.cac.model.OnePage; import com.xydl.cac.model.OnePage;
import com.xydl.cac.model.SensorDetail; import com.xydl.cac.model.SensorDetail;
@ -83,6 +84,8 @@ public class NSensorServiceImpl implements NSensorService {
sensor.setTableName(type.getTablename()); sensor.setTableName(type.getTablename());
} }
} }
HashMap<String, String> map = IEDCollectService.lastDataMap.get(sensor.getDevId());
sensor.setLastData(map);
} }
} }
} }

Loading…
Cancel
Save