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/fzzy/analysis/AnalysisGrain.java |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 156 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java
index 6e02d70..dd5a3b2 100644
--- a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java
+++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java
@@ -2,7 +2,18 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.fzzy.api.data.ApiCommonDevice;
+import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.api.utils.NumberUtil;
+import com.fzzy.gateway.GatewayUtils;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
+import com.fzzy.gateway.api.GatewayRemoteManager;
 import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.WeatherWebDto;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.ScConstant;
+import com.fzzy.gateway.hx2023.data.*;
+import com.fzzy.protocol.ProtocolUtils;
 import com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder;
 import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl;
 import com.fzzy.protocol.fzzy.data.ReMessage;
@@ -10,7 +21,12 @@
 import com.fzzy.protocol.fzzy.resp.Response2102;
 import com.fzzy.protocol.fzzy.server.ServerUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 绮儏瑙f瀽
@@ -20,6 +36,9 @@
 @Slf4j
 @Component(AnalysisGrain.BEAN_ID)
 public class AnalysisGrain extends BaseRemoteImpl {
+
+    @Resource
+    private GatewayRemoteManager gatewayRemoteManager;
 
     public static final String BEAN_ID = "fzzy.analysisGrain";
 
@@ -48,14 +67,16 @@
 
             Response2102 response = JSONObject.parseObject(reMessage.getContent(), Response2102.class);
 
-            String depotId = response.getHouseId();
-
-            //鑾峰彇璇锋眰淇℃伅
-            BaseReqData reqData = ServerUtils.getSyncReq(depotId);
-
 
             //绮儏瑙f瀽
-            log.info("鎺у埗鏌�--->骞冲彴绮儏淇℃伅--{}", response);
+            log.info("鎺у埗鏌�--->骞冲彴锛屾帶鍒舵煖杩斿洖绮儏妫�娴嬬粨鏋�--{}", response);
+
+            //绮儏灏佽鍜屽鐞�
+            if (StringUtils.isEmpty(response.getLayerPerCircle())) {
+                buildBizInfo1(response);
+            } else {
+                buildBizInfo2(response);
+            }
 
 
         } catch (Exception e) {
@@ -65,6 +86,135 @@
         }
     }
 
