From d52037b84cd6689b1cc03b47a5cd43fcb6b7342f Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期二, 26 九月 2023 21:23:51 +0800
Subject: [PATCH] 贝博粮情解析1

---
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java       |   13 
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java |    4 
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java     |    3 
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessageBuilder.java   |   58 ++++
 igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java             |    3 
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessage.java          |   37 ++
 igds-web/pom.xml                                                                                   |    8 
 igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java   |  657 ++++++++++++++++++++++++++++++++++++++++++----
 8 files changed, 705 insertions(+), 78 deletions(-)

diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java
index ab545e1..1dc5ca5 100644
--- a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java
@@ -43,7 +43,7 @@
             Thread.sleep(3000);
 
             //鐢熸垚绮儏鍛戒护
-            String hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), request.getDepotId());
+            String hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId());
 
             InvokeResult result = beibo.send(BytesUtil.hexStrToBytes(hexStr));
 
@@ -51,7 +51,6 @@
 
             // 灏佽杩斿洖淇℃伅
             if (InvokeResult.SUCCESS == result) {
-
                 String key = RedisConst.buildKey(request.getCompanyId(), "GRAIN_BEIBO");
                 redisUtil.set(key, request.getDepotId());
                 return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java
index ed6fedd..0191804 100644
--- a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java
@@ -2,19 +2,27 @@
 
 import com.ld.igds.common.CoreCommonService;
 import com.ld.igds.common.CoreSerService;
-import com.ld.igds.common.dto.THDto;
 import com.ld.igds.constant.BizType;
+import com.ld.igds.constant.Constant;
+import com.ld.igds.constant.DepotType;
 import com.ld.igds.grain.GrainUtil;
+import com.ld.igds.grain.dto.GrainItemInfo;
+import com.ld.igds.io.constant.OrderRespEnum;
 import com.ld.igds.io.notify.NotifyGrainInvoker;
 import com.ld.igds.models.DepotConf;
 import com.ld.igds.models.DeviceSer;
 import com.ld.igds.models.DicSysConf;
+import com.ld.igds.models.Grain;
 import com.ld.igds.order.ExeOrderService;
 import com.ld.igds.order.data.ExeRequest;
+import com.ld.igds.protocol.beibo.grain.builder.ReMessage;
+import com.ld.igds.protocol.beibo.grain.builder.ReMessageBuilder;
 import com.ld.igds.protocol.beibo.grain.util.BeiboGrainServerUtils;
+import com.ld.igds.util.BytesUtil;
 import com.ld.igds.util.ContextUtil;
 import com.ld.igds.warn.WarnUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -23,22 +31,11 @@
 /**
  * 鍗忚瑙f瀽
  *
- * @author vince
+ * @author czt
  */
 @Slf4j
 @Component(AnalysisService.BEAN_ID)
 public class AnalysisService {
-
-
-    /**
-     * 閽堝鍒嗗寘绮儏鎶ユ枃杩涜灏佽
-     */
-    public static Map<String, String> contextMapGrain = new HashMap<>();
-
-    /**
-     * 鐢ㄤ簬瀛樻斁杩斿洖鐨勪粨娓╀粨婀夸俊鎭�
-     */
-    public static Map<String, THDto> contextMapTH = new HashMap<>();
 
     public static final String BEAN_ID = "beiboGrain.analysisService";
 
@@ -55,71 +52,603 @@
     @Autowired
     private ExeOrderService exeOrderService;
 
+
+    public static Map<String, Map<String, String>> contextMap = new HashMap<>();
+
+    public static double ERROR_CHECK_TAG = -100.0;
+
+    public static double FAULT_CHECK_TAG = 85.0;
+
+    public static double ERROR_CHECK_TAG2 = 50;
+
+    public static double MAX_TEMP = -50.0;
+    public static double MIN_TEMP = 50.0;
+
     /**
+     * 00000000FFEB90FEAA 41 E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      *
      * @param result
      */
-    public void analysis(String result){
-        log.info("璐濆崥鍒嗘満------->>骞冲彴锛氫俊鎭姤鏂�={}", result);
-        if(!result.startsWith(BeiboGrainServerUtils.MSG_START)){
-            log.error("璐濆崥鍒嗘満------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ細鎶ユ枃璧峰绗﹂敊璇紝涓嶈В鏋�");
-        }
-        //鍘婚櫎璧峰绗�
-        result = result.substring(9*2-1);
+    public void analysis(String result) {
 
-        analysisGrain(result);
+        log.info("鍒嗘満------->>骞冲彴锛氫俊鎭姤鏂�={}", result);
+        ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(result);
+
+        if (!BeiboGrainServerUtils.MSG_START.startsWith(reMessage.getStartStr())) {
+            log.error("鍒嗘満------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ細鎶ユ枃璧峰绗�={}閿欒锛屼笉瑙f瀽", reMessage.getStartStr());
+        }
+
+
+        //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅
+        DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), reMessage.getSerId());
+        if (ser == null) {
+            log.error("鍒嗘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + reMessage.getSerId());
+            return;
+        }
+
+        List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId());
+        if (null == list || list.isEmpty()) {
+            String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍒版墍灞炰粨搴撲俊鎭��";
+            log.error("鍒嗘満------>>>骞冲彴锛�" + info);
+            notifyGrainInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, info);
+            return;
+        }
+
+        ExeRequest exeRequest = list.get(0);
+        log.info("鑾峰彇绮儏鍛戒护淇℃伅={}", exeRequest);
+        if (null == exeRequest) {
+            String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍘嗗彶鍛戒护銆�";
+            log.error("璐濆崥鍒嗘満------>>>骞冲彴锛�" + info);
+            return;
+        }
+
+        DepotConf depotConf = commonService.getCacheDepotConf(
+                exeRequest.getCompanyId(), exeRequest.getDepotId());
+        if (null == depotConf) {
+            String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍒扮伯鎯呭弬鏁伴厤缃俊鎭��";
+            log.error("鍒嗘満------>>>骞冲彴锛�" + info);
+            notifyGrainInvoker.notifyWeb(ser.getCompanyId(),
+                    OrderRespEnum.MSG_ERROR, BizType.GRAIN, info);
+            return;
+        }
+
+        // 棣栧厛鑾峰彇鍒扮郴缁熷弬鏁帮紝鍒ゆ柇鏄惁闇�瑕佹壒娆¤嚜鍔ㄤ紭鍖�
+        DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId());
+
+        reMessage.setCompanyId(ser.getCompanyId());
+        analysisGrain(depotConf, reMessage, ser, exeRequest, sysConf);
     }
 
 
