From 781e72ac16249003751f11d82a36f127d0ba255d Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 24 十二月 2024 11:55:28 +0800
Subject: [PATCH] 增加缓存,提高计算点当前值查询速度

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
index c97aa8b..bd0a697 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -10,6 +10,7 @@
 import com.iailab.module.data.channel.kio.collector.KingIOCollector;
 import com.iailab.module.data.channel.modbus.collector.ModBusCollector;
 import com.iailab.module.data.channel.opcua.collector.OpcUaCollector;
+import com.iailab.module.data.point.collection.PointCollector;
 import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils;
 import com.iailab.module.data.point.common.PointDataTypeEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
@@ -19,6 +20,7 @@
 import javax.annotation.Resource;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
@@ -57,6 +59,9 @@
 
     @Resource
     private DaPointService daPointService;
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
 
     public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) {
         log.info("测量点处理开始");
@@ -178,7 +183,9 @@
                 item -> {
                     try {
                         Object value = CommonConstant.BAD_VALUE;
-                        if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) {
+                        if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) {
+                            value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo());
+                        } else if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) {
                             value = opcUaCollector.getTagValue(item.getSourceId(), item.getTagNo());
                         } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) {
                             value = modBusCollector.getTagValue(item.getSourceId(), item.getTagNo());
@@ -186,12 +193,13 @@
                             value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo());
                         } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
                             value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType());
+                            // 存入缓存
+                            redisTemplate.opsForValue().set(PointCollector.PV + item.getPointNo(), value, PointCollector.offset);
                         } else {
                             log.info("没有匹配的TagNo=" + item.getTagNo());
                         }
-                        log.info("没有匹配的TagNo=" + item.getTagNo());
-                        log.info("valueStr=" + value.toString());
-                        log.info("DataType=" + item.getDataType());
+
+                        log.info("TagNo=" + item.getTagNo() + ",value=" + value.toString());
                         if (!PointDataTypeEnum.BOOLEAN.getCode().equals(item.getDataType())) {
                             BigDecimal decValue =  new BigDecimal(value.toString());
                             if (PointDataTypeEnum.FLOAT.getCode().equals(item.getDataType())) {

--
Gitblit v1.9.3