From 6495040bbda5308c86e852ad1b080097bfa916a9 Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期三, 09 七月 2025 09:22:17 +0800
Subject: [PATCH] 优化粮温检测

---
 src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java |   87 +++++++++++++++++++++++++++----------------
 1 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java
index 3c22d41..f03bd01 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/analysis/AnalysisService.java
@@ -201,13 +201,13 @@
         int sumNum = cableData.getSumNum();
 
         // 鏍规嵁灞傝鍒楄幏鍙栨寚瀹氶暱搴�
-        int start = 0;
+        int start = (Integer.valueOf(device.getCableStart()) - 1) *  cableData.getCableZ()  * 4;
         int len = 4 * sumNum;
 
         log.info("鍒嗘満------>>>骞冲彴锛氳繑鍥炵伯鎯呭畬鏁翠俊鎭紝鍒嗘満={}", device.getDeviceName());
 
         String strPoints = grainStr.substring(start, start + len);
-
+        log.info("strPoints = "+ strPoints);
         // 灏嗙伯鎯呰В鏋愭垚鏁扮粍
         List<Double> temps = new ArrayList<>();
         double tempValue;
@@ -277,8 +277,8 @@
         int cableZ = cableData.getCableZ();
         int cableY = cableData.getCableY();
 
-        int sumNum = temps.size();
-
+        int sumNum = 0;
+        log.info("temps:" + temps.toString());
         //鏁版嵁灏佽
         GrainData grain = new GrainData();
         grain.setMessageId(ScConstant.getMessageId());
@@ -304,7 +304,7 @@
 
         double curTemp;
         int x = 0, y = 0, z = 0;
-        for (int i = 0; i < sumNum; i++) {
+        for (int i = 0; i < temps.size(); i++) {
             curTemp = temps.get(i);
             position = i;
 
@@ -317,17 +317,27 @@
 
             temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
 
-            //姹傛渶澶ф渶灏忓��
-            if (curTemp < -900) {
-                sumNum--;
-            } else {
+//            //姹傛渶澶ф渶灏忓��
+//            if (curTemp < -900) {
+//            //    sumNum--;
+//            } else {
+//                sumT += curTemp;
+//                if (curTemp > max) {
+//                    max = curTemp;
+//                }
+//                if (curTemp < min) {
+//                    min = curTemp;
+//                }
+//            }
+            if (curTemp > max  && curTemp < 40) {
+                max = curTemp;
+            }
+            if (curTemp < min && curTemp > 3) {
+                min = curTemp;
+            }
+            if(curTemp > 3 &&  curTemp < 40){
                 sumT += curTemp;
-                if (curTemp > max) {
-                    max = curTemp;
-                }
-                if (curTemp < min) {
-                    min = curTemp;
-                }
+                sumNum++;
             }
         }
 
@@ -346,7 +356,7 @@
         outPut.setTemperature(temperature);
         outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
         outPut.setMinTemperature(min + "");
-        outPut.setMaxTemperature(min + "");
+        outPut.setMaxTemperature(max + "");
 
 
         JSONObject properties = new JSONObject();
@@ -376,7 +386,7 @@
             weatherStation.setId(device.getDeviceId());
         }
         weatherStation.setAirPressure(weather.getPressure());
-        weatherStation.setHumidity(weather.getHumidity());
+        weatherStation.setHumidity(weather.getHumidity().replaceAll("%",""));
         weatherStation.setPm(weather.getAir_pm25());
         weatherStation.setRadiation("0");
         weatherStation.setRainfallAmount(weather.getWea());
@@ -392,7 +402,7 @@
         grain.setProperties(properties);
         reqData.setData(JSONObject.toJSONString(grain));
 
-        doPushGrain(reqData);
+        doPushGrain(reqData,grain);
     }
 
     /**
@@ -448,8 +458,7 @@
         GrainOutPut outPut = new GrainOutPut();
 
 
-        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableX
-                * cableY * cableZ;
+        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = 0;
 
         List<GrainTemp> temperature = new ArrayList<>();
         //鏍瑰彿
@@ -470,16 +479,26 @@
             temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
 
             //姹傛渶澶ф渶灏忓��
-            if (curTemp < -900) {
-                sumNum--;
-            } else {
+//            if (curTemp < -900) {
+//                sumNum--;
+//            } else {
+//                sumT += curTemp;
+//                if (curTemp > max) {
+//                    max = curTemp;
+//                }
+//                if (curTemp < min) {
+//                    min = curTemp;
+//                }
+//            }
+            if (curTemp > max  && curTemp < 40) {
+                max = curTemp;
+            }
+            if (curTemp < min && curTemp > 3) {
+                min = curTemp;
+            }
+            if(curTemp > 3 &&  curTemp < 40){
                 sumT += curTemp;
-                if (curTemp > max) {
-                    max = curTemp;
-                }
-                if (curTemp < min) {
-                    min = curTemp;
-                }
+                sumNum++;
             }
         }
 
@@ -498,7 +517,7 @@
         outPut.setTemperature(temperature);
         outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
         outPut.setMinTemperature(min + "");
-        outPut.setMaxTemperature(min + "");
+        outPut.setMaxTemperature(max + "");
         List<GrainTH> ths = new ArrayList<>();
 
         ths.add(new GrainTH(thDto.getTempIn() != null ? thDto.getTempIn() + "" : "", thDto.getHumidityIn() != null ? thDto.getHumidityIn() + "" : "", "1"));
@@ -521,7 +540,7 @@
             weatherStation.setId(device.getDeviceId());
         }
         weatherStation.setAirPressure(weather.getPressure());
-        weatherStation.setHumidity(weather.getHumidity());
+        weatherStation.setHumidity(weather.getHumidity().replaceAll("%",""));
         weatherStation.setPm(weather.getAir_pm25());
         weatherStation.setRadiation("0");
         weatherStation.setRainfallAmount(weather.getWea());
@@ -537,10 +556,10 @@
 
         reqData.setData(JSONObject.toJSONString(grain));
 
-        doPushGrain(reqData);
+        doPushGrain(reqData,grain);
     }
 
-    private void doPushGrain(BaseReqData reqData) {
+    private void doPushGrain(BaseReqData reqData,GrainData grainData) {
 
         GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol());
         if (null == reportService) {
@@ -548,6 +567,8 @@
             return;
         }
         reportService.reportGrainData(reqData);
+        reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData());
+        reportService.reportGrainDataByKafka(reqData);
     }
 
 

--
Gitblit v1.9.3