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/analysis/AnalysisService.java | 657 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 593 insertions(+), 64 deletions(-) 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; } } -- Gitblit v1.9.3