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/PointCollector.java |   50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
index 7bd34be..c7475c9 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
@@ -3,11 +3,15 @@
 import com.iailab.module.data.common.enums.DataSourceType;
 import com.iailab.module.data.common.utils.R;
 import com.iailab.module.data.channel.kio.collector.KingIOCollector;
+import com.iailab.module.data.influxdb.pojo.InfluxPointValueBoolPOJO;
+import com.iailab.module.data.influxdb.pojo.InfluxPointValueDigPOJO;
+import com.iailab.module.data.influxdb.pojo.InfluxPointValueSimPOJO;
 import com.iailab.module.data.point.collection.handler.CalculateHandle;
+import com.iailab.module.data.point.collection.handler.CumulateHandle;
 import com.iailab.module.data.point.common.PointTypeEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
+import com.iailab.module.data.point.service.DaPointCollectStatusService;
 import com.iailab.module.data.point.service.DaPointService;
-import com.iailab.module.data.channel.http.collector.HttpCollectorForZxzk;
 import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
 import com.iailab.module.data.channel.modbus.collector.ModBusCollector;
 import com.iailab.module.data.channel.opcua.collector.OpcUaCollector;
@@ -16,7 +20,11 @@
 import com.iailab.module.data.point.dto.DaPointWriteValueDTO;
 import com.iailab.module.data.influxdb.service.InfluxDBService;
 import lombok.extern.slf4j.Slf4j;
+
 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,7 +65,17 @@
     private OpcUaCollector opcUaCollector;
 
     @Resource
-    private HttpCollectorForZxzk httpCollectorForZxzk;
+    private CumulateHandle cumulateHandle;
+
+    @Autowired
+    private DaPointCollectStatusService daPointCollectStatusService;
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    public static final String PV = "PV_";
+
+    public static final int offset = 60 * 3;
 
     /**
      * 采集
@@ -70,27 +88,42 @@
             Map<String, Object> dataMap = new HashMap<>();
             List<InfluxPointValuePOJO> pointValues = new ArrayList<>();
 
-            // 读取常量点
             log.info("读取常量点");
             List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(minfreq);
             pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap));
 
-            // 读取测量点
             log.info("读取测量点");
             List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq);
             pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap));
 
-            // 读取计算点
             log.info("读取计算点");
             List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq);
             pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap));
 
-            // 存入数据库
-            log.info("存入数据库");
+            log.info("读取累计点");
+            List<DaPointDTO> pointCumulateList = daPointService.getCumulatePoint(minfreq);
+            pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList));
+
+            log.info("存入时序库");
             influxDBService.asyncWritePointValues(pointValues);
 
+            log.info("存入缓存");
+            for (InfluxPointValuePOJO pointValue : pointValues) {
+                if (pointValue instanceof InfluxPointValueSimPOJO) {
+                    InfluxPointValueSimPOJO simPOJO = (InfluxPointValueSimPOJO) pointValue;
+                    redisTemplate.opsForValue().set(PV + simPOJO.getPoint(), simPOJO.getValue(), offset);
+                } else if (pointValue instanceof InfluxPointValueDigPOJO) {
+                    InfluxPointValueDigPOJO digPOJO = (InfluxPointValueDigPOJO) pointValue;
+                    redisTemplate.opsForValue().set(PV + digPOJO.getPoint(), digPOJO.getValue(), offset);
+                } else if (pointValue instanceof InfluxPointValueBoolPOJO) {
+                    InfluxPointValueBoolPOJO boolPOJO = (InfluxPointValueBoolPOJO) pointValue;
+                    redisTemplate.opsForValue().set(PV + boolPOJO.getPoint(), boolPOJO.getValue(), offset);
+                }
+            }
+            log.info("更新采集状态");
+            daPointCollectStatusService.recordStatusList(pointValues, collectTime);
             log.info("采集完成");
-        } catch (Exception ex)  {
+        } catch (Exception ex) {
             log.info("采集异常!");
             ex.printStackTrace();
         }
@@ -105,6 +138,7 @@
             data.putAll(constantHandle.getCurrent(pointNos));
             data.putAll(measureHandle.getCurrent(pointNos));
             data.putAll(calculateHandle.getCurrent(pointNos));
+            data.putAll(cumulateHandle.getCurrent(pointNos));
             return data;
         } catch (Exception ex) {
             return R.error(ex.getMessage());

--
Gitblit v1.9.3