+    private void buildBizInfo2(Response2102 response) {
+        //TODO 绛掍粨鐨勫皝瑁呰В鏋愬緟澶勭悊
+    }
+
+    //淇℃伅璋冩暣灏佽
+    private void buildBizInfo1(Response2102 response) {
+
+        //鑾峰彇璇锋眰淇℃伅
+        BaseReqData reqData = ProtocolUtils.getSyncReq(response.getHouseId());
+        log.info("--绮儏灏佽瑙f瀽锛岃幏鍙栧埌璇锋眰鍛戒护鍙傛暟----");
+        if (null == reqData) {
+            log.error("--绮儏灏佽瑙f瀽锛屾湭鑾峰彇鍒拌姹傜浉鍏冲弬鏁�----");
+            return;
+        }
+        ProtocolUtils.delSyncReq(response.getHouseId());
+        log.info(reqData.toString());
+
+        int cableZ = Integer.valueOf(response.getLay());
+        int cableY = Integer.valueOf(response.getRow());
+        int cableX = Integer.valueOf(response.getCol());
+
+        GatewayDevice device = reqData.getDevice();
+
+        //鏁版嵁灏佽
+        GrainData grain = new GrainData();
+        grain.setMessageId(ScConstant.getMessageId());
+        grain.setDeviceId(device.getDeviceId());
+        grain.setTimestamp(System.currentTimeMillis() + "");
+
+        ClientHeaders headers = new ClientHeaders();
+        headers.setDeviceName(device.getDeviceName());
+        headers.setProductId(device.getProductId());
+        headers.setOrgId(device.getOrgId());
+        headers.setMsgId(reqData.getMessageId());
+        grain.setHeaders(headers);
+
+        GrainOutPut outPut = new GrainOutPut();
+
+        outPut.setAvgTemperature(response.getTAvg() + "");
+        outPut.setMinTemperature(response.getTMin() + "");
+        outPut.setMaxTemperature(response.getTMax() + "");
+
+
+        List<GrainTemp> temperature = new ArrayList<>();
+        //鏍瑰彿
+        int cableNum = 1, position = 0;
+
+        double curTemp;
+        String[] attr = response.getPoints().split(",");
+        int x = 0, y = 0, z = 0;
+        for (int i = 0; i < attr.length; i++) {
+            curTemp = Double.valueOf(attr[i]);
+
+            if (curTemp < -900) {
+                curTemp = ERROR_CHECK_TAG;
+            }
+
+            //鏁版嵁浼樺寲
+            if (curTemp > 40) {
+                curTemp = response.getTAvg();
+            }
+
+            position = i;
+            z = i % cableZ + 1;
+            x = i / (cableZ * cableY);
+            y = x * (cableZ * cableY);
+            y = (i - y) / cableZ;
+            //鏍瑰彿
+            cableNum = (i / cableZ) + 1;
+
+            temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
+        }
+
+        outPut.setTemperature(temperature);
+        List<GrainTH> ths = new ArrayList<>();
+
+        ths.add(new GrainTH(response.getTIn()!=null?response.getTIn()+"":"",response.getHIn()!=null?response.getHIn()+"":"","1"));
+        outPut.setTemperatureAndhumidity(ths);
+        //grain.setOutput(JSONObject.toJSONString(outPut));
+        grain.setOutput(com.alibaba.fastjson2.JSONObject.toJSONString(outPut));
+
+
+        GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode());
+
+
+        //绯荤粺姘旇薄绔欎俊鎭�
+        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
+
+        //姘旇薄淇℃伅
+        GrainWeather weatherStation = new GrainWeather();
+        weatherStation.setMessageId(ScConstant.getMessageId());
+        weatherStation.setMessgeId(weatherStation.getMessageId());
+
+        if (null != gatewayDeviceWeather) {
+            weatherStation.setId(gatewayDeviceWeather.getDeviceId());
+        } else {
+            weatherStation.setId(device.getDeviceId());
+        }
+        weatherStation.setAirPressure(weather.getPressure());
+        weatherStation.setHumidity(weather.getHumidity().replaceAll("%",""));
+        weatherStation.setPm(weather.getAir_pm25());
+        weatherStation.setRadiation("0");
+        weatherStation.setRainfallAmount(weather.getWea());
+        weatherStation.setTemperature(weather.getTem());
+        weatherStation.setWindDirection(weather.getWin());
+        weatherStation.setWindPower(weather.getWin_meter());
+        weatherStation.setWindSpeed(weather.getWin_speed());
+        grain.setWeatherStation(JSONObject.toJSONString(weatherStation));
+
+
+        //灏佽濂界殑鏁版嵁
+        log.info("---绮儏鏈烘灏佽瀹屾垚----寮�濮嬫墽琛屾帹閫�");
+
+        reqData.setData(JSONObject.toJSONString(grain));
+        doPushGrain(reqData,grain);
+    }
+
+    private void doPushGrain(BaseReqData reqData,GrainData grainData) {
+
+        GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol());
+        if (null == reportService) {
+            log.error("------------绮儏鎺ㄩ�佸け璐ワ紝绯荤粺涓嶅瓨鍦ㄥ綋鍓嶅崗璁墽琛岀被----{}", reqData.getDevice().getDeviceName());
+            return;
+        }
+        reportService.reportGrainData(reqData);
+        reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData());
+        reportService.reportGrainDataByKafka(reqData);
+    }
+
     private void returnMsg(ApiCommonDevice ser) {
         //鍏堝洖澶嶆帶鍒舵煖
         SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();

--
Gitblit v1.9.3