From 6a9cf62f7ca4b45c48a571c63fd484c186070a0e Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期五, 19 一月 2024 23:53:12 +0800
Subject: [PATCH] 增加油罐仓的解析2

---
 src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 108 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
index b21e3ff..e7af6a7 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
@@ -2,11 +2,14 @@
 
 import com.alibaba.fastjson2.JSONObject;
 import com.fzzy.api.data.PushProtocol;
+import com.fzzy.api.utils.NumberUtil;
 import com.fzzy.async.fzzy40.entity.Fz40Grain;
 import com.fzzy.data.ConfigData;
+import com.fzzy.gateway.GatewayUtils;
 import com.fzzy.gateway.api.GatewayDeviceReportService;
 import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.GrainCableData;
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.hx2023.ScConstant;
 import com.fzzy.gateway.hx2023.data.*;
@@ -177,16 +180,17 @@
         result.setMaxTemperature(grainData.getTempMax() + "");
         result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss"));
 
-        //灞�-琛�-鍒�
-        String[] attrCable = grainData.getCable().split("-");
-        if (StringUtils.isNotEmpty(grainData.getCableCir())) {
-            return grainData2GatewayApiInfo2(grainData, device);
+
+        GrainCableData cableData = GatewayUtils.getCableData(device);
+
+        if(cableData.isCir()){
+            return grainData2GatewayApiInfo2(grainData, device,cableData);
         }
 
         //灞傝鍒�
-        int cableZ = Integer.valueOf(attrCable[0]);
-        int cableY = Integer.valueOf(attrCable[1]);
-        int cableX = Integer.valueOf(attrCable[2]);
+        int cableZ = cableData.getCableZ();
+        int cableY = cableData.getCableY();
+        int cableX = cableData.getCableX();
 
         //娓╁害闆嗗悎
         String[] attr = grainData.getPoints().split(",");
@@ -265,8 +269,104 @@
         return resp;
     }
 
-    private BaseResp grainData2GatewayApiInfo2(Fz40Grain grainData, GatewayDevice device) {
+    private BaseResp grainData2GatewayApiInfo2(Fz40Grain grainData, GatewayDevice device,GrainCableData cableData) {
         BaseResp resp = new BaseResp();
+
+//        int cableZ = cableData.getCableZ();
+//        int cableY = cableData.getCableY();
+//        int cableX = cableData.getCableX();
+//
+//        int sumNum = cableData.getSumNum();
+//
+//        //鏁版嵁灏佽
+//        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(ScConstant.getMessageId());
+//        grain.setHeaders(headers);
+//
+//
+//        GrainOutPut outPut = new GrainOutPut();
+//
+//
+//        double max = com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MAX_TEMP, min = com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MIN_TEMP, sumT = 0.0;
+//
+//        List<GrainTemp> temperature = new ArrayList<>();
+//        //鏍瑰彿
+//        int cableNum = 1, position = 0;
+//
+//        double curTemp;
+//        int x = 0, y = 0, z = 0;
+//        for (int i = 0; i < sumNum; i++) {
+//            curTemp = temps.get(i);
+//            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 + ""));
+//
+//            //姹傛渶澶ф渶灏忓��
+//            if (curTemp < -900) {
+//                sumNum--;
+//            } else {
+//                sumT += curTemp;
+//                if (curTemp > max) {
+//                    max = curTemp;
+//                }
+//                if (curTemp < min) {
+//                    min = curTemp;
+//                }
+//            }
+//        }
+//
+//        if (sumNum == 0) {
+//            sumNum = 1;
+//            log.warn("---褰撳墠绮儏閲囬泦寮傚父--");
+//        }
+//        //杩囨护姣旇緝鐢ㄧ殑鏈�澶ф渶灏忓��
+//        if (max == com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MAX_TEMP) {
+//            max = 0.0;
+//        }
+//        if (min == com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder.MIN_TEMP) {
+//            min = 0.0;
+//        }
+//
+//        outPut.setTemperature(temperature);
+//        outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
+//        outPut.setMinTemperature(min + "");
+//        outPut.setMaxTemperature(min + "");
+//
+//
+//        com.alibaba.fastjson.JSONObject properties = new com.alibaba.fastjson.JSONObject();
+//        properties.put("data", com.alibaba.fastjson.JSONObject.toJSONString(outPut));
+//        properties.put("timestamp", grain.getTimestamp());
+//
+//        String height = this.getCacheHeight(device);
+//        if (org.apache.commons.lang3.StringUtils.isEmpty(height)) height = "0.0";
+//        properties.put("liquidHeight", height);
+//
+//        grain.setProperties(properties.toJSONString());
+//
+//        //灏佽濂界殑鏁版嵁
+//        log.info("---娴呭渾浠撳皝瑁呭畬鎴�----寮�濮嬫墽琛屾帹閫�");
+
+
+
+
+
+
+
         resp.setCode(BaseResp.CODE_500);
         resp.setMsg("绛掍粨瑙f瀽鏆傛湭瀹炵幇");
         return resp;

--
Gitblit v1.9.3