-    private void analysisGrain(String result) {
-        try {
+    private void analysisGrain(DepotConf depotConf, ReMessage reMessage, DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) {
+        // 绮儏鐨勬壒娆″彿閲嶆柊鏍规嵁棰戠巼璋冩暣
+        reMessage.setBatchId(ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq()));
+        String grainStr = reMessage.getGrainStr();
 
-            //鎴彇鍒嗘満鍦板潃
-            String serId = result.substring(0, 2);
-            //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅
-            DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(),serId);
-            if (ser == null) {
-                log.error("璐濆崥鍒嗘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + serId);
-                return;
-            }
-
-            // 棣栧厛鑾峰彇鍒扮郴缁熷弬鏁帮紝鍒ゆ柇鏄惁闇�瑕佹壒娆¤嚜鍔ㄤ紭鍖�
-            DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId());
-            List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId());
-
-            if (null == list || list.isEmpty()) {
-                String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍒版墍灞炰粨搴撲俊鎭��";
-                log.error("璐濆崥鍒嗘満------>>>骞冲彴锛�" + info);
-                return;
-            }
-
-            //鑾峰彇閽堝褰撳墠浠撳簱鐨勫懡浠�
-            ExeRequest exeRequest = list.get(0);
-            if (null == exeRequest) {
-                String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍘嗗彶鍛戒护銆�";
-                log.error("璐濆崥鍒嗘満------>>>骞冲彴锛�" + info);
-                return;
-            }
-
-            DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId());
-
-            if (null == depotConf) {
-                String info = "绮儏瑙f瀽澶辫触:鍒嗘満=" + ser.getName() + "娌℃湁鑾峰彇鍒扮伯鎯呭弬鏁伴厤缃俊鎭��";
-                log.error("璐濆崥鍒嗘満------>>>骞冲彴锛�" + info);
-                return;
-            }
-
-            // 绮儏鐨勬壒娆″彿閲嶆柊鏍规嵁棰戠巼璋冩暣
-            String batchId = ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq());
-
-            //TODO 鏍规嵁瀹為檯鎶ユ枃锛屽緟瀹炵幇
+        log.debug("{}-{}=鏀跺埌鐨勭伯鎯呬俊鎭�={}", ser.getCompanyId(), ser.getName(), grainStr);
 
 
+        analysisStep0(depotConf, reMessage, ser, exeRequest, sysConf);
 
+        log.info("鍒嗘満------>>>骞冲彴锛氬懡浠ょ被鍨�=8817--绮儏鍏ㄩ儴鏀跺埌锛屽紑濮嬭В鏋�-{}-{}",
+                ser.getCompanyId(), ser.getName());
+    }
 
