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/v0/analysis/AnalysisService.java |   94 +++++++++++++++++++++++++++++------------------
 1 files changed, 58 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
index 2f8cb56..fad300a 100644
--- a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
+++ b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
@@ -108,19 +108,19 @@
     private void analysisGrain(IoMessage message) {
         try {
             //鏍规嵁鍒嗘満SN鑾峰彇璁惧閰嶇疆淇℃伅
-            GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(message.getAddr());
+            GatewayDevice gatewayDevice = BhznGrainV0ServerUtils.contextOrder;
             if (null == gatewayDevice) {
                 replayGrain(message);
                 log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺璁惧閰嶇疆淇℃伅锛�" + message.getAddr());
                 return;
             }
             //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅
-            ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
-            if (commonDevice == null) {
-                replayGrain(message);
-                log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr());
-                return;
-            }
+//            ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
+//            if (commonDevice == null) {
+//                replayGrain(message);
+//                log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr());
+//                return;
+//            }
 
             //鑾峰彇璇锋眰淇℃伅
             BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys());
@@ -188,7 +188,7 @@
         String hexStr = CommandBuild.getMsgGrainReply(message.getAddr());
         log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炵伯鎯呮姤鏂囨敹鍒颁俊鎭紝鎶ユ枃={}", hexStr);
 
-        BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
+        BhznGrainV0ServerEngine.pushByMin(hexStr);
     }
 
     /**
@@ -280,7 +280,7 @@
         int cableY = cableData.getCableY();
         int cableX = cableData.getCableX();
 
-        int sumNum = temps.size();
+        int sumNum = 0;
 
         //鏁版嵁灏佽
         GrainData grain = new GrainData();
@@ -307,7 +307,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;
 
@@ -321,16 +321,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++;
             }
         }
 
@@ -349,7 +359,7 @@
         outPut.setTemperature(temperature);
         outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
         outPut.setMinTemperature(min + "");
-        outPut.setMaxTemperature(min + "");
+        outPut.setMaxTemperature(max + "");
 
 
         JSONObject properties = new JSONObject();
@@ -367,7 +377,7 @@
 
         reqData.setData(JSONObject.toJSONString(grain));
 
-        doPushGrain(reqData);
+        doPushGrain(reqData,grain);
     }
 
     /**
@@ -415,7 +425,7 @@
         GrainOutPut outPut = new GrainOutPut();
 
 
-        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableData.getSumNum();
+        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum =0;
 
         List<GrainTemp> temperature = new ArrayList<>();
         //鏍瑰彿
@@ -437,16 +447,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++;
             }
         }
 
@@ -465,7 +485,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"));
@@ -488,7 +508,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());
@@ -504,10 +524,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) {
@@ -515,6 +535,8 @@
             return;
         }
         reportService.reportGrainData(reqData);
+        reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData());
+        reportService.reportGrainDataByKafka(reqData);
     }
 
 
@@ -562,7 +584,7 @@
         } finally {
             String hexStr = CommandBuild.getMsgTHReply(message.getAddr());
             log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炰粨娓╀粨婀挎敹鍒颁俊鎭紝鎶ユ枃={}", hexStr);
-            BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
+            BhznGrainV0ServerEngine.pushByMin(hexStr);
         }
     }
 

--
Gitblit v1.9.3