From 76743b009ca5ea67557fcab597b332f8d1947813 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期二, 24 十二月 2024 14:09:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 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 41299ec..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
@@ -1,5 +1,6 @@
 package com.iailab.module.data.point.collection.handler;
 
+import com.iailab.module.data.channel.http.collector.SourceApiEnum;
 import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd;
 import com.iailab.module.data.channel.opcda.collector.OpcDACollector;
 import com.iailab.module.data.common.enums.CommonConstant;
@@ -9,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;
@@ -18,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 +60,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("测量点处理开始");
         List<InfluxPointValuePOJO> result = new ArrayList<>();
@@ -81,8 +87,10 @@
             } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) {
                 kioTagIds.add(new String[]{item.getSourceId(), item.getTagNo()});
             } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
-                if (CommonConstant.iHyperDB.equals(item.getSourceName())) {
-                    httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()});
+                if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) {
+                    if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) {
+                        httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()});
+                    }
                 }
             }
         });
@@ -101,7 +109,7 @@
             tagValues.putAll(kingIOCollector.getTagValues(kioTagIds));
         }
         if (!CollectionUtils.isEmpty(httpTagIhd)) {
-            tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd));
+            tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd, collectTime));
         }
         this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
         log.info("测量点处理结束");
@@ -132,12 +140,17 @@
     private Object handleData(DaPointDTO dto, Object value) {
         Object result = value;
         try {
+            if (value == null) {
+                return CommonConstant.BAD_VALUE;
+            }
             if (DataTypeEnum.FLOAT.getCode().equals(dto.getDataType()) || DataTypeEnum.INT.getCode().equals(dto.getDataType())) {
                 BigDecimal rawValue = new BigDecimal(value.toString());
-
+                if(CommonConstant.BAD_VALUE.compareTo(rawValue) == 0) {
+                    return CommonConstant.BAD_VALUE;
+                }
                 // 异常值处理
                 if (rawValue.compareTo(maxValue) > 0 || rawValue.compareTo(minValue) < 0) {
-                    rawValue = CommonConstant.BAD_VALUE;
+                    return CommonConstant.BAD_VALUE;
                 }
                 BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor();
                 BigDecimal calValue = rawValue.multiply(coefficient);
@@ -156,7 +169,6 @@
             } else if (DataTypeEnum.BOOLEAN.getCode().equals(dto.getDataType())) {
                 result = Boolean.parseBoolean(value.toString());
             }
-
         } catch (Exception ex) {
             log.warn("handleData异常,PointNo=" + dto.getPointNo());
             ex.printStackTrace();
@@ -171,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());
@@ -179,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