From d6f1c42e4f06494557f6253b4f946cc477145375 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期一, 28 八月 2023 16:32:19 +0800
Subject: [PATCH] 更新MODBUS-TCP协议,协议解析3

---
 igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java |   87 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
index e069867..0cff6e1 100644
--- a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
+++ b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
@@ -1,17 +1,24 @@
 package com.ld.igds.protocol.modbus.command;
 
 import com.ld.igds.common.CoreDeviceService;
+import com.ld.igds.constant.BizType;
+import com.ld.igds.gas.CoreGasService;
 import com.ld.igds.io.constant.OrderRespEnum;
 import com.ld.igds.io.notify.NotifyWebInvoker;
 import com.ld.igds.io.request.CheckGasRequest;
 import com.ld.igds.io.request.DeviceControlRequest;
+import com.ld.igds.models.Gas;
 import com.ld.igds.protocol.modbus.ServerUtil;
 import com.ld.igds.protocol.modbus.data.ModbusGasResult;
+import com.ld.igds.util.ContextUtil;
+import com.ld.igds.util.NumberUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,6 +32,8 @@
     private CoreDeviceService coreDeviceService;
     @Resource
     private NotifyWebInvoker notifyInvoker;
+    @Autowired
+    private CoreGasService gasService;
 
 
     /**
@@ -58,5 +67,83 @@
      * @param results
      */
     public void analysisGas(CheckGasRequest request, List<ModbusGasResult> results) {
+
+        log.debug("----------寮�濮嬫墽琛屾皵浣撶粨鏋滆В鏋�----{}", request.getDepotId());
+
+        String batchId = ContextUtil.getDefaultBatchId();
+        //涓讳綋淇℃伅
+        Gas gas = new Gas(batchId, request.getCompanyId(), request.getDepotId(), new Date());
+        gas.setCheckNum(results.size());
+        gas.setGasEnd(results.size());
+        gas.setGasStart(1);
+        gas.setReceiveDate(new Date());
+
+        int sumNum = results.size();
+        double co2, o2, ph3, n2;
+        double sumO2 = 0.0, sumCo2 = 0.0, sumPh3 = 0.0, sumN2 = 0.0;
+        StringBuffer sb = new StringBuffer();
+        for (ModbusGasResult gasResult : results) {
+            co2 = gasResult.getCo2().doubleValue();
+            o2 = gasResult.getO2().doubleValue();
+            ph3 = gasResult.getPh3().doubleValue();
+            n2 = -100;
+
+            //TODO >>>>> 鏍规嵁杩斿洖鍊艰繘琛屽垽鏂拰杞崲
+
+
+            if (gas.getPerCo2Max() < co2) {
+                gas.setPerCo2Max(co2);
+            }
+            if (gas.getPerCo2Min() > co2) {
+                gas.setPerCo2Min(co2);
+            }
+            if (gas.getPerO2Max() < o2) {
+                gas.setPerO2Max(o2);
+            }
+            if (gas.getPerO2Min() > o2) {
+                gas.setPerO2Min(o2);
+            }
+            if (gas.getPerPh3Max() < ph3) {
+                gas.setPerPh3Max(ph3);
+            }
+            if (gas.getPerPh3Min() > ph3) {
+                gas.setPerPh3Min(ph3);
+            }
+            if (gas.getPerN2Max() < n2) {
+                gas.setPerN2Max(n2);
+            }
+            if (gas.getPerN2Min() > n2) {
+                gas.setPerN2Min(n2);
+            }
+
+            //鍥哄畾涓猴細passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;"
+            sb.append(gasResult.getPasscode());
+            sb.append(",");
+            sb.append(co2);
+            sb.append(",");
+            sb.append(o2);
+            sb.append(",");
+            sb.append(ph3);
+            sb.append(",");
+            sb.append(n2);
+            sb.append(";");
+
+            sumCo2 += co2;
+            sumO2 += o2;
+            sumPh3 += ph3;
+            sumN2 += n2;
+
+        }
+        gas.setPoints(sb.toString());
+        gas.setPerCo2(NumberUtil.keepPrecision(sumCo2 / sumNum, 2));
+        gas.setPerO2(NumberUtil.keepPrecision(sumO2 / sumNum, 2));
+        gas.setPerN2(NumberUtil.keepPrecision(sumN2 / sumNum, 2));
+        gas.setPerPh3(NumberUtil.keepPrecision(sumPh3 / sumNum, 2));
+
+        gasService.saveOrUpdateData(gas);
+
+        // 璋冪敤閫氱煡鍓嶇
+        notifyInvoker.notifyWeb(gas.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GAS, request.getDepotId() + " 姘斾綋妫�娴嬶細缁撴灉杩斿洖鎴愬姛.");
+        log.info("鎺у埗鏌�----->>>骞冲彴锛氭皵浣撹В鏋愬畬鎴�-浠撳簱={}", request.getDepotId());
     }
 }

--
Gitblit v1.9.3