From 140065f50679c04ea873db3f6c958358b8dd8ddc Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 24 十二月 2024 14:35:43 +0800
Subject: [PATCH] 计算点修复负数计算问题

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java |   25 +++++++++++++++++++++----
 1 files changed, 21 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 bd0a697..482c718 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
@@ -26,6 +26,7 @@
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 测量点处理
@@ -182,8 +183,9 @@
         pointMeasureList.forEach(
                 item -> {
                     try {
+                        boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo());
                         Object value = CommonConstant.BAD_VALUE;
-                        if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) {
+                        if (hasKey) {
                             value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo());
                         } else if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) {
                             value = opcUaCollector.getTagValue(item.getSourceId(), item.getTagNo());
@@ -193,12 +195,9 @@
                             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() + ",value=" + value.toString());
                         if (!PointDataTypeEnum.BOOLEAN.getCode().equals(item.getDataType())) {
                             BigDecimal decValue =  new BigDecimal(value.toString());
@@ -211,6 +210,11 @@
                         } else {
                             data.put(item.getPointNo(), value);
                         }
+
+                        if (!hasKey) {
+                            // 存入缓存
+                            toRedis(value, item);
+                        }
                     } catch (Exception ex) {
                         ex.printStackTrace();
                     }
@@ -219,4 +223,17 @@
         );
         return data;
     }
+
+    public void toRedis(Object value, DaPointDTO point) {
+        if (PointDataTypeEnum.FLOAT.getCode().equals(point.getDataType())) {
+            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), new BigDecimal(value.toString()).intValue(),
+                    PointCollector.offset, TimeUnit.SECONDS);
+        } else if (PointDataTypeEnum.INT.getCode().equals(point.getDataType())) {
+            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), new BigDecimal(value.toString()).doubleValue(),
+                    PointCollector.offset, TimeUnit.SECONDS);
+        } else if (PointDataTypeEnum.BOOLEAN.getCode().equals(point.getDataType())) {
+            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), Boolean.parseBoolean(value.toString()),
+                    PointCollector.offset, TimeUnit.SECONDS);
+        }
+    }
 }

--
Gitblit v1.9.3