CZT
2023-09-26 d52037b84cd6689b1cc03b47a5cd43fcb6b7342f
贝博粮情解析1
已修改6个文件
已添加2个文件
783 ■■■■■ 文件已修改
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/RemoteGrainServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/analysis/AnalysisService.java 657 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/CommandBuild.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessage.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/builder/ReMessageBuilder.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grain/util/BeiboGrainServerUtils.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/pom.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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(),
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 @@
/**
 * åè®®è§£æž
 *
 * @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("分机------->>平台,解析粮情失败:报文起始符={}错误,不解析", 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 = "粮情解析失败:分机=" + 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 = "粮情解析失败:分机=" + ser.getName() + "没有获取历史命令。";
            log.error("贝博分机------>>>平台:" + info);
            return;
        }
        DepotConf depotConf = commonService.getCacheDepotConf(
                exeRequest.getCompanyId(), exeRequest.getDepotId());
        if (null == depotConf) {
            String info = "粮情解析失败:分机=" + 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 = "粮情解析失败:分机=" + ser.getName() + "没有获取到所属仓库信息。";
                log.error("贝博分机------>>>平台:" + info);
                return;
            }
            //获取针对当前仓库的命令
            ExeRequest exeRequest = list.get(0);
            if (null == exeRequest) {
                String info = "粮情解析失败:分机=" + ser.getName() + "没有获取历史命令。";
                log.error("贝博分机------>>>平台:" + info);
                return;
            }
            DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId());
            if (null == depotConf) {
                String info = "粮情解析失败:分机=" + 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);
            }
        }
    }
    /**
     * åœ†ç­’仓的粮情解析
     *
     * @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("分机------>>>平台:当前仓库:{}-{},没有没有配置布线规则,无法解析粮情信息……",
                    ser.getCompanyId(), depotConf.getDepotName());
            return;
        }
        String[] cableRuleAtt = depotConf.getCableRule().split("-");
        String[] cableCirAtt = depotConf.getCableCir().split("-");
        if (cableRuleAtt.length != cableCirAtt.length) {
            log.error("分机------>>>平台:当前仓库:{}-{},布线规则不正确,无法解析粮情信息……", 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 å…±å¤šå°‘根电缆;cableZ å±‚的最大值,锥形仓补齐最大层
        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;
    }
    /**
     * å¹³æ–¹ä»“的解析,解析需要考虑当前是否启用的一分机多仓
     *
     * @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;
            // è¯´æ˜Žè§£æžçš„æ•°æ®æœ‰é—®é¢˜
            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);
    }
    /**
     * å¹³æˆ¿ä»“,解析第二步,解析到坐标数据
     *
     * @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("粮温正常");
        // èŽ·å–ç¼“å­˜ä¸­çš„å‘½ä»¤ä¿¡æ¯
        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("粮温正常");
        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;
    }
}
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或者FF
        sb.append("00");
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;// å½“前命令转换为字符串的信息
}
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;
    }
}
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; //结尾符
}
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()));
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>