From cd069965f32189683598ac1096dab66c992c517b Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 14 三月 2025 16:36:10 +0800
Subject: [PATCH] BAD点值修复

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java |   45 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 7 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 f263bd2..4c5eee6 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
@@ -1,5 +1,6 @@
 package com.iailab.module.data.point.collection;
 
+import com.alibaba.fastjson.JSONObject;
 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;
@@ -77,7 +78,7 @@
 
     public static final String PV = "point_value:";
 
-    public static final long offset = 60 * 3L;
+    public static final long offset = 60 * 2L;
 
     /**
      * 采集
@@ -89,22 +90,51 @@
         try {
             Map<String, Object> dataMap = new HashMap<>();
             List<InfluxPointValuePOJO> pointValues = new ArrayList<>();
-
+            // 记录点位状态
+            List<String> listGood = new ArrayList<>();
+            List<String> listBad = new ArrayList<>();
             log.info("读取常量点");
             List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(minfreq);
-            pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap));
+            pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap, listGood, listBad));
 
             log.info("读取测量点");
             List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq);
-            pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap));
+            pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap, listGood, listBad));
+
+            List<String> listBadNew = new ArrayList<>();
+            if (!CollectionUtils.isEmpty(listBad)) {
+                log.info("BAD点值修复");
+                List<InfluxPointValuePOJO> influxParams = new ArrayList<>();
+                for (String bad : listBad) {
+                    DaPointDTO daPointDTO = daPointService.getByNo(bad);
+                    InfluxPointValuePOJO pojo = new InfluxPointValuePOJO();
+                    pojo.setPoint(bad);
+                    pojo.setType(daPointDTO.getDataType());
+                    influxParams.add(pojo);
+                }
+                Map<String, Object> lastValue = influxDBService.queryPointsLastValue(influxParams);
+                log.info("lastValue=" + JSONObject.toJSONString(lastValue));
+                if (!CollectionUtils.isEmpty(lastValue)) {
+                    for (String bad : listBad) {
+                        if (lastValue.containsKey(bad)) {
+                            listGood.add(bad);
+                            dataMap.put(bad, lastValue.get(bad));
+                        } else {
+                            listBadNew.add(bad);
+                        }
+                    }
+                } else {
+                    listBadNew = listBad;
+                }
+            }
 
             log.info("读取计算点");
             List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq);
-            pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap));
+            pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap, listGood, listBadNew));
 
             log.info("读取累计点");
             List<DaPointDTO> pointCumulateList = daPointService.getCumulatePoint(minfreq);
-            pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList));
+            pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, listGood, listBadNew));
 
             log.info("存入时序库");
             influxDBService.asyncWritePointValues(pointValues);
@@ -123,7 +153,7 @@
                 }
             }
             log.info("更新采集状态");
-            daPointCollectStatusService.recordStatusList(pointValues, collectTime);
+            daPointCollectStatusService.recordStatusList(listGood, listBad, collectTime);
             log.info("采集完成");
         } catch (Exception ex) {
             log.info("采集异常!");
@@ -143,6 +173,7 @@
             data.putAll(cumulateHandle.getCurrent(pointNos));
             return data;
         } catch (Exception ex) {
+            ex.printStackTrace();
             return R.error(ex.getMessage());
         }
 

--
Gitblit v1.9.3