+    private void analysisStep0(DepotConf depotConf, ReMessage reMessage,
+                               DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) {
 
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
+        List<DepotConf> depotConfs = null;
+
+        // 涓�鍒嗘満澶氫粨锛屾妸璧峰鍒楁斁鍒版渶澶ц繘琛岄噰闆�
+        if (Constant.YN_Y.equals(sysConf.getGrainMoreTag())) {
+            depotConfs = commonService.getCacheDepotConfBySerId2(
+                    depotConf.getCompanyId(), ser.getId());
         }
+
+        if (null == depotConfs) {// 涓�涓垎鏈�1涓粨
+            if (DepotType.TYPE_02.getCode().equals(depotConf.getDepotType())) {
+                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
+            } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) {
+                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
+            } else {
+                analysisStep1(depotConf, ser, exeRequest, reMessage, sysConf);
+            }
+
+            return;
+        }
+
+        // 涓�鍒嗗嚑澶氫粨鎯呭喌锛岃�冭檻鍗曚粨閲囬泦鍜屽浠撻噰闆�
+        // 鍗曚粨閲囬泦鏃跺�欐暟鎹粠0杩斿洖
+        if (StringUtils.isEmpty(exeRequest.getDepotIds())) {
+
+            depotConf.setCableEnd(depotConf.getCableEnd() - depotConf.getCableStart() + 1);
+            depotConf.setCableStart(ser.getCableStart());
+
+            if (DepotType.TYPE_02.getCode().equals(depotConf.getDepotType())) {
+                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
+            } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) {
+                analysisStep2(depotConf, ser, exeRequest, reMessage, sysConf);
+            } else {
+                analysisStep1(depotConf, ser, exeRequest, reMessage, sysConf);
+            }
+
+            return;
+
+        }
+
+        // 鎵归噺閲囬泦鎵�鏈夊叧鑱斾竴璧烽噰闆嗭紝閬嶅巻鎵ц
+        for (DepotConf depotConfTemp : depotConfs) {
+            if (DepotType.TYPE_02.getCode().equals(depotConfTemp.getDepotType())) {
+                analysisStep2(depotConfTemp, ser, exeRequest, reMessage, sysConf);
+            } else if (DepotType.TYPE_04.getCode().equals(depotConfTemp.getDepotType())) {
+                analysisStep2(depotConfTemp, ser, exeRequest, reMessage, sysConf);
+            } else {
+                analysisStep1(depotConfTemp, ser, exeRequest, reMessage, sysConf);
+            }
+        }
+    }
+
+    /**
+     * 鍦嗙瓛浠撶殑绮儏瑙f瀽
+     *
+     * @param depotConf
+     * @param ser
+     * @param exeRequest
+     * @param reMessage
+     */
+    private void analysisStep2(DepotConf depotConf,
+                               DeviceSer ser, ExeRequest exeRequest,
+                               ReMessage reMessage, DicSysConf sysConf) {
+        if (StringUtils.isEmpty(depotConf.getCableRule())
+                || StringUtils.isEmpty(depotConf.getCableCir())) {
+            log.error("鍒嗘満------>>>骞冲彴锛氬綋鍓嶄粨搴擄細{}-{}锛屾病鏈夋病鏈夐厤缃竷绾胯鍒欙紝鏃犳硶瑙f瀽绮儏淇℃伅鈥︹��",
+                    ser.getCompanyId(), depotConf.getDepotName());
+            return;
+        }
+
+        String[] cableRuleAtt = depotConf.getCableRule().split("-");
+        String[] cableCirAtt = depotConf.getCableCir().split("-");
+
+        if (cableRuleAtt.length != cableCirAtt.length) {
+            log.error("鍒嗘満------>>>骞冲彴锛氬綋鍓嶄粨搴擄細{}-{}锛屽竷绾胯鍒欎笉姝g‘锛屾棤娉曡В鏋愮伯鎯呬俊鎭�︹��", ser.getCompanyId(), depotConf.getDepotName());
+            return;
+        }
+
+
+        //閬垮厤绌烘寚閽�
+        if (null == depotConf.getCableCone()) depotConf.setCableCone(Constant.CABLE_CONE_0);
+
+        // 鑾峰彇鏈�澶х殑灞傞厤缃�--榛樿姣忎竴鍦堥兘涓�鏍�
+        int layMax = Integer.valueOf(cableCirAtt[0]);
+        for (int i = 0; i < cableCirAtt.length; i++) {
+            if (Integer.valueOf(cableCirAtt[i]) >= layMax) layMax = Integer.valueOf(cableCirAtt[i]);
+        }
+
+        //绮儏淇℃伅
+        String strPoints = reMessage.getGrainStr();
+
+        log.info("------绛掍粨绮儏鎶ユ枃={}------", strPoints);
+
+        int sumNum = 0, cableZ = 1;// sumNum 鍏卞灏戞牴鐢电紗锛沜ableZ 灞傜殑鏈�澶у�硷紝閿ュ舰浠撹ˉ榻愭渶澶у眰
+        for (int i = 0; i < cableCirAtt.length; i++) {
+            if (Integer.valueOf(cableCirAtt[i]) > cableZ) {
+                cableZ = Integer.valueOf(cableCirAtt[i]);
+            }
+            sumNum += Integer.valueOf(cableRuleAtt[i]);
+        }
+
+        // 鏍规嵁灞傝鍒楄幏鍙栨寚瀹氶暱搴�
+        int start = 4 * (depotConf.getCableStart() - ser.getCableStart()) * cableZ;
+        int len = 4 * cableZ * sumNum;
+
+        strPoints = strPoints.substring(start, start + len);
+        log.info("鍒嗘満------>>>骞冲彴锛氳繑鍥炵伯鎯呭畬鏁翠俊鎭紝鎵�灞炵粍缁�={}锛屽垎鏈�={}", ser.getCompanyId(), ser.getName());
+
+        // 灏嗙伯鎯呰В鏋愭垚鏁扮粍
+        List<Double> temps = new ArrayList<>();
+        double tempValue;
+        String temp;
+        int curLay = 1;//鎵�鍦ㄥ眰浠�1寮�濮�
+        int curRoot = 1;//鎵�鍦ㄦ牴
+        int curCir = 1;//鎵�鍦ㄥ湀
+        int cirLay = 1;//褰撳墠鍦堢殑灞�
+        for (int i = 0; i < strPoints.length() / 4; i++) {
+            temp = strPoints.substring(i * 4, i * 4 + 4);
+            if (temp == null) {
+                temp = "0000";
+            }
+            tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0;
+
+            //闈炴甯稿��
+            if (tempValue > ERROR_CHECK_TAG2) {
+                tempValue = Constant.ERROR_TEMP;
+            }
+
+            // 鏁呴殰鍊煎鐞�
+            if (tempValue >= FAULT_CHECK_TAG) {
+                tempValue = Constant.FAULT_TEMP;
+            }
+
+            // 澶囩敤鍊�
+            if (tempValue == ERROR_CHECK_TAG) {
+                tempValue = Constant.ERROR_TEMP;
+
+
+                //楠岃瘉鏄笉鏄敟褰粨琛ュ伩鍊�
+                curLay = (i % layMax) + 1;
+                curRoot = (i / layMax) + 1;
+                curCir = getCurCir(curRoot, cableRuleAtt);
+
+                cirLay = Integer.valueOf(cableCirAtt[curCir - 1]);
+
+                //姣斿閰嶇疆浜�5灞備絾鏄綋鍓嶆槸6灞傦紝璇存槑褰撳墠鐐逛负琛ュ伩鐐�
+                if (curLay > cirLay) {
+                    tempValue = Constant.ADD_TEMP;
+
+                    //鍒ゆ柇鏄笉鏄笂閿ュ舰锛屽皢琛ョ偣杞Щ鍒颁笂鏂�
+                    if (Constant.CABLE_CONE_1.equals(depotConf.getCableCone())) {
+                        int index = i - curLay - 1;
+                        temps.add(index, tempValue);
+                    } else {
+                        temps.add(tempValue);
+                    }
+
+                } else {
+                    temps.add(tempValue);
+                }
+
+            } else {
+                temps.add(tempValue);
+            }
+        }
+
+        log.debug("-------CheckGrainRequest--={}", exeRequest.toString());
+
+        // 灏嗛泦鍚堣В鏋愭垚鍧愭爣鏁版嵁
+        addPoint2(temps, reMessage, depotConf, exeRequest, sysConf);
+    }
+
+    /**
+     * 鑾峰彇褰撳墠璺熸墍鍦ㄥ湀
+     *
+     * @param curRoot
+     * @param cableRuleAtt
+     * @return
+     */
+    private int getCurCir(int curRoot, String[] cableRuleAtt) {
+
+        int sum = 0;
+        for (int i = 0; i < cableRuleAtt.length; i++) {
+            sum += Integer.valueOf(cableRuleAtt[i]);
+            if (curRoot <= sum) return i + 1;
+        }
+
+        return 1;
+    }
+
+    /**
+     * 骞虫柟浠撶殑瑙f瀽锛岃В鏋愰渶瑕佽�冭檻褰撳墠鏄惁鍚敤鐨勪竴鍒嗘満澶氫粨
+     *
+     * @param depotConf
+     * @param ser
+     * @param exeRequest
+     * @param reMessage
+     */
+    private void analysisStep1(DepotConf depotConf, DeviceSer ser,
+                               ExeRequest exeRequest, ReMessage reMessage, DicSysConf sysConf) {
+        // 绮儏淇℃伅
+        String strPoints = reMessage.getGrainStr();
+
+        String[] attCable = depotConf.getCableRule().split("-");
+        int cableZ = Integer.valueOf(attCable[0]);
+        int cableY = Integer.valueOf(attCable[1]);
+        int cableX = Integer.valueOf(attCable[2]);
+
+        // 鏍规嵁灞傝鍒楄幏鍙栨寚瀹氶暱搴�
+        int start = 4 * (depotConf.getCableStart() - ser.getCableStart())
+                * cableZ * cableY;
+        int len = 4 * cableZ * cableY * cableX;
+
+        log.info("鍒嗘満------>>>骞冲彴锛氳繑鍥炵伯鎯呭畬鏁翠俊鎭紝鎵�灞炵粍缁�={}锛屽垎鏈�={}", ser.getCompanyId(), ser.getName());
+
+        strPoints = strPoints.substring(start, start + len);
+
+        // 灏嗙伯鎯呰В鏋愭垚鏁扮粍
+        List<Double> temps = new ArrayList<>();
+        double tempValue;
+        String temp;
+        for (int i = 0; i < strPoints.length() / 4; i++) {
+            temp = strPoints.substring(i * 4, i * 4 + 4);
+            if (temp == null) {
+                temp = "0000";
+            }
+            tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0;
+            // 璇存槑瑙f瀽鐨勬暟鎹湁闂
+            if (tempValue == ERROR_CHECK_TAG || tempValue == ERROR_CHECK_TAG2) {
+                tempValue = Constant.ERROR_TEMP;
+            }
+            // 鏁呴殰鍊煎鐞�
+            if (tempValue >= FAULT_CHECK_TAG) {
+                tempValue = Constant.FAULT_TEMP;
+            }
+            temps.add(tempValue);
+        }
+
+        log.debug("-------CheckGrainRequest--={}", exeRequest.toString());
+
+        // 灏嗛泦鍚堣В鏋愭垚鍧愭爣鏁版嵁
+        addPoint1(temps, reMessage, depotConf, ser, exeRequest, sysConf);
+    }
+
+    /**
+     * 骞虫埧浠擄紝瑙f瀽绗簩姝ワ紝瑙f瀽鍒板潗鏍囨暟鎹�
+     *
+     * @param temps
+     * @throws Exception
+     */
+    private void addPoint1(List<Double> temps, ReMessage msg,
+                           DepotConf depotConf, DeviceSer ser, ExeRequest exeRequest,
+                           DicSysConf sysConf) {
+
+        //鏍规嵁鐢电紗璧峰鏂逛綅鍜屽竷绾挎柟鍚戯紝瀵圭伯鎯呮暟鎹繘琛岃皟鏁�
+        if (null != depotConf.getStartOrientation()) {
+            temps = reversalGrainPoint(temps, depotConf);
+        }
+
+        //鑻ヨ捣鐐圭偣浣嶄负搴曢儴锛屽垯灏嗙伯鎯呮暟鎹繘琛岀炕杞�
+        if (null != depotConf.getStartPoint()
+                && Constant.GRAIN_START_POINT_BELOW.equals(depotConf.getStartPoint())) {
+            temps = grainUtil.reversalUpAndDown(temps, depotConf.getCableRule());
+        }
+
+        //鑻ラ厤缃眰琛岃浆鎹紝鍒欏皢绮儏鏁版嵁杩涜灞傝杞崲
+        if (StringUtils.isNotEmpty(depotConf.getStartConvert())) {
+            temps = convertGrainPoint(temps, depotConf);
+            String[] cableRule = depotConf.getCableRule().split("-");
+            //杞崲灞傝鍒楅厤缃�
+            if (Constant.GRAIN_CONVERT_CLOCKWISE.equals(depotConf.getStartConvert())
+                    || Constant.GRAIN_CONVERT_ANTICLOCKWISE.equals(depotConf.getStartConvert())) {
+                depotConf.setCableRule(Integer.valueOf(cableRule[1]) + "-" + Integer.valueOf(cableRule[0]) + "-" + Integer.valueOf(cableRule[2]));
+            }
+        }
+
+        String[] attCable = depotConf.getCableRule().split("-");
+        int cableZ = Integer.valueOf(attCable[0]);
+        int cableY = Integer.valueOf(attCable[1]);
+        int cableX = Integer.valueOf(attCable[2]);
+
+        Grain grain = new Grain();
+        grain.setDepotId(depotConf.getDepotId());
+        grain.setCompanyId(depotConf.getCompanyId());
+        grain.setCable(depotConf.getCableRule());
+        grain.setBatchId(msg.getBatchId());
+        grain.setTempIn(Constant.ERROR_TEMP);
+        grain.setHumidityIn(Constant.ERROR_TEMP);
+
+        grain.setReceiveDate(msg.getReceiveDate());
+        grain.setRemark("绮俯姝e父");
+
+        // 鑾峰彇缂撳瓨涓殑鍛戒护淇℃伅
+        grain.setCheckUser(exeRequest.getExeUser());
+
+        double max = MAX_TEMP, min = MIN_TEMP, sumT = 0.0, sumNum = cableX
+                * cableY * cableZ;
+
+        // 鏍¢獙鍜屽疄鐜扮粺璁★紝鐢熸垚閲囬泦鐐逛俊鎭�
+        List<GrainItemInfo> listGrainItems = new ArrayList<>();
+        int i = 1;
+        for (Double temp : temps) {
+            if (temp == Constant.ERROR_TEMP || temp == Constant.FAULT_TEMP || temp == Constant.ADD_TEMP) {
+                sumNum--;
+            } else {
+                sumT += temp;
+                if (temp > max) {
+                    max = temp;
+                }
+                if (temp < min) {
+                    min = temp;
+                }
+            }
+            listGrainItems.add(new GrainItemInfo(i, temp));
+            i++;
+        }
+
+        if (sumNum == 0) {
+            sumNum = 1;
+            grain.setRemark("褰撳墠绮儏閲囬泦寮傚父");
+        }
+        //杩囨护姣旇緝鐢ㄧ殑鏈�澶ф渶灏忓��
+        if (max == MAX_TEMP) {
+            max = 0.0;
+        }
+        if (min == MIN_TEMP) {
+            min = 0.0;
+        }
+        if (null != depotConf.getTempMax() && max > depotConf.getTempMax()) {
+            grain.setRemark("浠撳簱閰嶇疆楂樻俯璀﹀憡鍊硷細" + depotConf.getTempMax() + "锛屽綋鍓嶆娴嬮珮娓╁�硷細"
+                    + max);
+            warnUtils.addGrainWarn(depotConf, grain);
+        }
+
+        grain.setTempAve(sumT / sumNum);
+        grain.setTempMax(max);
+        grain.setTempMin(min);
+        grain.setPoints(StringUtils.join(temps, ","));
+
+        String depotIds = exeRequest.getDepotIds();
+
+        boolean notifyWeb = true;
+        if (null != depotIds && depotIds.indexOf(depotConf.getDepotId()) == -1) {
+            notifyWeb = false;
+        }
+        // 鐢ㄦ埛灏佽濂芥暟鎹嵆鍙�
+        notifyGrainInvoker.analysisSuccess(grain, listGrainItems, depotConf,
+                sysConf, notifyWeb, exeRequest);
+    }
+
+    /**
+     * 鍦嗙瓛浠撹В鏋愭楠�
+     *
+     * @param temps
+     * @param msg
+     * @param depotConf
+     * @param exeRequest
+     */
+    private void addPoint2(List<Double> temps, ReMessage msg,
+                           DepotConf depotConf, ExeRequest exeRequest,
+                           DicSysConf sysConf) {
+
+        Grain grain = new Grain();
+        grain.setDepotId(depotConf.getDepotId());
+        grain.setCompanyId(depotConf.getCompanyId());
+        grain.setCable(depotConf.getCableRule());
+        grain.setCableCir(depotConf.getCableCir());
+        grain.setBatchId(msg.getBatchId());
+        grain.setTempIn(Constant.ERROR_TEMP);
+        grain.setHumidityIn(Constant.ERROR_TEMP);
+
+        grain.setReceiveDate(msg.getReceiveDate());
+        grain.setRemark("绮俯姝e父");
+        grain.setCheckUser(exeRequest.getExeUser());
+
+        double max = MAX_TEMP, min = MIN_TEMP, sumT = 0.0;
+
+        int sumNum = temps.size();
+        List<GrainItemInfo> listGrainItems = new ArrayList<>();
+        int i = 1;
+        for (Double temp : temps) {
+            if (temp == Constant.ERROR_TEMP || temp == Constant.FAULT_TEMP || temp == Constant.ADD_TEMP) {
+                sumNum--;
+            } else {
+                sumT += temp;
+                if (temp > max) {
+                    max = temp;
+                }
+                if (temp < min) {
+                    min = temp;
+                }
+            }
+            listGrainItems.add(new GrainItemInfo(i, temp));
+            i++;
+        }
+
+        if (sumNum == 0) {
+            sumNum = 1;
+            grain.setRemark("褰撳墠绮儏閲囬泦寮傚父");
+        }
+        //杩囨护姣旇緝鐢ㄧ殑鏈�澶ф渶灏忓��
+        if (max == MAX_TEMP) {
+            max = 0.0;
+        }
+        if (min == MIN_TEMP) {
+            min = 0.0;
+        }
+        if (null != depotConf.getTempMax() && max > depotConf.getTempMax()) {
+            grain.setRemark("浠撳簱閰嶇疆楂樻俯璀﹀憡鍊硷細" + depotConf.getTempMax() + "锛屽綋鍓嶆娴嬮珮娓╁�硷細"
+                    + max);
+            warnUtils.addGrainWarn(depotConf, grain);
+        }
+
+        grain.setTempAve(sumT / sumNum);
+        grain.setTempMax(max);
+        grain.setTempMin(min);
+        grain.setPoints(StringUtils.join(temps, ","));
+
+        String depotIds = exeRequest.getDepotIds();
+        boolean notifyWeb = true;
+        if (null != depotIds && depotIds.indexOf(depotConf.getDepotId()) == -1) {
+            notifyWeb = false;
+        }
+
+        // 鐢ㄦ埛灏佽濂芥暟鎹嵆鍙�
+        notifyGrainInvoker.analysisSuccess(grain, listGrainItems, depotConf,
+                sysConf, notifyWeb, exeRequest);
+    }
+
+    private List<Double> convertGrainPoint(List<Double> temps, DepotConf conf) {
+        if (Constant.GRAIN_CONVERT_DEFAULT.equals(conf.getStartConvert())) {
+            //鑻ュ眰琛岃浆鎹负榛樿锛屽垯鐩存帴杩斿洖
+            return temps;
+        }
+
+        //椤烘椂閽堣浆鎹�
+        if (Constant.GRAIN_CONVERT_CLOCKWISE.equals(conf.getStartConvert())) {
+            return grainUtil.convertRight(temps, conf.getCableRule());
+        }
+        //閫嗘椂閽堣浆鎹�
+        if (Constant.GRAIN_CONVERT_ANTICLOCKWISE.equals(conf.getStartConvert())) {
+            return grainUtil.convertLeft(temps, conf.getCableRule());
+        }
+
+        return temps;
+    }
+
+    private List<Double> reversalGrainPoint(List<Double> temps, DepotConf conf) {
+        if (StringUtils.isEmpty(conf.getStartOrientation())) {
+            //鑻ヨ捣濮嬫柟浣嶄负绌猴紝鍒欓粯璁よ捣濮嬫柟浣嶅拰鏂瑰悜锛岀洿鎺ヨ繑鍥�
+            return temps;
+        }
+        //璧峰鏂逛綅涓哄彸杈规椂
+        if (Constant.GRAIN_START_ORIENTATION_RIGHT.equals(conf.getStartOrientation())) {
+            if (StringUtils.isEmpty(conf.getStartDirection())) {
+                //鍙宠竟璧峰锛岄粯璁ょ旱鍚戝竷绾匡紝鐩存帴杩斿洖
+                return temps;
+            }
+            if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) {
+                //鍙宠竟璧峰锛屾í鍚戝竷绾�
+                return grainUtil.reversalRight1(temps, conf.getCableRule());
+            }
+            //鍙宠竟璧峰锛岄粯璁ょ旱鍚戝竷绾匡紝鐩存帴杩斿洖
+            return temps;
+        }
+        //璧峰鏂逛綅涓哄彸涓婃椂
+        if (Constant.GRAIN_START_ORIENTATION_RIGHT_UP.equals(conf.getStartOrientation())) {
+            if (StringUtils.isEmpty(conf.getStartDirection())) {
+                //鍙充笂璧峰锛岄粯璁ょ旱鍚戝竷绾�
+                return grainUtil.reversalRightUp2(temps, conf.getCableRule());
+            }
+            if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) {
+                //鍙充笂璧峰锛屾í鍚戝竷绾�
+                return grainUtil.reversalRightUp1(temps, conf.getCableRule());
+            }
+            //鍙充笂璧峰锛岄粯璁ょ旱鍚戝竷绾�
+            return grainUtil.reversalRightUp2(temps, conf.getCableRule());
+        }
+        //璧峰鏂逛綅涓哄乏杈规椂
+        if (Constant.GRAIN_START_ORIENTATION_LEFT.equals(conf.getStartOrientation())) {
+            if (StringUtils.isEmpty(conf.getStartDirection())) {
+                //宸﹁竟璧峰锛岄粯璁ょ旱鍚戝竷绾�
+                return grainUtil.reversalLeft2(temps, conf.getCableRule());
+            }
+            if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) {
+                //宸﹁竟璧峰锛屾í鍚戝竷绾�
+                return grainUtil.reversalLeft1(temps, conf.getCableRule());
+            }
+            //宸﹁竟璧峰锛岄粯璁ょ旱鍚戝竷绾�
+            return grainUtil.reversalLeft2(temps, conf.getCableRule());
+        }
+        //璧峰鏂逛綅涓哄乏涓婃椂
+        if (Constant.GRAIN_START_ORIENTATION_LEFT_UP.equals(conf.getStartOrientation())) {
+            if (StringUtils.isEmpty(conf.getStartDirection())) {
+                //宸︿笂璧峰锛岄粯璁ょ旱鍚戝竷绾�
+                return grainUtil.reversalLeftUp2(temps, conf.getCableRule());
+            }
+            if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) {
+                //宸︿笂璧峰锛屾í鍚戝竷绾�
+                return grainUtil.reversalLeftUp1(temps, conf.getCableRule());
+            }
+            //宸︿笂璧峰锛岄粯璁ょ旱鍚戝竷绾�
+            return grainUtil.reversalLeftUp2(temps, conf.getCableRule());
+        }
+
+        return temps;
+    }
+
+    private String buildCurKey(ReMessage msg, int curPacket) {
+        return msg.getSerId() + "_" + curPacket;
+    }
+
+    private String buildContextKey(ReMessage msg, String depotId) {
+        return msg.getCompanyId() + "_" + msg.getSerId() + "_" + depotId;
     }
 }
diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java
index 6c1ce26..816574a 100644
--- a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java
@@ -23,25 +23,26 @@
      * 绮儏閲囬泦鍛戒护
      *
      * @param grainAddr 绮儏鍒嗘満鍦板潃
-     * @param depotId    浠撳簱缂栧彿鍦板潃
      * @return
      */
-    public static String getMsgCheck(String grainAddr, String depotId) {
+    public static String getMsgCheck(String grainAddr) {
 
         StringBuffer sb = new StringBuffer();
 
         //璧峰绗�
         sb.append(BeiboGrainServerUtils.MSG_START);
 
-        //鍒嗘満鍦板潃
-        int i = Integer.parseInt(grainAddr);
-        sb.append(BytesUtil.intToHexStr1(i));
+        //瀹為檯鍒嗘満鍦板潃
+        int addr = Integer.parseInt(grainAddr);
+        //绮儏鍒嗘満鍦板潃=鎷ㄧ爜寮�鍏冲湴鍧�+40H
+        addr += BeiboGrainServerUtils.BM;
+        sb.append(BytesUtil.intToHexStr1(addr));
 
         //鎺у埗鍛戒护
         sb.append("82");
 
         //鍒嗘満鍦板潃
-        sb.append(BytesUtil.intToHexStr1(i));
+        sb.append(BytesUtil.intToHexStr1(addr));
 
         //娴嬫俯鐢电紗灞傛暟锛屼笉鐭ラ亾鐢电紗閲囬泦灞傛暟鏃讹紝榛樿00鎴栬�匜F
         sb.append("00");
diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessage.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessage.java
new file mode 100644
index 0000000..70b81c2
--- /dev/null
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessage.java
@@ -0,0 +1,37 @@
+package com.ld.igds.protocol.beibo.grain.builder;
+
+import lombok.Data;
+import java.util.Date;
+
+/**
+ * 杩斿洖娑堟伅灏佽
+ * 
+ * @author czt
+ *
+ */
+@Data
+public class ReMessage {
+
+	private String startStr; //璧峰绗�
+
+	private String serId;     //鍒嗘満鍦板潃
+
+	private String grainStr;  //绮俯鏁版嵁
+
+	private String thStr;     //娓╂箍搴︽暟鎹�
+
+	private String expand;    //鎵╁厖鏁版嵁
+
+	private String hexCrc16;  //妫�楠岀爜
+
+	private String batchId;
+
+	private String companyId;
+
+	private Date receiveDate;
+
+	// 寮傚父淇℃伅
+	private String error;
+
+	private String strMsg;// 褰撳墠鍛戒护杞崲涓哄瓧绗︿覆鐨勪俊鎭�
+}
diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessageBuilder.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessageBuilder.java
new file mode 100644
index 0000000..9491a6f
--- /dev/null
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessageBuilder.java
@@ -0,0 +1,58 @@
+package com.ld.igds.protocol.beibo.grain.builder;
+
+import com.ld.igds.protocol.beibo.grain.util.BeiboGrainServerUtils;
+import com.ld.igds.util.BytesUtil;
+
+/**
+ * 鏍规嵁鎺ユ敹鍒扮殑淇℃伅杩涜灏佽
+ *
+ * @author czt
+ */
+public class ReMessageBuilder {
+
+    private final static ReMessageBuilder instance = new ReMessageBuilder();
+
+    private ReMessageBuilder() {
+    }
+
+    public static ReMessageBuilder getInstance() {
+        return instance;
+    }
+
+    /**
+     * @param strMsg
+     * @return
+     */
+    public ReMessage buildMessage(String strMsg) {
+
+        ReMessage message = new ReMessage();
+        message.setStrMsg(strMsg);
+        //璁剧疆璧峰绗�
+        message.setStartStr(strMsg.substring(0, 9*2-1));
+
+        //璁剧疆绮儏鍒嗘満鍦板潃
+        String str = strMsg.substring(9*2-1, 10*2-1);
+        int i = BytesUtil.hexToInt(str);
+        String serId = String.valueOf(i - BeiboGrainServerUtils.BM);
+        message.setSerId(serId);
+
+        //绮儏鏁版嵁
+        str = strMsg.substring(10*2-1, 1034*2 -1);
+        message.setGrainStr(str);
+
+        //娓╁害鏁版嵁
+        str = strMsg.substring(1034*2 -1, 1052*2-1);
+        message.setThStr(str);
+
+        //鎵╁厖鏁版嵁
+        str = strMsg.substring(strMsg.length()-14*2, strMsg.length()-4*2);
+        message.setExpand(str);
+
+        //妫�楠岀爜
+        str = strMsg.substring(strMsg.length()-4*2);
+        message.setHexCrc16(str);
+
+        return message;
+    }
+}
+
diff --git a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java
index de00a97..4380b66 100644
--- a/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java
+++ b/igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java
@@ -10,4 +10,8 @@
 
     public static String MSG_START = "00000000FFEB90FEAA"; //璧峰绗�
     public static String MSG_END = "00000000000000000000000000"; //缁撳熬绗�
+
+    public static int BM = 64; //缁撳熬绗�
+
+
 }
diff --git a/igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java b/igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java
index 983803d..8720573 100644
--- a/igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java
+++ b/igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java
@@ -163,8 +163,7 @@
      * @param msg
      * @throws Exception
      */
-    private void analysisStep(DepotConf depotConf, ReMessage msg,
-                              DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) {
+    private void analysisStep(DepotConf depotConf, ReMessage msg, DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) {
         // 绮儏鐨勬壒娆″彿閲嶆柊鏍规嵁棰戠巼璋冩暣
         msg.setBatchId(ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq()));
 
diff --git a/igds-web/pom.xml b/igds-web/pom.xml
index 82287d2..7af5246 100644
--- a/igds-web/pom.xml
+++ b/igds-web/pom.xml
@@ -205,7 +205,7 @@
             </exclusions>
         </dependency>
 
-        <!--  绉佹湁鍗忚-璐濆崥绮儏
+        <!--  绉佹湁鍗忚-璐濆崥绮儏-->
         <dependency>
             <groupId>com.ld.igds</groupId>
             <artifactId>igds-protocol-beibo</artifactId>
@@ -220,9 +220,9 @@
                     <groupId>log4j</groupId>
                 </exclusion>
             </exclusions>
-        </dependency>-->
+        </dependency>
 
-        <!--  绉佹湁鍗忚-DLT645鐢佃〃鍗忚
+        <!--  绉佹湁鍗忚-DLT645鐢佃〃鍗忚-->
         <dependency>
             <groupId>com.ld.igds</groupId>
             <artifactId>igds-protocol-es</artifactId>
@@ -237,7 +237,7 @@
                     <groupId>log4j</groupId>
                 </exclusion>
             </exclusions>
-        </dependency>-->
+        </dependency>
 
         <!--  绉佹湁鍗忚-閭︽捣鏅鸿兘
         <dependency>

--
Gitblit v1.9.3