vince
2023-09-04 e241acb82959328535d8f903902863bd420df139
增加zldz协议
已修改7个文件
已添加45个文件
5075 ■■■■■ 文件已修改
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/ServerRunner.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/RemoteGrainV1ServiceImpl.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/msg/AnalysisService.java 82 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/server/BhznGrainV1SessionListener.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/pom.xml 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/ServerRunner.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisConf.java 381 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java 819 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisService.java 211 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisTH.java 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/builder/ReMessageBuilder.java 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/Metadata.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/ReMessage.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/ReMessageBody.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/BaseRemoteImpl.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/RemoteCommonImpl.java 426 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/RemoteGrainServiceImpl.java 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder.java 144 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1115.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1116_0.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1116_1.java 97 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1122.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1123.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1125.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1126.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1128.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8815.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8817.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8829.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/OnLineCommandBuilder.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/message/Message.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/message/MessageBody.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/PublisherControl.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/ReceiverServer.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/RedisSubConfig.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/package-info.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/HeartbeatProviderImpl.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/MsgConsumer.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/SessionListener.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/ZldzServerEngine.java 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/CommandReSendService.java 145 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/CommandTask.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/ReSendCommonTask.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/ReSendGrainTask.java 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/CRC16.java 135 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/CRC8.java 186 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/ServerUtils.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/pom.xml 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/src/main/resources/application-pro1000.yml 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/src/main/resources/application-pro5322.yml 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/ServerRunner.java
@@ -1,6 +1,7 @@
package com.ld.igds.protocol.bhzn;
import com.ld.igds.data.ConfigData;
import com.ld.igds.protocol.bhzn.grainv1.server.BhznGrainV1ServerEngine;
import com.ld.igds.protocol.bhzn.grainv2.server.BhznGrainV2ServerEngine;
import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerEngine;
import org.springframework.beans.factory.annotation.Autowired;
@@ -20,19 +21,21 @@
    @Autowired
    private ConfigData configData;
    @Autowired
    private BhznGrainV2ServerEngine bhznGrainServerEngine;
    private BhznGrainV2ServerEngine bhznGrainServerEngine2;
    @Autowired
    private BhznGrainV1ServerEngine bhznGrainServerEngine1;
    @Autowired
    private BhznVerbServerEngine bhznVerbServerEngine;
    @Override
    public void run(String... strings) throws Exception {
        if (configData.getActive().indexOf("pro") >= 0) {
            bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT);
            bhznVerbServerEngine.start(BhznVerbServerEngine.PORT);
            bhznGrainServerEngine1.start(BhznGrainV1ServerEngine.PORT);
           // bhznVerbServerEngine.start(BhznVerbServerEngine.PORT);
        }
        if (configData.getActive().indexOf("dev") >= 0) {
            bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT);
            bhznVerbServerEngine.start(BhznVerbServerEngine.PORT);
            bhznGrainServerEngine1.start(BhznGrainV1ServerEngine.PORT);
            //bhznVerbServerEngine.start(BhznVerbServerEngine.PORT);
        }
    }
}
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/RemoteGrainV1ServiceImpl.java
@@ -37,8 +37,28 @@
    public GrainResponse checkGrain(CheckGrainRequest request) {
        try {
            // ç”Ÿæˆç²®æƒ…信息
            String hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), request.getDepotId());
            String hexStr = "";
            if("5323".equals(request.getCompanyId())){
                if("0P01".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "1");
                }else if("0P02".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(),  "1");
                }else if("0P03".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(),  "2");
                }else if("0P04".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "2");
                }else if("0P05".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "3");
                }else if("0P06".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4");
                }else if("0P07".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4");
                }else if("0P08".equals(request.getDepotId())){
                    hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4");
                }
            }else{
                hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), request.getDepotId());
            }
//            //通讯使用的是主机通讯
//            DeviceSer mainSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID);
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/msg/AnalysisService.java
@@ -5,13 +5,11 @@
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.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.models.*;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.protocol.bhzn.grainv1.msg.builder.CommandBuild;
@@ -75,7 +73,7 @@
            //DO NOTHING
            log.info("主机------->>平台:注册信息报文={}", message);
            DeviceSer ser = coreSerService.getCacheSerBySn(ContextUtil.getDefaultCompanyId(),message.getAddr());
            DeviceSer ser = coreSerService.getCacheSerBySn("5323",message.getAddr());
            if(ser!= null ){
                ser.setIp(message.getIp());
                ser.setPort(message.getPort());
@@ -113,7 +111,7 @@
            //根据分机地址获取分机信息
            DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), message.getAddr());
            DeviceSer ser = coreSerService.getCacheSer("5323", message.getAddr());
            if (ser == null) {
                replayGrain(message);
                log.error("主机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + message.getAddr());
@@ -145,15 +143,30 @@
                log.error("分机------>>>平台:" + info);
                return;
            }
            Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId());
            if (null == depot) {
                String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置仓库。";
                log.error("分机------>>>平台:" + info);
                return;
            }
            // ç²®æƒ…的批次号重新根据频率调整
            String batchId = ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq());
            // åˆ¤æ–­æ•°æ®æœ‰æ²¡æœ‰æ”¶å–完整
            String[] attCable = depotConf.getCableRule().split("-");
            int cableZ = Integer.valueOf(attCable[0]);
            int cableY = Integer.valueOf(attCable[1]);
            int cableX = Integer.valueOf(attCable[2]);
            int cableZ = 1;
            int cableY = 1;
            int cableX = 1;
            if(DepotType.TYPE_01.equals(depot.getDepotType())){
                cableZ = Integer.valueOf(attCable[0]);
                cableY = Integer.valueOf(attCable[1]);
                cableX = Integer.valueOf(attCable[2]);
            }else{
                cableZ = Integer.valueOf(depotConf.getCableCir());
                cableY = Integer.valueOf(attCable[0]);
                cableX = 1;
            }
            int sumPoint = cableZ * cableY * cableX;
            //获取当前粮情温度报文
@@ -215,10 +228,26 @@
    private void analysisGrain2(DeviceSer ser, IoMessage message, ExeRequest exeRequest, DepotConf depotConf, DicSysConf sysConf, String batchId, String grainStr) {
        // èŽ·å–å®Œæ•´çš„ç²®æƒ…åŒ…ä¿¡æ¯
        Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId());
        if (null == depot) {
            String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置仓库。";
            log.error("分机------>>>平台:" + info);
            return;
        }
        String[] attCable = depotConf.getCableRule().split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        int cableZ = 1;
        int cableY = 1;
        int cableX = 1;
        if(DepotType.TYPE_01.equals(depot.getDepotType())){
            cableZ = Integer.valueOf(attCable[0]);
            cableY = Integer.valueOf(attCable[1]);
            cableX = Integer.valueOf(attCable[2]);
        }else{
            cableZ = Integer.valueOf(depotConf.getCableCir());
            cableY = Integer.valueOf(attCable[0]);
            cableX = 1;
        }
        // æ ¹æ®å±‚行列获取指定长度
        int start = 4 * (depotConf.getCableStart() - ser.getCableStart())
@@ -275,7 +304,12 @@
    private void addPoint1(List<Double> temps,
                           DepotConf depotConf, DeviceSer ser, ExeRequest exeRequest,
                           THDto thDto, DicSysConf sysConf, String batchId) {
        Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId());
        if (null == depot) {
            String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置仓库。";
            log.error("分机------>>>平台:" + info);
            return;
        }
        //根据电缆起始方位和布线方向,对粮情数据进行调整
        if (null != depotConf.getStartOrientation()) {
            temps = reversalGrainPoint(temps, depotConf);
@@ -288,14 +322,26 @@
        }
        String[] attCable = depotConf.getCableRule().split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        int cableZ = 1;
        int cableY = 1;
        int cableX = 1;
        if(DepotType.TYPE_01.equals(depot.getDepotType())){
            cableZ = Integer.valueOf(attCable[0]);
            cableY = Integer.valueOf(attCable[1]);
            cableX = Integer.valueOf(attCable[2]);
        }else{
            cableZ = Integer.valueOf(depotConf.getCableCir());
            cableY = Integer.valueOf(attCable[0]);
            cableX = 1;
        }
        Grain grain = new Grain();
        grain.setDepotId(depotConf.getDepotId());
        grain.setCompanyId(depotConf.getCompanyId());
        grain.setCable(depotConf.getCableRule());
        grain.setCableCir(depotConf.getCableCir());
        grain.setBatchId(batchId);
        grain.setTempIn(Constant.ERROR_TEMP);
        grain.setHumidityIn(Constant.ERROR_TEMP);
@@ -430,7 +476,7 @@
    private void analysisTh(IoMessage message) {
        try {
            THDto th = new THDto();
            th.setCompanyId(ContextUtil.getDefaultCompanyId());
            th.setCompanyId("5323");
            String data = message.getContent();
            String houseNo = data.substring(0, 2);
            String t = data.substring(4, 8);
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/grainv1/server/BhznGrainV1SessionListener.java
@@ -1,9 +1,11 @@
package com.ld.igds.protocol.bhzn.grainv1.server;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.constant.Constant;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.view.service.DeviceSerService;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
@@ -19,7 +21,6 @@
    @Autowired
    private CoreSerService coreSerService;
    /**
     * è®¾å¤‡åˆ›å»ºåœ¨çº¿ï¼Œéœ€è¦æ³¨æ„å½“前使用主机模式,主机上线默认所有相同SN配置的分机全部上线
     *
@@ -37,10 +38,8 @@
        session.setBusinessKey(BhznGrainV1ServerUtils.getServerKey(session.getAddress(), session.getPort()));
        //项目采用无线主机模式,直接获取默认设备
        DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID);
        DeviceSer deviceSer = coreSerService.getCacheSerBySn("5323", BhznGrainV1ServerUtils.DEFAULT_MAC_ID);
        if (null == deviceSer) return;
        coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_Y);
        //更新缓存
        coreSerService.refreshCache(deviceSer.getCompanyId());
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java
@@ -131,7 +131,7 @@
        try{
            log.info("BHZN控制LED开始");
            BHZNClientEngine test = new BHZNClientEngine(
                    "12.10.0.187", 58258);
                    "192.168.0.210", 58258);
            test.start();
            Thread.sleep(3000L);
igds-protocol-zldz/pom.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ld.igds</groupId>
    <artifactId>igds-protocol-zldz</artifactId>
    <version>4.0.0-RELEASE</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <igds.version>4.0.0-RELEASE</igds.version>
    </properties>
    <dependencies>
        <!-- å¼•入义务核心包 -->
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-core</artifactId>
            <version>${igds.version}</version>
        </dependency>
        <!-- å¼•å…¥IO包 -->
        <dependency>
            <groupId>com.ld.base.io</groupId>
            <artifactId>base-io-netty</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
     <build>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
                     <compilerArguments>
                         <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                     </compilerArguments>
                 </configuration>
             </plugin>
         </plugins>
     </build>
</project>
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/ServerRunner.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,53 @@
package com.ld.igds.protocol.zldz;
import com.ld.igds.data.ConfigData;
import com.ld.igds.protocol.zldz.server.ZldzServerEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
 * å¯ä»¥æ ¹æ®é…ç½®æ–‡ä»¶çµæ´»è°ƒæ•´
 * é…ç½®éšç³»ç»Ÿè‡ªåŠ¨å¯åŠ¨æœåŠ¡ -- æ‰§è¡Œé¡ºåº20-29
 */
@Component(ServerRunner.BEAN_ID)
@Order(value = 22)
public class ServerRunner implements CommandLineRunner {
    public static final String BEAN_ID = "zldz.serverRunner";
    @Autowired
    private ConfigData configData;
    @Override
    public void run(String... strings) throws Exception {
        //
        if ("fzzy".equals(configData.getActive())) {
            ZldzServerEngine.start(9201);
            return;
        }
        //风正致远默认部署服务当前应用使用9000端口
        if (configData.getActive().equals("dev")) {
            ZldzServerEngine.start(9201);
            return;
        }
        //风正致远默认部署服务当前应用使用9000端口
        if (configData.getActive().indexOf("pro") >= 0) {
            //FZZY平台
            ZldzServerEngine.start(9201);
            //其他平台
//            ZldzServerEngine.start(ZldzServerEngine.PORT);
            return;
        }
        //请注意,正来电子本事服务器部署用的端口是:8000
        if (configData.getActive().equals("zldz")) {
            ZldzServerEngine.start(ZldzServerEngine.PORT);
            return;
        }
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisConf.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,381 @@
package com.ld.igds.protocol.zldz.analysis;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.grain.dto.GrainSerCableData;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8829;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.task.CommandReSendService;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
import com.ld.igds.util.RedisUtil;
import com.ld.igds.view.manager.TempManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * @author vince
 */
@Slf4j
@Component(AnalysisConf.BEAN_ID)
public class AnalysisConf extends BaseRemoteImpl {
    public static final String BEAN_ID = "zldz.analysisConf";
    @Autowired
    private NotifyWebInvoker notifyWebInvoker;
    @Autowired
    private CoreSerService serService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private TempManager thManager;
    @Autowired
    private CommandReSendService commandReSendService;
    /**
     * è§£æžåˆ†æœºé…ç½®ä¿¡æ¯
     *
     * @param message
     * @param ser
     */
    public void analysis8816(ReMessage message, DeviceSer ser) {
        log.debug("分机---->>>平台:消息类型=8816----{}-{}.{}", ser.getCompanyId(),
                ser.getIp(), ser.getPort());
        // æ¸…除缓存
        commandReSendService.cleanKey(message.getCompanyId(), message.getIp(),
                message.getPort(), ServerUtils.MSG_TYPE_8816);
        // æ¸…楚初始化登陆的解析
        commandReSendService.cleanKey(ServerUtils.DEFAULT_COMPANY,
                message.getIp(), message.getPort(), ServerUtils.MSG_TYPE_8816);
        ser.setStatus(Constant.YN_Y);
        String content = message.getBody().getContent();
        // è¯»å†™æ ‡å¿—
        int start = 0, len = 1;
        String temp = content.substring(start * 2, start * 2 + len * 2);
        int readTag = BytesUtil.hexToInt(temp);
        // è®¾å¤‡ID,全局唯一
        start = 1;
        len = 2;
        temp = content.substring(start * 2, start * 2 + len * 2);
        // ç½‘络ID
        start = 3;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        // ä¿¡é“
        start = 4;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        // é€Ÿçއ
        start = 5;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        // å±‚æ•°
        start = 6;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setCableZ(BytesUtil.hexToInt(temp));
        // è¡Œæ•°
        start = 7;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setCableY(BytesUtil.hexToInt(temp));
        // åˆ—æ•°
        start = 8;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setCableX(BytesUtil.hexToInt(temp));
        // ç”µç¼†åˆ¶å¼
        start = 9;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setCableFormat("0" + BytesUtil.hexToInt(temp));
        // ç”µç¼†ç±»åž‹
        start = 10;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setCableType("0" + BytesUtil.hexToInt(temp));
        // ä¾›ç”µæ¨¡å¼
        start = 11;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        ser.setPowerModel("0" + BytesUtil.hexToInt(temp));
        String msg = ser.getName() + " è¿œç¨‹èŽ·å–é…ç½®æˆåŠŸï¼Œè¯·åˆ·æ–°æ•°æ®æŸ¥çœ‹ï¼";
        // ç»„织编码
        start = 12;
        temp = content.substring(start * 2);
        if (readTag == 1) {// è¡¨ç¤ºå†™çš„æˆåŠŸè¿”å›ž
            ser.setOrgId(ser.getCompanyId());
            msg = ser.getName() + " è¿œç¨‹å†™å…¥æˆåŠŸï¼Œè¯·åˆ·æ–°æ•°æ®æŸ¥çœ‹ï¼";
        } else {
            ser.setOrgId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
        }
        if (null == ser.getSn()) {
            ser.setSn(ser.getId());
        }
        ser.setIp(message.getIp());
        ser.setPort(message.getPort());
        // å¼€å§‹åˆ—默认=1
        if (ser.getCableStart() == 0) {
            ser.setCableStart(1);
        }
        log.info("分机---->>>平台:分机配置解析完成----{}-{}-{}-{},更新到服服务器",
                ser.getCompanyId(), ser.getIp(), ser.getPort(), ser.getName());
        serService.updateSerById(ser);
        // æ›´æ–°ä¼šè¯ä¿¡æ¯
        super.updateSession(ser.getIp(), ser.getPort(), ser.getCompanyId());
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
        //分机上线进行一次温湿度采集
        thManager.checkThBySer(ser.getCompanyId(), ser.getId());
    }
    /**
     * ç”µç¼†åˆå§‹åŒ–成功
     *
     * @param reMessage
     * @param ser
     */
    public void analysis8822(ReMessage reMessage, DeviceSer ser) {
        log.debug("-----------analysis8822------------{}-{}.{}",
                ser.getCompanyId(), ser.getIp(), ser.getPort());
        // æ¸…除缓存
        commandReSendService.cleanKey(reMessage.getCompanyId(),
                reMessage.getIp(), reMessage.getPort(),
                ServerUtils.MSG_TYPE_8822);
        String msg = ser.getName() + " åˆå§‹åŒ–电缆完成!!";
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
    }
    /**
     * ç”µç¼†ä¿®æ”¹è¿”回,
     *
     * @param reMessage
     * @param ser
     */
    public void analysis8826(ReMessage reMessage, DeviceSer ser) {
        log.debug("-----------analysis8826------------{}-{}.{}",
                ser.getCompanyId(), ser.getIp(), ser.getPort());
        // æ¸…除缓存
        commandReSendService.cleanKey(reMessage.getCompanyId(),
                reMessage.getIp(), reMessage.getPort(),
                ServerUtils.MSG_TYPE_8826);
        String msg = ser.getName() + " ç”µç¼†ä¿®æ”¹æ“ä½œå®Œæˆ";
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
    }
    /**
     * é€šé“电缆获取返回,分机返回收到命令信息,实际返回值在8829中说明
     *
     * @param reMessage
     * @param ser
     */
    public void analysis8825(ReMessage reMessage, DeviceSer ser) {
        log.debug("-----------analysis8825------------{}-{}.{}",
                ser.getCompanyId(), ser.getIp(), ser.getPort());
        // æ¸…除缓存
        commandReSendService.cleanKey(reMessage.getCompanyId(),
                reMessage.getIp(), reMessage.getPort(),
                ServerUtils.MSG_TYPE_8825);
        String msg = ser.getName() + " è¯»å–通道电缆开始返回";
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg);
    }
    /**
     * ç»ˆç«¯å‘送通道电缆数据给后台,分机主动推送
     *
     * @param reMessage
     * @param ser
     */
    @SuppressWarnings("unchecked")
    public void analysis1129(ReMessage reMessage, DeviceSer ser) {
        // å¼€å§‹è§£æž
        String content = reMessage.getBody().getContent();
        // é€šé“号
        int start = 0, len = 1;
        String temp = content.substring(start * 2, start * 2 + len * 2);
        int passCode = BytesUtil.hexToInt(temp);
        // ç‚¹åºå·ï¼ŒæŒ‰ç…§è¿”回顺序填写从1开始
        start = 1;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        int iotNum = BytesUtil.hexToInt(temp);
        // æ€»åŒ…æ•°
        start = 2;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        int sumPacket = BytesUtil.hexToInt(temp);
        // å½“前包
        start = 3;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        int curPacket = BytesUtil.hexToInt(temp);
        // -----------后端通知终端收到信息----------------------//
        GrainSerConfRequest request = new GrainSerConfRequest();
        request.setSerId(ser.getId());
        request.setBizType(BizType.SYS.getCode());
        request.setIp(ser.getIp());
        request.setPort(ser.getPort());
        request.setCompanyId(ser.getCompanyId());
        request.setValue1(curPacket);
        Message message = CommandBuilder8829.getInstance()
                .buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "后台收到电缆数据应答="
                + message.toString());
        // å‘送命令
        send(request.getIp(), request.getPort(), message.getByteMsg());
        // -----------后端通知终端收到信息 EDN----------------------//
        log.info("分机------>>>平台:返回电缆信息,分机={},当前包:{},信息={}", ser.getName(),
                curPacket, content);
        // è¯¦ç»†ä¿¡æ¯ï¼Œæ¯é•¿åº¦5为一组数据
        start = 4;
        temp = content.substring(start * 2);
        String redisKey = RedisConst.buildKey(ser.getCompanyId(),
                RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId() + "_"
                        + passCode);
        List<GrainSerCableData> dataList = null;
        if (curPacket != 1) {
            dataList = (List<GrainSerCableData>) redisUtil.get(redisKey);
        }
        if (null == dataList)
            dataList = new ArrayList<>();
        GrainSerCableData data;
        String str1 = temp.substring(0, 160);// æ¸©åº¦ç‚¹ 40个
        String str2 = temp.substring(160, 400);// 1个根号,1个点号,1个配置,功能40组
        String temp1, temp2;
        for (int i = 0; i < 40; i++) {
            data = new GrainSerCableData();
            data.setPassCode(passCode);
            data.setIotNum(i + 1);
            data.setReceiveDate(new Date());
            //data.setPointIndex(dataList.size() + i + 1);
            // æ¸©åº¦
            temp1 = str1.substring(i * 4, i * 4 + 4);
            data.setTemp(BytesUtil.hexToInt(BytesUtil.tran_LH(temp1)) / 10.0);
            //根号
            temp2 = str2.substring(i * 6, i * 6 + 6);
            data.setRootIndex(BytesUtil.hexToInt(temp2.substring(0, 2)));
            //点号
            data.setPointIndex(BytesUtil.hexToInt(temp2.substring(2, 4)));
            //配置
            data.setConf(temp2.substring(4, 6));
            dataList.add(data);
        }
        // å­˜æ”¾ç·©å­˜
        redisUtil.set(redisKey, dataList, 5 * 60);
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS, "系统收到电缆配置信息,请手动刷新,分机="
                        + ser.getName() + ",通道=" + passCode + ",总包="
                        + sumPacket + ",当前包=" + curPacket);
    }
    /**
     * ç”µç¼†æ±‡æ€»åº”ç­”
     *
     * @param reMessage
     * @param ser
     */
    public void analysis8823(ReMessage reMessage, DeviceSer ser) {
        // å¼€å§‹è§£æž
        String content = reMessage.getBody().getContent();
        // åŠ¨æ€æ‹¼æŽ¥å¯¹è±¡
        List<GrainSerCableData> dataList = new ArrayList<GrainSerCableData>();
        String tempStr;
        GrainSerCableData cableData;
        for (int i = 0; i < content.length() / 4; i++) {
            tempStr = content.substring(i * 4, i * 4 + 4);
            cableData = new GrainSerCableData();
            cableData.setPassCode(i + 1);
            cableData.setReceiveDate(new Date());
            cableData.setIotNum(BytesUtil.hexToInt(tempStr.substring(0, 2)));
            cableData.setIotErrNum(BytesUtil.hexToInt(tempStr.substring(2, 4)));
            dataList.add(cableData);
        }
        String redisKey = RedisConst.buildKey(ser.getCompanyId(),
                RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId());
        // å­˜æ”¾ç·©å­˜
        redisUtil.set(redisKey, dataList, 5 * 60);
        notifyWebInvoker.notifyWeb(ser.getCompanyId(),
                OrderRespEnum.MSG_SUCCESS, BizType.SYS,
                "系统收到电缆汇总信息,请手动更新查看,返回信息:分机=" + ser.getName());
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisGrain.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,819 @@
package com.ld.igds.protocol.zldz.analysis;
import com.ld.igds.common.CoreCommonService;
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.notify.NotifyGrainInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.BaseRequest;
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.zldz.analysis.message.ReMessage;
import com.ld.igds.protocol.zldz.command.RemoteGrainServiceImpl;
import com.ld.igds.protocol.zldz.task.CommandReSendService;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.th.CoreThService;
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;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * ç²®æƒ…解析
 *
 * @author Andy
 */
@Slf4j
@Component(AnalysisGrain.BEAN_ID)
public class AnalysisGrain {
    public static final String BEAN_ID = "zldz.analysisGrain";
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private CoreThService thService;
    @Autowired
    private ExeOrderService exeOrderService;
    @Autowired
    private GrainUtil grainUtil;
    @Autowired
    private NotifyGrainInvoker notifyGrainInvoker;
    @Autowired
    private RemoteGrainServiceImpl remoteGrainService;
    @Autowired
    private CommandReSendService commandReSendService;
    @Autowired
    private WarnUtils warnUtils;
    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;
    /**
     * åŽå°å‘送请求后,终端的响应
     *
     * @param reMessage
     * @param ser
     */
    public void analysis8815(ReMessage reMessage, DeviceSer ser) {
        BaseRequest request = new BaseRequest();
        request.setSerId(ser.getId());
        request.setCompanyId(ser.getCompanyId());
        request.setIp(reMessage.getIp());
        request.setPort(reMessage.getPort());
        request.setSerName(ser.getName());
        remoteGrainService.reply8815(request);
    }
    /**
     * æŽ¥æ”¶åˆ°ç²®æƒ…的回复
     *
     * @param reMessage
     * @param ser
     */
    public void reply8817(ReMessage reMessage, DeviceSer ser) {
        String bodyMsg = reMessage.getBody().getContent();
        log.info("分机------>>>平台:收到的粮情信息-{}-{}-{}", ser.getCompanyId(),
                ser.getName(), reMessage.getStrMsg());
        // Step1根据需要简化需要的信息
        String ua = bodyMsg.substring(0 * 2, 1 * 2);
        log.debug("获取到的电压信息,系统不保留={}", ua);
        // æ€»åŒ…æ•°
        // int sumPacket = BytesUtil.hexToInt(bodyMsg.substring(1 * 2, 1 * 2 + 1
        // * 2));
        // å½“前包
        String hexCurPacket = bodyMsg.substring(2 * 2, 2 * 2 + 1 * 2);
        // int curPacket = BytesUtil.hexToInt(hexCurPacket);
        BaseRequest request = new BaseRequest();
        request.setSerId(ser.getId());
        request.setCompanyId(ser.getCompanyId());
        request.setIp(reMessage.getIp());
        request.setPort(reMessage.getPort());
        request.setSerName(ser.getName());
        remoteGrainService.reply8817(request, hexCurPacket);
    }
    @Transactional
    public void analysis8817(ReMessage msg, DeviceSer ser) {
        // æŽ¥åˆ°ä¿¡æ¯å›žå¤--主机
        reply8817(msg, ser);
        // é¦–先获取到系统参数,判断是否需要批次自动优化
        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);
            notifyGrainInvoker.notifyWeb(ser.getCompanyId(),
                    OrderRespEnum.MSG_ERROR, BizType.GRAIN, info);
            return;
        }
        ExeRequest exeRequest = list.get(0);
        log.info("获取粮情命令信息={}", exeRequest);
        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;
        }
        analysisStep(depotConf, msg, ser, exeRequest, sysConf);
    }
    /**
     * å¼€å§‹è§£æž
     *
     * @param ser
     * @param msg
     * @throws Exception
     */
    private void analysisStep(DepotConf depotConf, ReMessage msg,
                              DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) {
        // ç²®æƒ…的批次号重新根据频率调整
        msg.setBatchId(ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq()));
        String bodyMsg = msg.getBody().getContent();
        log.debug("{}-{}=收到的粮情信息={}", ser.getCompanyId(), ser.getName(),
                msg.getStrMsg());
        // Step1根据需要简化需要的信息
        String ua = bodyMsg.substring(0 * 2, 1 * 2);
        log.debug("获取到的电压信息,系统不保留={}", ua);
        // æ€»åŒ…æ•°
        int sumPacket = BytesUtil.hexToInt(bodyMsg.substring(1 * 2,
                1 * 2 + 1 * 2));
        // å½“前包
        String hexCurPacket = bodyMsg.substring(2 * 2, 2 * 2 + 1 * 2);
        int curPacket = BytesUtil.hexToInt(hexCurPacket);
        log.debug("分机={},包总数={},当前包={}", ser.getName(), sumPacket, curPacket);
        // ç²®é£Ÿæ¸©åº¦ä¿¡æ¯
        String grainStr = bodyMsg.substring(3 * 2);
        String contextKey = this.buildContextKey(msg, depotConf.getDepotId());
        String curKey = this.buildCurKey(msg, curPacket);
        Map<String, String> curMap = contextMap.get(contextKey);
        if (null == curMap) {
            curMap = new HashMap<>();
            contextMap.put(contextKey, curMap);
        }
        contextMap.get(contextKey).put(curKey, grainStr);
        // æ•°æ®å‡†å¤‡å¥½ï¼Œå¼€å§‹æ‰§è¡Œè§£æž
        if (curPacket == sumPacket) {
            analysisStep0(depotConf, msg, ser, exeRequest, contextKey,
                    sumPacket, sysConf);
            log.info("分机------>>>平台:命令类型=8817--粮情全部收到,开始解析-{}-{}",
                    ser.getCompanyId(), ser.getName());
            // æ¸…除命令
            commandReSendService.cleanKey(msg.getCompanyId(), msg.getIp(),
                    msg.getPort(), ServerUtils.MSG_TYPE_8817);
        }
    }
    private void analysisStep0(DepotConf depotConf, ReMessage msg,
                               DeviceSer ser, ExeRequest exeRequest, String contextKey,
                               int sumPacket, DicSysConf sysConf) {
        Map<String, String> curMap = contextMap.get(contextKey);
        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, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) {
                analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else {
                analysisStep1(depotConf, msg, ser, exeRequest, curMap, sumPacket, 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, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) {
                analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else {
                analysisStep1(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            }
            return;
        }
        // æ‰¹é‡é‡‡é›†æ‰€æœ‰å…³è”一起采集,遍历执行
        for (DepotConf depotConfTemp : depotConfs) {
            if (DepotType.TYPE_02.getCode().equals(depotConfTemp.getDepotType())) {
                analysisStep2(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else if (DepotType.TYPE_04.getCode().equals(depotConfTemp.getDepotType())) {
                analysisStep2(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            } else {
                analysisStep1(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf);
            }
        }
    }
    /**
     * åœ†ç­’仓的粮情解析
     *
     * @param depotConf
     * @param msg
     * @param ser
     * @param exeRequest
     * @param packetMap
     * @param sumPackets
     */
    private void analysisStep2(DepotConf depotConf, ReMessage msg,
                               DeviceSer ser, ExeRequest exeRequest,
                               Map<String, String> packetMap, int sumPackets, 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 = "";
        for (int i = 1; i <= sumPackets; i++) {
            strPoints += packetMap.get(buildCurKey(msg, i));
        }
        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());
        THDto thDto = thService.getCacheTH(exeRequest.getCompanyId(), exeRequest.getTempSerId(), exeRequest.getThConf());
        if (null != thDto) {
            log.debug("-------THDto--={}", thDto.toString());
        }
        // å°†é›†åˆè§£æžæˆåæ ‡æ•°æ®
        addPoint2(temps, msg, depotConf, exeRequest, thDto, 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 msg
     * @param ser
     * @param exeRequest
     * @param packetMap
     * @param sumPackets
     */
    private void analysisStep1(DepotConf depotConf, ReMessage msg,
                               DeviceSer ser, ExeRequest exeRequest,
                               Map<String, String> packetMap, int sumPackets, DicSysConf sysConf) {
        // èŽ·å–å®Œæ•´çš„ç²®æƒ…åŒ…ä¿¡æ¯
        String strPoints = "";
        for (int i = 1; i <= sumPackets; i++) {
            strPoints += packetMap.get(buildCurKey(msg, i));
        }
        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());
        THDto thDto = thService.getCacheTH(exeRequest.getCompanyId(),
                exeRequest.getTempSerId(), exeRequest.getThConf());
        if (null != thDto) {
            log.debug("-------THDto--={}", thDto.toString());
        }
        // å°†é›†åˆè§£æžæˆåæ ‡æ•°æ®
        addPoint1(temps, msg, depotConf, ser, exeRequest, thDto, sysConf);
    }
    private String buildCurKey(ReMessage msg, int curPacket) {
        return msg.getSourceId() + "_" + curPacket;
    }
    private String buildContextKey(ReMessage msg, String depotId) {
        return msg.getCompanyId() + "_" + msg.getSourceId() + "_" + depotId;
    }
    /**
     * å¹³æˆ¿ä»“,解析第二步,解析到坐标数据
     *
     * @param temps
     * @throws Exception
     */
    private void addPoint1(List<Double> temps, ReMessage msg,
                           DepotConf depotConf, DeviceSer ser, ExeRequest exeRequest,
                           THDto thDto, 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());
        }
        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);
        if (null != thDto) {
            log.debug("粮情解析中获取到的温湿度信息={}", thDto.toString());
            grain.setHumidityIn(thDto.getHumidityIn());
            grain.setTempIn(thDto.getTempIn());
        }
        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
     * @param thDto
     */
    private void addPoint2(List<Double> temps, ReMessage msg,
                           DepotConf depotConf, ExeRequest exeRequest, THDto thDto,
                           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);
        if (null != thDto) {
            log.debug("粮情解析中获取到的温湿度信息={}", thDto.toString());
            grain.setHumidityIn(thDto.getHumidityIn());
            grain.setTempIn(thDto.getTempIn());
        }
        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> 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;
    }
    /**
     * åè½¬åˆ— çŽ°å®žä¸­ä»Žå·¦è¾¹å¼€å§‹ï¼Œå¼ºè¡Œå°†å³è¾¹è§£æžä¸ºç¬¬ä¸€åˆ—
     *
     * @return
     */
    private List<Double> reversalCable(List<Double> temps, String cable) {
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        List<Double> t = new ArrayList<>();
        for (int i = 1; i <= temps.size(); i++) {
            t.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
            if (i % (cableY * cableZ) == 0) {
                cableX = cableX - 1;
            }
        }
        return t;
    }
    /**
     * ç”µç¼†ä»Žä¸‹é¢å¼€å§‹æ—¶ï¼Œå°†ç²®æƒ…电缆上下翻转
     *
     * @param pointsData ç²®æƒ…数据
     * @param cable      å±‚行列配置,如:4-7-11
     * @return
     */
    private String reversalUpAndDown(String pointsData, String cable) {
        String str = "";
        if (StringUtils.isEmpty(cable)) {
            str = pointsData;
        }
        String[] attCable = cable.split("-");
        int cableZ = Integer.valueOf(attCable[0]); //层
        String[] points = pointsData.split(",");
        for (int i = 0; i <= points.length - cableZ; i += cableZ) {
            for (int j = cableZ - 1; j >= 0; j--) {
                str += points[i + j];
                str += ",";
            }
        }
        return str;
    }
    /**
     * åè½¬åˆ—号验证
     * 2022å¹´5月30日 12:11:18
     * vince
     *
     * @param args
     */
    public static void main(String[] args) {
        List<Double> temps = new ArrayList<>();
        int cableZ = 3;
        int cableY = 4;
        int cableX = 6;
        for (int i = 1; i < (cableX * cableY * cableZ + 1); i++) {
            temps.add(i + 0.0);
        }
        List<Double> t = new ArrayList<>();
        for (int i = 1; i <= temps.size(); i++) {
            t.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
            if (i % (cableY * cableZ) == 0) {
                cableX = cableX - 1;
            }
        }
        for (Double x : t) {
            System.out.print(x);
            System.out.print(",");
        }
        System.out.println("--------------------------");
        int i = 15;
        int layMax = 10;
        System.out.println(i % layMax);
        System.out.println(i / layMax);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,211 @@
package com.ld.igds.protocol.zldz.analysis;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.constant.BizType;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.protocol.zldz.analysis.builder.ReMessageBuilder;
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
import com.ld.igds.protocol.zldz.task.CommandReSendService;
import com.ld.igds.protocol.zldz.util.CRC8;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
 * åè®®è§£æžå…¥å£
 *
 * @author jiazx
 */
@Slf4j
@Component(AnalysisService.BEAN_ID)
public class AnalysisService {
    public static final String BEAN_ID = "zldz.analysisService";
    @Autowired
    private CoreSerService coreSerService;
    @Autowired
    private AnalysisTH analysisTH;
    @Autowired
    private AnalysisGrain analysisGrain;
    @Autowired
    private AnalysisConf analysisConf;
    @Autowired
    private NotifyWebInvoker notifyWebInvoker;
    @Autowired
    private ExeOrderService exeOrderService;
    @Autowired
    private CommandReSendService commandReSendService;
    /**
     * @param sessionKey ip:port
     * @param strMsg
     */
    public void analysis2(String sessionKey, String strMsg) {
        String[] attr = sessionKey.split(":");
        String ip = attr[0];
        Integer port = Integer.valueOf(attr[1]);
        ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(null, ip, port, strMsg);
        if (null == reMessage || null == reMessage.getCompanyId()) {
            log.error("分机----->>>平台:返回信息没有获取组织编码信息,无法继续解析----{}", sessionKey);
            return;
        }
        DeviceSer ser = coreSerService.getCacheSer(reMessage.getCompanyId(), reMessage.getSourceId());
        if (null == ser) {
            String info = "分机=" + reMessage.getSourceId() + "返回信息没有匹配到分机,系统踢出离线。";
            log.error("分机----->>>平台:" + info);
            notifyWebInvoker.notifyWeb(reMessage.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, info);
            // æ¸…除缓存并销毁链接
            commandReSendService.destoryAndDelCache(reMessage.getCompanyId(), ip, port, reMessage.getMessageType());
            return;
        }
        log.debug("分机----->>>平台:所属组织-{},分机-{} è¿”回的命令信息={}", ser.getCompanyId(), ser.getName(), reMessage.toString());
        String checkMsg = this.checkMsg(reMessage, ser);
        if (null != checkMsg) {
            // ç³»ç»Ÿæ‹¦æˆªåˆ°äº†å¼‚常原因,不踢出连接
            if (ServerUtils.MSG_TYPE_8815.equals(reMessage.getMessageType()) || ServerUtils.MSG_TYPE_8817.equals(reMessage.getMessageType())) {
                commandReSendService.cleanKey(ser.getCompanyId(), ser.getIp(), ser.getPort(), ServerUtils.MSG_TYPE_8817);
                List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId());
                if (null != list && list.size() > 0) {
                    exeOrderService.progressError(ser.getCompanyId(), BizType.GRAIN.getCode(), list.get(0).getDepotId(), checkMsg);
                } else {
                    notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, checkMsg);
                }
            } else {
                commandReSendService.cleanKey(ser.getCompanyId(), ser.getIp(), ser.getPort(), reMessage.getMessageType());
                notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, checkMsg);
            }
            log.error("分机----->>>平台:命令验证异常:所属组织-{},异常信息-{},报文信息-{}", ser.getCompanyId(), checkMsg, reMessage.getStrMsg());
            return;
        }
        switch (reMessage.getMessageType()) {
            case ServerUtils.MSG_TYPE_8828:// æ¸©æ¹¿åº¦è§£æž
                analysisTH.analysis8828(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8815:// ç»ˆç«¯åº”答粮情请求
                analysisGrain.analysis8815(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_1117:// ç²®æƒ…数据信息
                analysisGrain.analysis8817(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_1129:// ç»ˆç«¯å‘送通道电缆数据给后台
                analysisConf.analysis1129(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8816:// è§£æžé…ç½®
                analysisConf.analysis8816(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8822:// ç”µç¼†åˆå§‹åŒ–成功
                analysisConf.analysis8822(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8823:// ç”µç¼†æ±‡æ€»åº”ç­”
                analysisConf.analysis8823(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8825:// è¯»å–通道电缆配置
                analysisConf.analysis8825(reMessage, ser);
                break;
            case ServerUtils.MSG_TYPE_8826:// ä¿®æ”¹ç”µç¼†çš„返回
                analysisConf.analysis8826(reMessage, ser);
                break;
            default:
                break;
        }
    }
    /**
     * æ ¡éªŒï¼Œæ­£å¸¸è¿”回NULL,异常返回异常原因,正常异常原因返回不踢掉重新连接
     *
     * @param message
     * @param ser
     * @return
     * @throws Exception
     */
    private String checkMsg(ReMessage message, DeviceSer ser) {
        String result;
        if (message.getResult() == 1) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šæŽ¥æ”¶çš„åº”ç­”æ ¡éªŒå¼‚å¸¸";
            return result;
        }
        if (message.getResult() == 2) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šå‘é€çš„æ•°æ®æ ¡éªŒå¼‚å¸¸";
            return result;
        }
        if (message.getResult() == 3) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šæŽ’é˜Ÿä¸­";
            return result;
        }
        if (message.getResult() == 4) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šå‘é€è¶…æ—¶é”™è¯¯";
            return result;
        }
        if (message.getResult() == 9) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šIo模块不在线";
            return result;
        }
        if (message.getResult() == 10) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šå‘é€ä¸­";
            return result;
        }
        if (message.getResult() == 11) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šæ— çº¿æ¨¡å—æ•…éšœ";
            return result;
        }
        if (message.getResult() == 12) {
            result = "分机=" + ser.getName()
                    + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šä¸»è¦æ˜¯åé¦ˆåæ ‡ç‚¹äº¤æ¢å‘½ä»¤æˆ–è€…æ˜¯ç”µç¼†ä¿®æ”¹å‘½ä»¤çš„é”™è¯¯ï¼Œæˆ–è€…ç²®æƒ…é‡‡é›†çš„å‚æ•°ä¸å¯¹";
            return result;
        }
        if (message.getResult() == 13) {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šç½‘å…³æœªæ³¨å†Œ";
            return result;
        }
        // èŽ·å–æ ¡éªŒçš„æŠ¥æ–‡ä¿¡æ¯
        int end = 4 + 18 * 2 + message.getBody().getLength() * 2;
        String checkStr = message.getStrMsg().substring(4, end);
        byte[] byteCrc16 = BytesUtil.hexStrToBytes(checkStr);
        short crc16Hex2 = CRC8.calculateCrc16(byteCrc16, (short) 0,
                (short) (byteCrc16.length));
        byte[] crc16Hex2Bytes = BytesUtil.shortToByte(crc16Hex2);
        int crc16 = BytesUtil.bytesToInt(crc16Hex2Bytes);
        String hexCrc16 = BytesUtil.intToHexStr(crc16);
        if (message.getHexCrc16().equals(hexCrc16)) {
            return null;
        } else {
            result = "分机=" + ser.getName() + " åè®®è§£æžå¤±è´¥ï¼ŒåŽŸå› ï¼šCRC16校验异常";
            return result;
        }
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/AnalysisTH.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,120 @@
package com.ld.igds.protocol.zldz.analysis;
import com.ld.igds.common.dto.THDto;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
import com.ld.igds.th.CoreThService;
import com.ld.igds.util.BytesUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
 * è§£æžæ¸©æ¹¿åº¦ä¿¡æ¯
 *
 * @author Andy
 */
@Slf4j
@Component(AnalysisTH.BEAN_ID)
public class AnalysisTH {
    public static final String BEAN_ID = "zldz.analysisTH";
    @Autowired
    private CoreThService thService;
    @Autowired
    private NotifyWebInvoker notifyWebInvoker;
    @Autowired
    private ExeOrderService exeOrderService;
    public static int ERROR_TH_TAG = -50;
    /**
     * è§£æžä»“库温湿度信息,将信息放在缓存中,以便粮情使用
     *
     * @param msg
     * @param ser
     */
    public void analysis8828(ReMessage msg, DeviceSer ser) {
        log.debug("-----------analysis8828------------{}-{}.{}", ser.getCompanyId(), ser.getIp(), ser.getPort());
        String content = msg.getBody().getContent();
        //温湿度地址,截取4位
        String temp = content.substring(0, 0 + 2 * 2);
        //高低位转换
        temp = BytesUtil.tran_LH(temp);
        int thConf = BytesUtil.hexToInt(temp);
        List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.SYS.getCode(), ser.getId() + "_" + thConf);
        ExeRequest exeRequest = list.get(0);
        int t, h;
        THDto th = new THDto();
        th.setCompanyId(ser.getCompanyId());
        th.setTempIn(Constant.ERROR_TEMP);
        th.setHumidityIn(Constant.ERROR_TEMP);
        //温度
        int start = 2, len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        t = BytesUtil.hexToInt(temp);
        if (t > 127) {//说明是负数
            t = BytesUtil.hexToInt("FF" + temp);
        }
        if (t == ERROR_TH_TAG) {
            log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getName());
            th.setRemark(ser.getName() + "温湿度解析异常,原因:没有检测到传感器");
        } else {
            th.setTempIn(Double.valueOf(t));
        }
        //湿度
        start = 3;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        h = BytesUtil.hexToInt(temp);
        if (h > 127) {//说明是负数
            h = BytesUtil.hexToInt("FF" + temp);
        }
        if (h == ERROR_TH_TAG) {
            log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getName());
            th.setRemark(ser.getName() + "温湿度解析异常,原因:没有检测到传感器");
        } else {
            th.setHumidityIn(Double.valueOf(h));
        }
        th.setSerId(ser.getId());
        if (null != exeRequest) {
            th.setThConf(exeRequest.getThConf());
        } else {
            th.setThConf(thConf + "");
        }
        log.info("仓温仓湿解析完成={}", th.toString());
        //按照分机采集来确定
        thService.setCacheTH(th);
        String info = ser.getName() + " æ¸©æ¹¿åº¦èŽ·å–å®Œæˆ";
        if (null != exeRequest) {
            //完成
            exeRequest.setMsg(info);
            exeOrderService.completeCache(exeRequest, false);
        }
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, info);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/builder/ReMessageBuilder.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,130 @@
package com.ld.igds.protocol.zldz.analysis.builder;
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
import com.ld.igds.protocol.zldz.analysis.message.ReMessageBody;
import com.ld.igds.util.BytesUtil;
import com.ld.igds.util.ContextUtil;
import java.util.Date;
/**
 * æ ¹æ®æŽ¥æ”¶åˆ°çš„信息进行封装
 *
 * @author Andy
 */
public class ReMessageBuilder {
    private final static ReMessageBuilder instance = new ReMessageBuilder();
    private ReMessageBuilder() {
    }
    public static ReMessageBuilder getInstance() {
        return instance;
    }
    /**
     * ä½¿ç”¨ä¸­å‘现CRC16可能以EE结尾,NETTY误以为是结尾导致截取少了一个EE,当前方法必须从头向后截取,保证CRC16的位置准确
     *
     * @param bytes
     * @param ip
     * @param port
     * @param strMsg
     * @return
     */
    public ReMessage buildMessage(byte[] bytes, String ip, int port, String strMsg) {
        ReMessage message = new ReMessage();
        message.setIp(ip);
        message.setPort(port);
        message.setStrMsg(strMsg);
        message.setByteMsg(bytes);
        // æºID,分机唯一ID
        int start = 2, len = 2;
        String temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setSourceId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
        //分机所属组织编码
        String companyId = ContextUtil.getCompanyIdBySn(message.getSourceId());
        // ç›®æ ‡ID
        start = 4;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setTargetId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
        // å‘送ID
        start = 6;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setSendId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
        // è·¯ç”±ä¿¡æ¯ï¼Œä¸è§£æž
        // æ¶ˆæ¯ç±»åž‹
        start = 12;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setMessageType(BytesUtil.tran_LH(temp));
        // å¤„理结果
        start = 14;
        len = 1;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setResult(BytesUtil.hexToInt(temp));
        // ç»„织编码
        start = 15;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        if(null == companyId){
            message.setCompanyId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + "");
        }else{
            message.setCompanyId(companyId);
        }
        //包头校验
        start = 17;
        len = 1;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setHexCrc8(temp);
        // å‘½ä»¤ä½“-长度
        message.setBody(buildBody());
        start = 18;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        int bodyLen = BytesUtil.hexToInt(BytesUtil.tran_LH(temp));
        message.getBody().setLength(bodyLen);
        //命令体-内容
        start = 20;
        len = bodyLen;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.getBody().setContent(temp);
        // crc16验证
        start = 20 + bodyLen;
        len = 2;
        temp = strMsg.substring(start * 2, start * 2 + len * 2);
        message.setHexCrc16(temp);
        message.setReceiveDate(new Date());
        message.setBatchId(ContextUtil.getDefaultBatchId());
        return message;
    }
    /**
     * åˆ›å»ºBODY对象
     *
     * @param
     * @return
     */
    public ReMessageBody buildBody() {
        ReMessageBody body = new ReMessageBody();
        body.setLength(0);
        body.setContent("");
        return body;
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/Metadata.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
package com.ld.igds.protocol.zldz.analysis.message;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
@Retention(RetentionPolicy.RUNTIME)
@Target(FIELD)
public @interface Metadata {
    String label() default "";
    int bytes() default 0;
    int startIndex() default 0;
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/ReMessage.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
package com.ld.igds.protocol.zldz.analysis.message;
import lombok.Data;
import java.util.Date;
/**
 * æ¶ˆæ¯å¤´å¯¹è±¡
 *
 * @author Andy
 *
 */
@Data
public class ReMessage {
    private String ip;
    private int port;
    private String begin;
    private String sourceId;// æº ID
    private String targetId;// ç›®æ ‡ID
    private String sendId;//发送者ID
    private String gateway1;//路由1
    private String gateway2;//路由2
    private String messageType;// æ¶ˆæ¯ç±»åž‹
    private int result;// å¤„理结果
    private String companyId;// ç»„织编码
    private String hexCrc8;//crc8包头校验
    private ReMessageBody body;
    private String hexCrc16;//crc16校验
    private String end;
    private byte[] byteMsg;// å½“前命令的字节信息
    private String strMsg;// å½“前命令转换为字符串的信息
    private String batchId;
    private Date receiveDate;
    // å¼‚常信息
    private String error;
    @Override
    public String toString() {
        return "ReMessage{" +
                "ip='" + ip + '\'' +
                ", port=" + port +
                ", sourceId='" + sourceId + '\'' +
                ", targetId='" + targetId + '\'' +
                ", sendId='" + sendId + '\'' +
                ", messageType='" + messageType + '\'' +
                ", result=" + result +
                ", companyId='" + companyId + '\'' +
                ", hexCrc8='" + hexCrc8 + '\'' +
                ", hexCrc16='" + hexCrc16 + '\'' +
                ", strMsg='" + strMsg + '\'' +
                '}';
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/analysis/message/ReMessageBody.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
package com.ld.igds.protocol.zldz.analysis.message;
import lombok.Data;
/**
 * æ¶ˆæ¯-消息体
 *
 * @author Andy
 *
 */
@Data
public class ReMessageBody {
    private int length;
    private String content;
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/BaseRemoteImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package com.ld.igds.protocol.zldz.command;
import com.ld.igds.io.constant.ProtocolEnum;
import com.ld.igds.protocol.zldz.server.ZldzServerEngine;
import com.ld.io.api.InvokeResult;
import com.ld.io.api.IoSession;
public class BaseRemoteImpl {
    public String getProtocol() {
        return ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode();
    }
    /**
     * å‘送命令
     *
     * @param ip
     * @param port
     * @param msg
     * @return
     */
    public InvokeResult send(String ip, int port, byte[] msg) {
        IoSession session = ZldzServerEngine.getSession(ip,port);
        if (null == session) {
            return InvokeResult.CHANNEL_CLOSED;
        }
        return session.invoke(msg);
    }
    public static void updateSession(String ip, int port, String companyId) {
        IoSession ioSession = ZldzServerEngine.getSession(ip,port);
        if(null != ioSession){
            ioSession.setCompanyId(companyId);
        }
    }
    public static InvokeResult destory(String ip, int port) {
        IoSession session = ZldzServerEngine.getSession(ip,port);
        if (null == session) {
            return InvokeResult.SUCCESS;
        }
        // æ‰§è¡Œè¿žæŽ¥é”€æ¯
        session.destroy();
        return InvokeResult.SUCCESS;
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/RemoteCommonImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,426 @@
package com.ld.igds.protocol.zldz.command;
import com.ld.igds.io.RemoteCommonService;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.*;
import com.ld.igds.io.response.BaseResponse;
import com.ld.igds.io.response.GrainResponse;
import com.ld.igds.protocol.zldz.command.builder.*;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.task.CommandReSendService;
import com.ld.igds.protocol.zldz.task.CommandTask;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * å½“前协议实现,粮情模块命令接口
 *
 * @author jiazx
 */
@Slf4j
@Component(RemoteCommonImpl.BEAN_ID)
public class RemoteCommonImpl extends BaseRemoteImpl implements RemoteCommonService {
    public static final String BEAN_ID = "zldz.remoteCommonService";
    @Autowired
    private CommandReSendService commandReSendService;
    @Override
    public BaseResponse heartBeat(BaseRequest request) {
        return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "协议不支持");
    }
    @Override
    public BaseResponse pullDevice(BaseRequest request) {
        return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "协议不支持");
    }
    @Override
    public BaseResponse pullDepot(BaseRequest request) {
        return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "协议不支持");
    }
    @Override
    public BaseResponse pullAccess(AccessRequest request) {
        return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "协议不支持");
    }
    @Override
    public BaseResponse pullDepotStatus(DepotStatusRequest request) {
        return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "协议不支持");
    }
    @Override
    public BaseResponse checkTh(CheckThRequest request) {
        try {
            Message message = CommandBuilder1128.getInstance().buildMessage(request);
            log.info("平台------>>>分机:" + request.getSerName() + "-温湿度命令信息=" + message.toString());
            // å‘送命令
            InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
            // å°è£…返回信息
            if (InvokeResult.SUCCESS == result) {
                return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                        "分机=" + request.getSerName() + "发送温湿度命令成功");
            } else {
                return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                        "分机=" + request.getSerName() + "发送温湿度命令失败:" + result.getMessage());
            }
        } catch (Exception e) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "分机=" + request.getSerName() + "温湿度命令失败:" + e.getMessage());
        }
    }
    @Override
    public BaseResponse writeConf(GrainSerConfRequest request) {
        try {
            // Step1 ç”Ÿæˆå‘½ä»¤
            Message message = CommandBuilder1116_1.getInstance().buildMessage(request);
            log.info("平台------>>>分机:" + request.getSerName() + "-写入配置命令=" + message.toString());
            // å‘送命令
            InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
            // å°è£…返回信息
            if (InvokeResult.SUCCESS == result) {
                CommandTask commandData = new CommandTask();
                commandData.setCompanyId(request.getCompanyId());
                commandData.setIp(request.getIp());
                commandData.setPort(request.getPort());
                commandData.setByteCommand(message.getByteMsg());
                commandData.setCommand(message.getStrMsg());
                commandData.setResultType(ServerUtils.MSG_TYPE_8816);
                commandReSendService.reSendTask(commandData);
                return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                        "分机=" + request.getSerName() + "写入配置命令发送成功");
            } else {
                return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                        "分机=" + request.getSerName() + "写入配置命令发送异常:" + result.getMessage());
            }
        } catch (Exception e) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "分机=" + request.getSerName() + "写入配置命令发送异常:" + e.getMessage());
        }
    }
    @Override
    public BaseResponse readConf(GrainSerConfRequest request) {
        try {
            // Step1 ç”Ÿæˆå‘½ä»¤
            Message message = CommandBuilder1116_0.getInstance().buildMessage(request);
            log.info("平台------>>>分机:" + request.getSerName() + "-读取配置命令=" + message.toString());
            // å‘送命令
            InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
            // å°è£…返回信息
            if (InvokeResult.SUCCESS == result) {
                CommandTask commandData = new CommandTask();
                commandData.setCompanyId(request.getCompanyId());
                commandData.setIp(request.getIp());
                commandData.setPort(request.getPort());
                commandData.setByteCommand(message.getByteMsg());
                commandData.setCommand(message.getStrMsg());
                commandData.setResultType(ServerUtils.MSG_TYPE_8816);
                commandReSendService.reSendTask(commandData);
                return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                        "分机=" + request.getSerName() + "读取配置命令发送成功");
            } else {
                return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                        "分机=" + request.getSerName() + "读取配置命令发送异常:" + result.getMessage());
            }
        } catch (Exception e) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "分机=" + request.getSerName() + "读取配置命令发送异常:" + e.getMessage());
        }
    }
    @Override
    public BaseResponse initCable(BaseRequest request) {
        try {
            // Step1 ç”Ÿæˆç²®æƒ…信息
            Message message = CommandBuilder1122.getInstance().buildMessage(request);
            log.info("平台------>>>分机:" + request.getSerName() + "-初始化电缆命令=" + message.toString());
            // å‘送命令
            InvokeResult result = send(request.getIp(), request.getPort(),
                    message.getByteMsg());
            // å°è£…返回信息
            if (InvokeResult.SUCCESS == result) {
                CommandTask commandData = new CommandTask();
                commandData.setCompanyId(request.getCompanyId());
                commandData.setIp(request.getIp());
                commandData.setPort(request.getPort());
                commandData.setByteCommand(message.getByteMsg());
                commandData.setCommand(message.getStrMsg());
                commandData.setResultType(ServerUtils.MSG_TYPE_8822);
                commandReSendService.reSendTask(commandData);
                return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                        "分机=" + request.getSerName() + "初始化电缆发送成功");
            } else {
                return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                        "分机=" + request.getSerName() + "初始化电缆命令发送失败:" + result.getMessage());
            }
        } catch (Exception e) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "分机=" + request.getSerName() + "初始化电缆命令执行失败:" + e.getMessage());
        }
    }
    @Override
    public BaseResponse updateGrainSerCable(GrainSerConfRequest request) {
        if (null == request.getEditTag()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "当前操作没有制定修改标识,无法执行!");
        }
        //根据修改标识处理不同的逻辑 -- 2点号修改 3列号修改,4根号修改,5同步电缆,6根号替换
        if (2 == request.getEditTag()) {
            return updateGrainSerCable2(request);
        }
        if (3 == request.getEditTag()) {
            return updateGrainSerCable3(request);
        }
        if (4 == request.getEditTag()) {
            return updateGrainSerCable4(request);
        }
        if (5 == request.getEditTag()) {
            return updateGrainSerCable5(request);
        }
        if (6 == request.getEditTag()) {
            return updateGrainSerCable6(request);
        }
        return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                "没有匹配到当前需要操作的标识,标识=" + request.getEditTag());
    }
    /**
     * æ ¹å·æ›¿æ¢
     *
     * @param request
     * @return
     */
    private BaseResponse updateGrainSerCable6(GrainSerConfRequest request) {
        if (null == request.getValue1() || null == request.getValue2()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "替换操作中,没有获取到新旧参数配置!");
        }
        // Step1
        Message message = CommandBuilder1126.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "电缆-根号替换命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号替换发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号替换发送失败:" + result.getMessage());
        }
    }
    /**
     * @param request
     * @return
     */
    private BaseResponse updateGrainSerCable5(GrainSerConfRequest request) {
        if (null == request.getValue1() || null == request.getValue2()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "同步电缆失败,同步电缆参数不完整");
        }
        // Step1
        Message message = CommandBuilder1126.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "同步电缆-命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号替换发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号替换发送失败:" + result.getMessage());
        }
    }
    private BaseResponse updateGrainSerCable4(GrainSerConfRequest request) {
        if (null == request.getValue1() || null == request.getValue2()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "替换操作中,没有获取到新旧参数配置!");
        }
        //输入值需要-1
        request.setValue1(request.getValue1() - 1);
        request.setValue2(request.getValue2() - 1);
        // Step1
        Message message = CommandBuilder1126.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "-电缆-根号修改命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号修改命令发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆-根号修改命令发送失败:" + result.getMessage());
        }
    }
    private BaseResponse updateGrainSerCable3(GrainSerConfRequest request) {
        if (null == request.getEditCol()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "替换操作中,没有获取列参数!");
        }
        // Step1
        Message message = CommandBuilder1126.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "电缆-列号修改命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆-列号修改命令发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆-列号修改命令发送失败:" + result.getMessage());
        }
    }
    private BaseResponse updateGrainSerCable2(GrainSerConfRequest request) {
        if (null == request.getValue1() || null == request.getValue2()) {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "替换操作中,没有获取到新旧参数配置!");
        }
        //输入值需要-1
        request.setValue1(request.getValue1() - 1);
        request.setValue2(request.getValue2() == null ? 0 : request.getValue2());
        // Step1 ç”Ÿæˆå‘½ä»¤
        Message message = CommandBuilder1126.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "电缆-点号修改命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆-点号修改命令发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆-点号修改命令发送失败:" + result.getMessage());
        }
    }
    /**
     * èŽ·å–é€šé“ç”µç¼†
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse checkGrainSerCable(GrainSerConfRequest request) {
        // Step1 ç”Ÿæˆç²®æƒ…信息
        Message message = CommandBuilder1125.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "获取通道电缆命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "获取通道电缆命令发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "获取通道电缆命令发送失败:" + result.getMessage());
        }
    }
    @Override
    public BaseResponse destroyCon(BaseRequest request) {
        InvokeResult result = destory(request.getIp(), request.getPort());
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "断开连接执行成功");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "分机=" + request.getSerName() + "断开连接失败:" + result.getMessage());
        }
    }
    @Override
    public BaseResponse updateSysDepotConf(BaseRequest request) {
        return new BaseResponse(OrderRespEnum.NO_FUNCTION);
    }
    @Override
    public BaseResponse sumGrainSerCable(GrainSerConfRequest request) {
        // Step1
        Message message = CommandBuilder1123.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" + request.getSerName() + "电缆汇总命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机=" + request.getSerName() + "电缆汇总命令发送成功!");
        } else {
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机=" + request.getSerName() + "电缆汇总命令发送失败:" + result.getMessage());
        }
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/RemoteGrainServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,129 @@
package com.ld.igds.protocol.zldz.command;
import com.ld.igds.io.RemoteGrainService;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.io.request.CheckGrainRequest;
import com.ld.igds.io.response.BaseResponse;
import com.ld.igds.io.response.GrainResponse;
import com.ld.igds.protocol.zldz.command.builder.CommandBuilder1115;
import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8815;
import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8817;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.task.CommandReSendService;
import com.ld.igds.protocol.zldz.task.CommandTask;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * ç²®æƒ…协议,直接获取粮情,温湿度信息通过心跳定时获取。
 *
 * @author jiazx
 */
@Slf4j
@Component(RemoteGrainServiceImpl.BEAN_ID)
public class RemoteGrainServiceImpl extends BaseRemoteImpl implements
        RemoteGrainService {
    public static final String BEAN_ID = "zldz.remoteGrainService";
    @Autowired
    private CommandReSendService commandReSendService;
    /**
     * ç²®æƒ…检测,首先需要执行温湿度检测,温湿度检测完成后,再进粮情检测。
     * æ¸©æ¹¿åº¦çš„信息根据分机和温湿度地址存在缓存30分钟,30分钟内不重复采集,系统判断与当前时间差距离当前时间是否超过25分钟
     * ï¼Œè¶…过重新获取,没有超过直接采集粮情
     *
     * @param request
     * @return
     */
    @Override
    public GrainResponse checkGrain(CheckGrainRequest request) {
        // Step1 ç”Ÿæˆç²®æƒ…信息
        Message message = CommandBuilder1115.getInstance().buildMessage(request);
        log.info("平台------>>>分机:" +request.getSerName() + "-粮情采集命令=" + message.toString());
        InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            CommandTask commandData = new CommandTask();
            commandData.setCompanyId(request.getCompanyId());
            commandData.setIp(request.getIp());
            commandData.setPort(request.getPort());
            commandData.setByteCommand(message.getByteMsg());
            commandData.setCommand(message.getStrMsg());
            commandData.setResultType(ServerUtils.MSG_TYPE_8817);
            commandData.setCableRule(request.getCableRule());
            commandData.setSerName(request.getSerName());
            commandData.setDepotId(request.getDepotId());
            commandReSendService.reSendGrainTask(commandData);
            return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "粮情采集命令发送成功");
        } else {
            log.info("分机" + request.getSerName() + "粮情采集命令发送失败:" + result.getMessage());
            return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), result.getMessage());
        }
    }
    /**
     * æœåŠ¡å™¨å›žå¤ç»ˆç«¯çš„æ”¶åˆ°è¯·æ±‚
     *
     * @param request
     */
    public BaseResponse reply8815(BaseRequest request) {
        // Step1 ç”Ÿæˆç²®æƒ…信息
        Message message = CommandBuilder8815.getInstance().buildMessage(
                request);
        log.debug("平台------>>>分机:" +request.getSerName() + "-粮情服务端回复命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机" + request.getSerName() + "粮情服务端回复命令发送成功");
        } else {
            log.error("分机" + request.getSerName() + "粮情服务端回复命令发送失败:" + result.getMessage());
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机" + request.getSerName() + "粮情服务端回复命令发送失败:" + result.getMessage());
        }
    }
    /**
     * å›žå¤å‘½ä»¤
     *
     * @param request
     * @param hexCurPacket å½“前包的hex
     */
    public BaseResponse reply8817(BaseRequest request, String hexCurPacket) {
        // Step1 ç”Ÿæˆç²®æƒ…信息,把信息放在request
        request.setBizType(hexCurPacket);
        Message message = CommandBuilder8817.getInstance().buildMessage(request);
        log.debug("平台------>>>分机:" +request.getSerName() + "-粮情服务端回复收到粮情包命令=" + message.toString());
        // å‘送命令
        InvokeResult result = send(request.getIp(), request.getPort(),
                message.getByteMsg());
        // å°è£…返回信息
        if (InvokeResult.SUCCESS == result) {
            return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(),
                    "分机" + request.getSerName() + "粮情服务端回复收到粮情包命令发送成功");
        } else {
            log.info("分机" + request.getSerName() + "粮情服务端回复收到粮情包命令发送失败:" + result.getMessage());
            return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(),
                    "分机" + request.getSerName() + "粮情服务端回复收到粮情包命令发送失败:" + result.getMessage());
        }
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,144 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.CRC8;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * å‘½ä»¤ç”Ÿæˆå™¨
 *
 * @author Andy
 */
public abstract class CommandBuilder {
    /*
     * å‘½ä»¤åˆ›å»º
     *
     * @param order
     */
    public Message buildMessage(BaseRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        //包头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, BaseRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setSourceId(BytesUtil.getTargetId(request.getSerId(), true));
        message.setMessageType(ServerUtils.MSG_TYPE_1116);
    }
    public void buildBody(Message message, BaseRequest request) {
        MessageBody body = new MessageBody();
        body.setContent("");
        body.setLength(0);
        message.setBody(body);
    }
    public void buildCrc8(Message message) {
        StringBuffer hexSbCrc8 = new StringBuffer();
        hexSbCrc8.append(message.getSourceId());
        hexSbCrc8.append(message.getTargetId());
        hexSbCrc8.append(message.getSendId());
        hexSbCrc8.append(message.getGateway1());
        hexSbCrc8.append(message.getGateway2());
        hexSbCrc8.append(message.getMessageType());
        hexSbCrc8.append(message.getResult());
        hexSbCrc8.append(message.getCompanyId());
        byte[] bytes = BytesUtil.hexStrToBytes(hexSbCrc8.toString());
        byte crc8 = CRC8.calcCrc8(bytes, (short) 0, (short) (bytes.length),
                (byte) 0);
        message.setHexCrc8(BytesUtil.byteToHex(crc8));
    }
    public void buildCrc16(Message message) {
        StringBuffer hexSbCrc16 = new StringBuffer();
        hexSbCrc16.append(message.getSourceId());
        hexSbCrc16.append(message.getTargetId());
        hexSbCrc16.append(message.getSendId());
        hexSbCrc16.append(message.getGateway1());
        hexSbCrc16.append(message.getGateway2());
        hexSbCrc16.append(message.getMessageType());
        hexSbCrc16.append(message.getResult());
        hexSbCrc16.append(message.getCompanyId());
        hexSbCrc16.append(message.getHexCrc8());
        hexSbCrc16.append(BytesUtil.tran_LH(BytesUtil
                .getHex2LenStr(message.getBody().getLength())));
        hexSbCrc16.append(message.getBody().getContent());
        byte[] byteCrc16 = BytesUtil.hexStrToBytes(hexSbCrc16.toString());
        short crc16Hex2 = CRC8.calculateCrc16(byteCrc16, (short) 0, (short) (byteCrc16.length));
        byte[] crc16Hex2Bytes = BytesUtil.shortToByte(crc16Hex2);
        int crc16 = BytesUtil.bytesToInt(crc16Hex2Bytes);
        message.setHexCrc16(BytesUtil.intToHexStr(crc16));
    }
    /**
     * æ ¹æ®ç”Ÿæˆçš„命令,进行调整
     *
     * @param message
     */
    public void build(Message message) {
        StringBuffer hexSb = new StringBuffer();
        hexSb.append(message.getBegin());
        hexSb.append(message.getSourceId());
        hexSb.append(message.getTargetId());
        hexSb.append(message.getSendId());
        hexSb.append(message.getGateway1());
        hexSb.append(message.getGateway2());
        hexSb.append(message.getMessageType());
        hexSb.append(message.getResult());
        hexSb.append(message.getCompanyId());
        hexSb.append(message.getHexCrc8());
        hexSb.append(BytesUtil.tran_LH(BytesUtil
                .getHex2LenStr(message.getBody().getLength())));
        hexSb.append(message.getBody().getContent());
        hexSb.append(message.getHexCrc16());
        hexSb.append(message.getEnd());
        message.setStrMsg(hexSb.toString());
        message.setByteMsg(BytesUtil.hexStrToBytes(message.getStrMsg()));
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1115.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,79 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.io.request.CheckGrainRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…信息命令
 *
 * @author Andy
 */
public class CommandBuilder1115 extends CommandBuilder {
    private final static CommandBuilder1115 instance = new CommandBuilder1115();
    private CommandBuilder1115() {
    }
    public static CommandBuilder1115 getInstance() {
        return instance;
    }
    public Message buildMessage(CheckGrainRequest request) {
        //request.setCompanyId("1");
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        //包头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, BaseRequest order) {
        String hexCompanyId = BytesUtil.getTargetId(order.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(order.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1115));
    }
    public void buildBody(Message message, CheckGrainRequest order) {
        MessageBody body = new MessageBody();
        body.setLength(2);
        int start = order.getCableStart();
        int end = order.getCableEnd();
        body.setContent(BytesUtil.toHexString(start) + BytesUtil.toHexString(end));
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1116_0.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,83 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 *
 * @author Andy
 */
public class CommandBuilder1116_0 extends CommandBuilder {
    private final static CommandBuilder1116_0 instance = new CommandBuilder1116_0();
    private CommandBuilder1116_0() {
    }
    public static CommandBuilder1116_0 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        //包头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
//        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
//
//        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
//        message.setSourceId(hexCompanyId);
//        message.setSendId(hexCompanyId);
//
//        //发送的必须是原来的组织编码
//         String orgId = BytesUtil.tran_LH(BytesUtil.getTargetId(request.getOrgId(),true));
//         message.setCompanyId(orgId);
//
//        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setSourceId("0000");
        message.setSendId("0000");
        message.setCompanyId("0000");
        message.setTargetId("FFFF");
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116));
    }
    public void buildBody(Message message, GrainSerConfRequest request) {
        MessageBody body = new MessageBody();
        body.setContent("0000000000000000000000000000");
        body.setLength(14);
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1116_1.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,97 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
import org.apache.commons.lang3.StringUtils;
/**
 *
 * @author Andy
 */
public class CommandBuilder1116_1 extends CommandBuilder {
    private final static CommandBuilder1116_1 instance = new CommandBuilder1116_1();
    private CommandBuilder1116_1() {
    }
    public static CommandBuilder1116_1 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        //包头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        //发送的必须是原来的组织编码
        String orgId = BytesUtil.tran_LH(BytesUtil.getTargetId(request.getOrgId(),true));
        message.setCompanyId(orgId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116));
    }
    public void buildBody(Message message, GrainSerConfRequest request) {
        MessageBody body = new MessageBody();
        StringBuffer content = new StringBuffer();
        content.append("01");//写标记
        content.append(message.getTargetId());
        content.append(BytesUtil.getTargetId("01",false));//网络ID
        content.append("0A");//默认10 ä¿¡é“
        content.append(BytesUtil.getTargetId("03",false));//速率
        content.append(BytesUtil.toHexString(request.getCableZ()));
        content.append(BytesUtil.toHexString(request.getCableY()));
        content.append(BytesUtil.toHexString(request.getCableX()));
        content.append(BytesUtil.getTargetId(request.getCableFormat(),false));
        content.append(BytesUtil.getTargetId(request.getCableType(),false));
        if(StringUtils.isEmpty(request.getPowerModel())){
            request.setPowerModel("02");
        }
        content.append(BytesUtil.getTargetId(request.getPowerModel(),false));
        content.append(message.getSourceId());
        body.setContent(content.toString());
        body.setLength(14);
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1122.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * åˆå§‹åŒ–电缆电缆
 *
 * @author Andy
 */
public class CommandBuilder1122 extends CommandBuilder {
    private final static CommandBuilder1122 instance = new CommandBuilder1122();
    private CommandBuilder1122() {
    }
    public static CommandBuilder1122 getInstance() {
        return instance;
    }
    public void buildHeader(Message message, BaseRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1122));
    }
    public void buildBody(Message message, BaseRequest request) {
        MessageBody body = new MessageBody();
        body.setContent("01");
        body.setLength(1);
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1123.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,65 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…分机-电缆汇总
 *
 * @author Andy
 */
public class CommandBuilder1123 extends CommandBuilder {
    private final static CommandBuilder1123 instance = new CommandBuilder1123();
    private CommandBuilder1123() {
    }
    public static CommandBuilder1123 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        // åŒ…头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),
                true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(
                request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1123));
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1125.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…分机-电缆检测
 *
 * @author Andy
 */
public class CommandBuilder1125 extends CommandBuilder {
    private final static CommandBuilder1125 instance = new CommandBuilder1125();
    private CommandBuilder1125() {
    }
    public static CommandBuilder1125 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        // åŒ…头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),
                true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(
                request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1125));
    }
    public void buildBody(Message message, GrainSerConfRequest request) {
        MessageBody body = new MessageBody();
        body.setLength(1);
        body.setContent(BytesUtil.toHexString(request.getPassCode()));
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1126.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,100 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…分机-修改通道电缆
 *
 * @author Andy
 */
public class CommandBuilder1126 extends CommandBuilder {
    private final static CommandBuilder1126 instance = new CommandBuilder1126();
    private CommandBuilder1126() {
    }
    public static CommandBuilder1126 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        // åŒ…头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),
                true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(
                request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1126));
    }
    public void buildBody(Message message, GrainSerConfRequest request) {
        MessageBody body = new MessageBody();
        body.setLength(5);
        StringBuilder bodyStr = new StringBuilder();
        // ä¿®æ”¹æ ‡è¯†
        bodyStr.append(BytesUtil.toHexString(request.getEditTag()));
        // é€šé“号
        bodyStr.append(BytesUtil.toHexString(request.getPassCode()));
        // åˆ—号
        bodyStr.append(BytesUtil.toHexString(request.getEditCol()));
        // ç‚¹åºå·/原根号/起始根号/根序号
        // æ–°ç‚¹å·/新根号/电缆层数/新根号
        if (6 == request.getEditTag()) {
            bodyStr.append(BytesUtil.toHexString(request.getValue1()));
            bodyStr.append(BytesUtil.toHexString(request.getValue2()));
        } else if (5 == request.getEditTag()) {
            bodyStr.append(BytesUtil.toHexString(request.getValue1()));
            bodyStr.append(BytesUtil.toHexString(request.getValue2()));
        } else if (4 == request.getEditTag()) {
            bodyStr.append(BytesUtil.toHexString(request.getValue1()));
            bodyStr.append(BytesUtil.toHexString(request.getValue2()));
        } else if (2 == request.getEditTag()) {
            bodyStr.append(BytesUtil.toHexString(request.getValue1()));
            bodyStr.append(BytesUtil.toHexString(request.getValue2()));
        } else {
            bodyStr.append("00");
            bodyStr.append("00");
        }
        body.setContent(bodyStr.toString());
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder1128.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.CheckThRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ä»“温仓湿命令
 *
 * @author Andy
 */
public class CommandBuilder1128 extends CommandBuilder {
    private final static CommandBuilder1128 instance = new CommandBuilder1128();
    private CommandBuilder1128() {
    }
    public static CommandBuilder1128 getInstance() {
        return instance;
    }
    public Message buildMessage(CheckThRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        //包头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, CheckThRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1128));
    }
    public void buildBody(Message message, CheckThRequest request) {
        MessageBody body = new MessageBody();
        body.setLength(2);
        body.setContent(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getThConf(), true)));
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8815.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…信息命令
 *
 * @author Andy
 */
public class CommandBuilder8815 extends CommandBuilder {
    private final static CommandBuilder8815 instance = new CommandBuilder8815();
    private CommandBuilder8815() {
    }
    public static CommandBuilder8815 getInstance() {
        return instance;
    }
    public void buildHeader(Message message, BaseRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8815));
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8817.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…信息命令
 *
 * @author Andy
 */
public class CommandBuilder8817 extends CommandBuilder {
    private final static CommandBuilder8817 instance = new CommandBuilder8817();
    private CommandBuilder8817() {
    }
    public static CommandBuilder8817 getInstance() {
        return instance;
    }
    public void buildHeader(Message message, BaseRequest request) {
        //request.setCompanyId("1");
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8817));
    }
    public void buildBody(Message message, BaseRequest request) {
        MessageBody body = new MessageBody();
        body.setContent(request.getBizType());
        body.setLength(1);
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/CommandBuilder8829.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.GrainSerConfRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 * ç²®æƒ…分机-电缆汇总
 *
 * @author Andy
 */
public class CommandBuilder8829 extends CommandBuilder {
    private final static CommandBuilder8829 instance = new CommandBuilder8829();
    private CommandBuilder8829() {
    }
    public static CommandBuilder8829 getInstance() {
        return instance;
    }
    public Message buildMessage(GrainSerConfRequest request) {
        Message message = new Message();
        message.setBegin(ServerUtils.MSG_START);
        // è°ƒæ•´Message头部信息
        buildHeader(message, request);
        // åŒ…头校验
        buildCrc8(message);
        // åˆ›å»ºæ¶ˆæ¯ä½“
        buildBody(message, request);
        // æ·»åŠ æ ¡éªŒ
        buildCrc16(message);
        message.setEnd(ServerUtils.MSG_END);
        // ç”Ÿæˆæ•´ä½“命令信息和BYte信息
        build(message);
        return message;
    }
    public void buildHeader(Message message, GrainSerConfRequest request) {
        String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),
                true);
        hexCompanyId = BytesUtil.tran_LH(hexCompanyId);
        message.setSourceId(hexCompanyId);
        message.setSendId(hexCompanyId);
        message.setCompanyId(hexCompanyId);
        message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(
                request.getSerId(), true)));
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8829));
    }
    public void buildBody(Message message, GrainSerConfRequest request) {
        MessageBody body = new MessageBody();
        body.setLength(1);
        body.setContent(BytesUtil.toHexString(request.getValue1()));
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/builder/OnLineCommandBuilder.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,40 @@
package com.ld.igds.protocol.zldz.command.builder;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.command.message.MessageBody;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
/**
 *
 * @author Andy
 */
public class OnLineCommandBuilder extends CommandBuilder {
    private final static OnLineCommandBuilder instance = new OnLineCommandBuilder();
    private OnLineCommandBuilder() {
    }
    public static OnLineCommandBuilder getInstance() {
        return instance;
    }
    public void buildHeader(Message message, BaseRequest request) {
        message.setSourceId("0000");
        message.setSendId("0000");
        message.setCompanyId("0000");
        message.setTargetId("FFFF");
        message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116));
    }
    public void buildBody(Message message, BaseRequest request) {
        MessageBody body = new MessageBody();
        body.setContent("0000000000000000000000000000");
        body.setLength(14);
        message.setBody(body);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/message/Message.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,52 @@
package com.ld.igds.protocol.zldz.command.message;
import lombok.Data;
/**
 * å­—符串值均采用十六进制,方便校验和开发
 */
@Data
public class Message {
    private String begin;
    private String sourceId;// æº ID
    private String targetId="FFFF";// ç›®æ ‡ID
    private String sendId;//发送者ID
    private String gateway1 = "0100";//路由1
    private String gateway2 = "0000";//路由2
    private String messageType;// æ¶ˆæ¯ç±»åž‹
    private String result ="00";// å¤„理结果
    private String companyId;// ç»„织编码
    private String hexCrc8;//crc8包头校验
    private MessageBody body;
    private String hexCrc16;//crc16校验
    private String end;
    private byte[] byteMsg;// å½“前命令的字节信息
    private String strMsg;// å½“前命令转换为字符串的信息
    @Override
    public String toString() {
        return "Message [sourceId=" + sourceId
                + ", targetId=" + targetId
                + ", messageType=" + messageType
                + ", result=" + result + ", companyId=" + companyId
                + ", hexCrc8=" + hexCrc8 + ", body=" + body + ", hexCrc16="
                + hexCrc16 + ", strMsg=" + strMsg + "]";
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/command/message/MessageBody.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package com.ld.igds.protocol.zldz.command.message;
import lombok.Data;
@Data
public class MessageBody {
    //默认10进制长度
    private int length = 0;
    //消息体内容
    private String content = "";
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/PublisherControl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,42 @@
package com.ld.igds.protocol.zldz.mq;
import com.ld.igds.io.constant.ProtocolEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
/**
 * æŽ§åˆ¶ç»ˆç«¯ä½œä¸ºå‘布者发布信息,服务端作为订阅者订阅,通道定义为当前协议编码
 */
@Slf4j
@Component(PublisherControl.BEAN_ID)
public class PublisherControl {
    public static final String BEAN_ID = "zldz.redisPublisher";
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    /**
     * æ­£å¸¸è¿”回信息获取
     *
     * @param reMessage
     */
    public void publishMessage(String reMessage) {
        redisTemplate.convertAndSend(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode(), reMessage);
        log.debug("-----------报文信息存入队列------{}", reMessage);
    }
    /**
     * ç™»å½•信息获取
     *
     * @param sessionKey
     */
    public void publishLoginMessage(String sessionKey) {
        redisTemplate.convertAndSend(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode() + "_LOGIN", sessionKey);
        log.debug("-----------登录信息存入队列------{}", sessionKey);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/ReceiverServer.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,90 @@
package com.ld.igds.protocol.zldz.mq;
import com.ld.igds.io.request.BaseRequest;
import com.ld.igds.protocol.zldz.analysis.AnalysisService;
import com.ld.igds.protocol.zldz.command.builder.OnLineCommandBuilder;
import com.ld.igds.protocol.zldz.command.message.Message;
import com.ld.igds.protocol.zldz.server.ZldzServerEngine;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.io.api.InvokeResult;
import com.ld.io.api.IoSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.CountDownLatch;
/**
 * æŠ¥æ–‡æŽ¥å—到后处理
 */
@Slf4j
public class ReceiverServer {
    private CountDownLatch latch;
    @Autowired
    public ReceiverServer(CountDownLatch latch) {
        this.latch = latch;
    }
    @Autowired
    private AnalysisService analysisService;
    public void onMessage(String message) {
        message = message.replaceAll("\"", "");
        log.info("-------获取队列信息---" + message);
        try {
            String[] attr = message.split("_");
            String sessionKey = attr[0];
            String msg = attr[1];
            analysisService.analysis2(sessionKey, msg);
        } catch (Exception e) {
            latch.countDown();
            log.error("[正来电子--消息队列数据失败,失败信息:{}]", e.getMessage(),e);
        }
        latch.countDown();
    }
    public void onLoginMessage(String sessionKey) {
        log.info("-------获取登录队列信息---{}", sessionKey);
        try {
            sessionKey = sessionKey.replaceAll("\"", "");
            String[] attr = sessionKey.split(":");
            IoSession session = ZldzServerEngine.getSession(attr[0],Integer.valueOf(attr[1]));
            if (null == session) {
                log.warn("---------------没有获取到会话信息-------------{}", sessionKey);
                latch.countDown();
                return;
            }
            long l = RandomUtils.nextInt(1000, 9999);
            Thread.sleep(l);
            BaseRequest request = new BaseRequest();
            request.setIp(session.getAddress());
            request.setPort(session.getPort());
            request.setCompanyId(ServerUtils.DEFAULT_COMPANY);
            // Step1 ç”Ÿæˆåœ¨çº¿æµ‹è¯•命令
            Message message = OnLineCommandBuilder.getInstance().buildMessage(request);
            // å‘送命令
            InvokeResult result = session.invoke(message.getByteMsg());
            //如果命令发送失败,直接踢掉连接
            if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) {
                session.destroy();
            }
        } catch (Exception e) {
            latch.countDown();
            log.error("[正来电子--登录消息队列数据失败,失败信息:{}]", e.getMessage());
        }
        latch.countDown();
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/mq/RedisSubConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,75 @@
package com.ld.igds.protocol.zldz.mq;
import com.ld.igds.io.constant.ProtocolEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import java.util.concurrent.CountDownLatch;
/**
 * æ¶ˆæ¯è®¢é˜…配置
 */
@Configuration
public class RedisSubConfig {
    /**
     * åˆ›å»ºè¿žæŽ¥å·¥åŽ‚
     *
     * @param connectionFactory
     * @return
     */
    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
                                                   MessageListenerAdapter adapter1,
                                                   MessageListenerAdapter adapter2) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        //监听对应的channel
        container.addMessageListener(adapter1, new PatternTopic(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode()));
        //监听对应的channel
        container.addMessageListener(adapter2, new PatternTopic(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode() + "_LOGIN"));
        return container;
    }
    /**
     * ç»‘定消息监听者和接收监听的方法
     *
     * @param receiver
     * @return
     */
    @Bean
    public MessageListenerAdapter adapter1(ReceiverServer receiver) {
        return new MessageListenerAdapter(receiver, "onMessage");
    }
    /**
     * ç»‘定消息监听者和接收监听的方法
     *
     * @param receiver
     * @return
     */
    @Bean
    public MessageListenerAdapter adapter2(ReceiverServer receiver) {
        return new MessageListenerAdapter(receiver, "onLoginMessage");
    }
    @Bean
    ReceiverServer receiver(CountDownLatch latch) {
        return new ReceiverServer(latch);
    }
    @Bean
    public CountDownLatch latch() {
        return new CountDownLatch(1);//指定了计数的次数 1
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/package-info.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,6 @@
/**
 * æ­£æ¥ç”µå­-粮情协议V1
 *
 */
package com.ld.igds.protocol.zldz;
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/HeartbeatProviderImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,45 @@
package com.ld.igds.protocol.zldz.server;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.util.SpringUtil;
import com.ld.io.api.HeartbeatProvider;
import com.ld.io.api.IoSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
 * å¿ƒè·³ç»´æŒï¼ŒéªŒè¯å½“前连接中的IP在服务器上配置的有没有,如果有则表示正常连接,如果没有则踢除连接。
 * <p>
 * å¦‚果有正常心跳,则发送正常心跳命令,如果没有则发送设备状态查询,
 */
@Slf4j
public class HeartbeatProviderImpl implements HeartbeatProvider {
    private CoreSerService serService;
    @Override
    public byte[] provide(IoSession session) {
        log.debug("========系统开始执行心跳=========={}---{}", session.getCompanyId(), session.getBusinessKey());
        if (null == serService) {
            serService = SpringUtil.getBean(CoreSerService.class);
        }
        DeviceSer ser = null;
        String companyId = session.getCompanyId();
        if (StringUtils.isNotEmpty(companyId)) {
            ser = serService.getCacheSerByIp(companyId, session.getAddress(), session.getPort());
        }
        if (null == ser) {
            log.error("========心跳执行没有获取到分机信息======IP={}-{},取消踢出,只做日志提醒。", session.getAddress(), session.getPort());
            session.destroy();
            return null;
        }
        return null;
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/MsgConsumer.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package com.ld.igds.protocol.zldz.server;
import com.ld.igds.protocol.zldz.mq.PublisherControl;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
import com.ld.igds.util.SpringUtil;
import com.ld.io.api.IoMsgConsumer;
import com.ld.io.api.IoSession;
/**
 * æŽ¥æ”¶ç»ˆç«¯è¿”回回来的信息。
 *
 * @author Andy
 */
public class MsgConsumer implements IoMsgConsumer {
    // private AnalysisService analysisService;
    private PublisherControl publisherControl;
    @Override
    public void consume(IoSession session, byte[] bytes) {
        // è°ƒç”¨è§£æžæŽ¥å£å¼€å§‹è§£æž
        // if(null == analysisService){
        // analysisService = (AnalysisService)
        // SpringUtil.getBean(AnalysisService.BEAN_ID);
        // }
        // analysisService.analysis(session.getAddress(),session.getPort(),bytes);
        // 2021å¹´6月9日 è°ƒæ•´ä¸ºæ¶ˆæ¯é˜Ÿåˆ—处理
        if (null == publisherControl) {
            publisherControl = SpringUtil.getBean(PublisherControl.class);
        }
        String strMsg = BytesUtil.bytesToString(bytes) + ServerUtils.MSG_END;
        // äºŒæ¬¡è°ƒæ•´æŠ¥æ–‡
        if (!strMsg.startsWith(ServerUtils.MSG_START)) {
            strMsg = strMsg.substring(strMsg.indexOf(ServerUtils.MSG_START));
        }
        publisherControl.publishMessage(session.getBusinessKey() + "_" + strMsg);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/SessionListener.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,40 @@
package com.ld.igds.protocol.zldz.server;
import com.ld.igds.io.notify.ServerNotifyInvoker;
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.protocol.zldz.mq.PublisherControl;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.SpringUtil;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
public class SessionListener extends BaseRemoteImpl implements IoSessionListener {
    public static final String BEAN_ID = "zldz.sessionListener";
    private ServerNotifyInvoker serverNotifyInvoker;
    private PublisherControl publisherControl;
    @Override
    public void onCreate(IoSession session) {
        // æ·»åŠ è‡ªå®šä¹‰ä¸šåŠ¡ID
        session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort()));
        //2021å¹´6月9日 è°ƒæ•´ä½¿ç”¨ä¸ºé˜Ÿåˆ—
        if (null == publisherControl) {
            publisherControl = SpringUtil.getBean(PublisherControl.class);
        }
        publisherControl.publishLoginMessage(session.getBusinessKey());
    }
    @Override
    public void onDestroy(IoSession session) {
        if (null == serverNotifyInvoker) {
            serverNotifyInvoker = SpringUtil.getBean(ServerNotifyInvoker.class);
        }
        serverNotifyInvoker.connectDestory(session.getBusinessKey(),
                session.getAddress(), session.getPort());
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/server/ZldzServerEngine.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,113 @@
package com.ld.igds.protocol.zldz.server;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.BytesUtil;
import com.ld.io.api.*;
import com.ld.io.netty.NettyServer;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
 * é…ç½®ä¸»æœåŠ¡ä¿¡æ¯
 *
 * @author Andy 2019å¹´10月4日 æ–°å¢ž
 */
@Slf4j
public class ZldzServerEngine {
    public static final int PORT = 8000;
    public static NettyServer ioServer = null;
    // é…ç½®æ¶ˆæ¯æŽ¥æ”¶ç±»
    private static MsgConsumer messageConsume = new MsgConsumer();
    // ç›‘听会话的创建与销毁
    private static SessionListener ioSessionListener = new SessionListener();
    // å¿ƒè·³æä¾› ï¼Œè¯¥æœåŠ¡ä¸éœ€è¦å¿ƒè·³ç»´æŒ
    private static HeartbeatProvider heartbeatProvider = new HeartbeatProviderImpl();
    public static void start() {
        start(PORT);
    }
    public static void start(int port) {
        // é…ç½®Server的配置
        IoServerOption ioServerOption = new IoServerOption(port);
        ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL);
        ioServerOption.setDelimiter(BytesUtil.hexStrToBytes(ServerUtils.MSG_END));
        // é…ç½®å¿ƒè·³æ‰§è¡Œæ—¶é—´
        ioServerOption.setReaderIdleTime(60 * 60);
        ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener, heartbeatProvider);
        ioServer.startup();
        log.info("* ========================");
        log.info("* ");
        log.info("* çº¯ç²®æƒ…协议,端口号={}", port);
        log.info("* ");
        log.info("* ========================");
        System.out.println("* ========================");
        System.out.println("* ");
        System.out.println("* çº¯ç²®æƒ…协议,端口号=" + port);
        System.out.println("* ");
        System.out.println("* ========================");
    }
    /**
     * å‘送信息
     *
     * @param ip
     * @param port
     * @param msg
     * @return
     */
    public static InvokeResult push(String ip, int port, byte[] msg) {
        IoSession session = getSession(ip, port);
        if (null == session) {
            return InvokeResult.CHANNEL_CLOSED;
        }
        return session.invoke(msg);
    }
    /**
     * ä¸»åŠ¨é”€æ¯å½“å‰è¿žæŽ¥
     *
     * @param ip
     * @param port
     * @return
     */
    public static InvokeResult destory(String ip, int port) {
        IoSession session = getSession(ip, port);
        if (null == session) {
            return InvokeResult.SUCCESS;
        }
        // æ‰§è¡Œè¿žæŽ¥é”€æ¯
        session.destroy();
        return InvokeResult.SUCCESS;
    }
    /**
     * æ ¹æ®SessionKey获取Session信息
     *
     * @param ip
     * @return
     */
    public static IoSession getSession(String ip, int port) {
        IoSessionQuery sessionFactory = ioServer.getSessionQuery();
        List<IoSession> sessions = sessionFactory.getAllSession();
        for (IoSession ioSession : sessions) {
            if (ip.equals(ioSession.getAddress()) && port == ioSession.getPort()) {
                return ioSession;
            }
        }
        return null;
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/CommandReSendService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,145 @@
package com.ld.igds.protocol.zldz.task;
import com.ld.igds.io.request.CheckGrainRequest;
import com.ld.igds.io.request.CheckThRequest;
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.protocol.zldz.util.ServerUtils;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
/**
 * å‘½ä»¤é‡å‘
 */
@Slf4j
@Component(CommandReSendService.BEAN_ID)
public class CommandReSendService extends BaseRemoteImpl {
    public static final String BEAN_ID = "zldz.commandReSendService";
    public static final String REDIS_KEY_RESEND_COMMAND = "REDIS_KEY_RESEND_COMMAND";
    public static final String REDIS_KEY_TH_QUEEN = "REDIS_KEY_TH_QUEEN";
    public static final int REDIS_KEY_TIME = 4 * 60;
    @Autowired
    private RedisUtil redisUtil;
    public String buildKey(CommandTask data) {
        return buildKey(data.getCompanyId(), data.getIp(), data.getPort(),
                data.getResultType());
    }
    public String buildKey(String companyId, String ip, int port,
            String resultType) {
        String key = ip + "." + port + ":" + resultType;
        return companyId + ":" + REDIS_KEY_RESEND_COMMAND + ":" + key;
    }
    public void reSendTask(CommandTask data) {
        // ç¼“å­˜
        redisUtil.set(buildKey(data), data, REDIS_KEY_TIME);
        // åˆ›å»ºå­ä»»åŠ¡
        FutureTask<String> futureTask = new FutureTask<>(new ReSendCommonTask(data, redisUtil, buildKey(data)));
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.submit(futureTask);
        executorService.shutdown();
    }
    // æ¸©æ¹¿åº¦å‘½ä»¤ä¸ä½¿ç”¨å­ä»»åŠ¡
    public void reSendThTask(CommandTask data) {
        // ç¼“å­˜
        redisUtil.set(buildKey(data), data, REDIS_KEY_TIME);
    }
    public void reSendGrainTask(CommandTask data) {
        // ç¼“å­˜
        redisUtil.set(buildKey(data), data, REDIS_KEY_TIME);
        // åˆ›å»ºå­ä»»åŠ¡
        FutureTask<String> futureTask = new FutureTask<>(new ReSendGrainTask(
                data, redisUtil, buildKey(data)));
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.submit(futureTask);
        executorService.shutdown();
    }
    public void cleanKey(String companyId, String ip, int port,
            String resultType) {
        String key = buildKey(companyId, ip, port, resultType);
        redisUtil.del(key);
    }
    public void destoryAndDelCache(String companyId, String ip, Integer port,
            String messageType) {
        try {
            // ç²®æƒ…直接使用最总的状态返回
            if (messageType.equals(ServerUtils.MSG_TYPE_1115)) {
                messageType = ServerUtils.MSG_TYPE_8817;
            }
            this.cleanKey(companyId, ip, port, messageType);
            //间隔5S踢出,避免快速直接连接
            Thread.sleep(5 * 1000);
            super.destory(ip, port);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public void reSend(String companyId, String ip, int port, String resultType) {
        String key = buildKey(companyId, ip, port, resultType);
        CommandTask commandData = (CommandTask) redisUtil.get(key);
        if (null != commandData) {
            super.send(ip, port, commandData.getByteCommand());
        } else {
            log.error("命令重发失败:{}-{}-{}没有获取到命令。", ip, port, resultType);
        }
    }
    public CommandTask getRedisCommand(String companyId, String ip,
            Integer port, String resultType) {
        String key = this.buildKey(companyId, ip, port, resultType);
        return (CommandTask) redisUtil.get(key);
    }
    /**
     * å½“前分机相同粮情分机的等待队列
     *
     * @param thRequest
     * @param request
     */
    public void addToThQueen(CheckThRequest thRequest, CheckGrainRequest request) {
        String key = thRequest.getCompanyId() + ":" + REDIS_KEY_TH_QUEEN + ":"
                + thRequest.getSerId();
        List<CheckGrainRequest> list = this.getThQueen(
                thRequest.getCompanyId(), thRequest.getSerId());
        if (null == list) {
            list = new ArrayList<>();
        }
        list.add(request);
        redisUtil.set(key, list, 60);
    }
    @SuppressWarnings("unchecked")
    public List<CheckGrainRequest> getThQueen(String companyId, String serId) {
        String key = companyId + ":" + REDIS_KEY_TH_QUEEN + ":" + serId;
        return (List<CheckGrainRequest>) redisUtil.get(key);
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/CommandTask.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package com.ld.igds.protocol.zldz.task;
import lombok.Data;
/**
 * ç”¨äºŽå­˜æ”¾å‘送的命令信息,存放到缓存中
 */
@Data
public class CommandTask {
    private String companyId;
    private String depotId;//执行仓库
    private String serName;
    private String ip = "";
    private int port = 0;
    private String command; //发送的命令
    private byte[] byteCommand; //发送的命令
    private String resultType;//等待返回的命令类型
    private int sendNum = 1;//发送次数
    private String cableRule;
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/ReSendCommonTask.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,95 @@
package com.ld.igds.protocol.zldz.task;
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Callable;
/**
 * å­ä»»åŠ¡ï¼Œç”¨äºŽåˆ¤æ–­é‡å‘å’Œå¼‚å¸¸å¤„ç†ï¼Œå‘½ä»¤å‘é€åŽå°†å‘½ä»¤ä¿¡æ¯å­˜æ”¾ç¼“å­˜ï¼Œå½“å‰
 *
 * @author andy.jia
 */
@Slf4j
public class ReSendCommonTask extends BaseRemoteImpl implements Callable<String> {
    private CommandTask commandData;
    private RedisUtil redisUtil;
    private String redisKey;
    public RedisUtil getRedisUtil() {
        return redisUtil;
    }
    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }
    public String getRedisKey() {
        return redisKey;
    }
    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }
    public void setCommandData(CommandTask commandData) {
        this.commandData = commandData;
    }
    public CommandTask getCommandData() {
        return commandData;
    }
    public ReSendCommonTask() {
        super();
    }
    public ReSendCommonTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) {
        super();
        this.commandData = commandData;
        this.redisUtil = redisUtil;
        this.redisKey = redisKey;
    }
    @Override
    public String call() throws Exception {
        //1,获取缓存中信息
        Thread.sleep(15 * 1000);
        CommandTask redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第1次等待,终端已经正常返回";
        } else {
            log.info("{}-第1次命令补发命令={}", commandData.getIp(), commandData.getCommand());
            super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
        }
        //2,等待20S
        Thread.sleep(15 * 1000);
        redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第2次等等,终端已经正常返回";
        } else {
            log.info("{}-第2次命令补命令={}", commandData.getIp(), commandData.getCommand());
            super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
        }
        //2,等待20S
        Thread.sleep(15 * 1000);
        redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第3次等等,终端已经正常返回";
        } else {
            log.info("{}-第3次命令补发后,仍然没有返回,取消等待。", commandData.getIp());
            //super.destory(commandData.getIp(), commandData.getPort());
        }
        return "子任务执行完成";
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/task/ReSendGrainTask.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,99 @@
package com.ld.igds.protocol.zldz.task;
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Callable;
/**
 * ç²®æƒ…子任务,粮情子任务,忽略8815的回复和8817的回复,直接等结果包的到达,如果结果包没有到达,就重复发送粮情请求
 *
 * @author andy.jia
 */
@Slf4j
public class ReSendGrainTask extends BaseRemoteImpl implements Callable<String> {
    private CommandTask commandData;
    private RedisUtil redisUtil;
    private String redisKey;
    public RedisUtil getRedisUtil() {
        return redisUtil;
    }
    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }
    public String getRedisKey() {
        return redisKey;
    }
    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }
    public void setCommandData(CommandTask commandData) {
        this.commandData = commandData;
    }
    public CommandTask getCommandData() {
        return commandData;
    }
    public ReSendGrainTask() {
        super();
    }
    public ReSendGrainTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) {
        super();
        this.commandData = commandData;
        this.redisUtil = redisUtil;
        this.redisKey = redisKey;
    }
    @Override
    public String call() throws Exception {
        String[] attCable = commandData.getCableRule().split("-");
        int cableZ = Integer.valueOf(attCable[0]);
        int cableY = Integer.valueOf(attCable[1]);
        int cableX = Integer.valueOf(attCable[2]);
        int point = cableX * cableY * cableZ;
        long time = point * 100 + (point / 100) * 500;
        //1,粮情第1次等待时间为采集点个数* 0.1 ç§’ + 20秒,如果没有正常返回则发送第二次命令。
        Thread.sleep(time);
        CommandTask redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第1次等待,终端已经正常返回";
        } else {
            String msg = commandData.getSerName() + " ç¬¬1次补发命令=" + commandData.getCommand();
            log.info(msg);
            super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
        }
        //2
        Thread.sleep(time);
        redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第2次等等,终端已经正常返回";
        } else {
            String msg = commandData.getSerName() + " ç¬¬2次补发粮情命令,没有返回,系统断开当前连接。";
            log.info(msg);
//            ExeOrderService orderService = SpringUtil.getBean(ExeOrderService.class);
//            orderService.progressError(commandData.getCompanyId(), BizType.GRAIN, commandData.getDepotId(), msg);
            //2021å¹´6月5日 07:30:22 å–消超时踢出连接
           // super.destory(commandData.getIp(), commandData.getPort());
        }
        return "子任务执行完成";
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/CRC16.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,135 @@
package com.ld.igds.protocol.zldz.util;
/***
 *
 * @author Andy
 *
 */
public class CRC16 {
    static byte[] crc16_tab_h = { (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0,
            (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1,
            (byte) 0x81, (byte) 0x40 };
    static byte[] crc16_tab_l = { (byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03,
            (byte) 0x02, (byte) 0xC2, (byte) 0xC6, (byte) 0x06, (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5,
            (byte) 0xC4, (byte) 0x04, (byte) 0xCC, (byte) 0x0C, (byte) 0x0D, (byte) 0xCD, (byte) 0x0F, (byte) 0xCF,
            (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, (byte) 0xC9, (byte) 0x09,
            (byte) 0x08, (byte) 0xC8, (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB,
            (byte) 0xDA, (byte) 0x1A, (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D,
            (byte) 0x1C, (byte) 0xDC, (byte) 0x14, (byte) 0xD4, (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17,
            (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, (byte) 0x13, (byte) 0xD3, (byte) 0x11, (byte) 0xD1,
            (byte) 0xD0, (byte) 0x10, (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, (byte) 0x33, (byte) 0xF3,
            (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35,
            (byte) 0x34, (byte) 0xF4, (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F,
            (byte) 0x3E, (byte) 0xFE, (byte) 0xFA, (byte) 0x3A, (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9,
            (byte) 0xF8, (byte) 0x38, (byte) 0x28, (byte) 0xE8, (byte) 0xE9, (byte) 0x29, (byte) 0xEB, (byte) 0x2B,
            (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, (byte) 0x2D, (byte) 0xED,
            (byte) 0xEC, (byte) 0x2C, (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7,
            (byte) 0xE6, (byte) 0x26, (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21,
            (byte) 0x20, (byte) 0xE0, (byte) 0xA0, (byte) 0x60, (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3,
            (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, (byte) 0xA7, (byte) 0x67, (byte) 0xA5, (byte) 0x65,
            (byte) 0x64, (byte) 0xA4, (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, (byte) 0xAF, (byte) 0x6F,
            (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9,
            (byte) 0xA8, (byte) 0x68, (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B,
            (byte) 0x7A, (byte) 0xBA, (byte) 0xBE, (byte) 0x7E, (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD,
            (byte) 0xBC, (byte) 0x7C, (byte) 0xB4, (byte) 0x74, (byte) 0x75, (byte) 0xB5, (byte) 0x77, (byte) 0xB7,
            (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, (byte) 0xB1, (byte) 0x71,
            (byte) 0x70, (byte) 0xB0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53,
            (byte) 0x52, (byte) 0x92, (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95,
            (byte) 0x94, (byte) 0x54, (byte) 0x9C, (byte) 0x5C, (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F,
            (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, (byte) 0x9B, (byte) 0x5B, (byte) 0x99, (byte) 0x59,
            (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4B, (byte) 0x8B,
            (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D,
            (byte) 0x4C, (byte) 0x8C, (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47,
            (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81,
            (byte) 0x80, (byte) 0x40 };
    /**
     * è®¡ç®—CRC16校验
     *
     * @param data
     *            éœ€è¦è®¡ç®—的数组
     * @return CRC16校验值
     */
    public static int calcCrc16(byte[] data) {
        return calcCrc16(data, 0, data.length);
    }
    /**
     * è®¡ç®—CRC16校验
     *
     * @param data
     *            éœ€è¦è®¡ç®—的数组
     * @param offset
     *            èµ·å§‹ä½ç½®
     * @param len
     *            é•¿åº¦
     * @return CRC16校验值
     */
    public static int calcCrc16(byte[] data, int offset, int len) {
        return calcCrc16(data, offset, len, 0xffff);
    }
    /**
     * è®¡ç®—CRC16校验
     *
     * @param data
     *            éœ€è¦è®¡ç®—的数组
     * @param offset
     *            èµ·å§‹ä½ç½®
     * @param len
     *            é•¿åº¦
     * @param preval
     *            ä¹‹å‰çš„æ ¡éªŒå€¼
     * @return CRC16校验值
     */
    public static int calcCrc16(byte[] data, int offset, int len, int preval) {
        int ucCRCHi = (preval & 0xff00) >> 8;
        int ucCRCLo = preval & 0x00ff;
        int iIndex;
        for (int i = 0; i < len; ++i) {
            iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff;
            ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex];
            ucCRCHi = crc16_tab_l[iIndex];
        }
        return ((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff;
    }
    // æµ‹è¯•
    public static void main(String[] args) {
        // 0x02 05 00 03 FF 00 , crc16=7C 09
        int crc = CRC16.calcCrc16(new byte[] { 0x02, 0x05, 0x00, 0x03, (byte) 0xff, 0x00 });
        System.out.println(String.format("0x%04x", crc));
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/CRC8.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,186 @@
package com.ld.igds.protocol.zldz.util;
/**
 *计算CRC8校验值
 */
public class CRC8 {
    public static void main(String[] args) {
    }
    static short[] gCrc16Table = { (short) 0x0000, (short) 0x1021, (short) 0x2042, (short) 0x3063, (short) 0x4084,
            (short) 0x50a5, (short) 0x60c6, (short) 0x70e7, (short) 0xd94c, (short) 0xc96d, (short) 0xf90e,
            (short) 0xe92f, (short) 0x99c8, (short) 0x89e9, (short) 0xb98a, (short) 0xa9ab, (short) 0x5844,
            (short) 0x4865, (short) 0x7806, (short) 0x6827, (short) 0x18c0, (short) 0x08e1, (short) 0x3882,
            (short) 0x28a3, (short) 0xcb7d, (short) 0xdb5c, (short) 0xeb3f, (short) 0xfb1e, (short) 0x8bf9,
            (short) 0x9bd8, (short) 0xabbb, (short) 0xbb9a, (short) 0x4a75, (short) 0x5a54, (short) 0x6a37,
            (short) 0x7a16, (short) 0x0af1, (short) 0x1ad0, (short) 0x2ab3, (short) 0x3a92, (short) 0xfd2e,
            (short) 0xed0f, (short) 0xdd6c, (short) 0xcd4d, (short) 0xbdaa, (short) 0xad8b, (short) 0x9de8,
            (short) 0x8dc9, (short) 0xc9cc, (short) 0xd9ed, (short) 0xe98e, (short) 0xf9af, (short) 0x8948,
            (short) 0x9969, (short) 0xa90a, (short) 0xb92b, (short) 0x5af5, (short) 0x4ad4, (short) 0x7ab7,
            (short) 0x6a96, (short) 0x1a71, (short) 0x0a50, (short) 0x3a33, (short) 0x2a12, (short) 0xdbfd,
            (short) 0xcbdc, (short) 0xfbbf, (short) 0xeb9e, (short) 0x9b79, (short) 0x8b58, (short) 0xbb3b,
            (short) 0xab1a, (short) 0x6ca6, (short) 0x7c87, (short) 0x4ce4, (short) 0x5cc5, (short) 0x2c22,
            (short) 0x3c03, (short) 0x0c60, (short) 0x1c41, (short) 0x8108, (short) 0x9129, (short) 0xa14a,
            (short) 0xb16b, (short) 0xc18c, (short) 0xd1ad, (short) 0xe1ce, (short) 0xf1ef, (short) 0x1231,
            (short) 0x0210, (short) 0x3273, (short) 0x2252, (short) 0x52b5, (short) 0x4294, (short) 0x72f7,
            (short) 0x62d6, (short) 0x9339, (short) 0x8318, (short) 0xb37b, (short) 0xa35a, (short) 0xd3bd,
            (short) 0xc39c, (short) 0xf3ff, (short) 0xe3de, (short) 0x2462, (short) 0x3443, (short) 0x0420,
            (short) 0x1401, (short) 0x64e6, (short) 0x74c7, (short) 0x44a4, (short) 0x5485, (short) 0xa56a,
            (short) 0xb54b, (short) 0x8528, (short) 0x9509, (short) 0xe5ee, (short) 0xf5cf, (short) 0xc5ac,
            (short) 0xd58d, (short) 0x3653, (short) 0x2672, (short) 0x1611, (short) 0x0630, (short) 0x76d7,
            (short) 0x66f6, (short) 0x5695, (short) 0x46b4, (short) 0xb75b, (short) 0xa77a, (short) 0x9719,
            (short) 0x8738, (short) 0xf7df, (short) 0xe7fe, (short) 0xd79d, (short) 0xc7bc, (short) 0x48c4,
            (short) 0x58e5, (short) 0x6886, (short) 0x78a7, (short) 0x0840, (short) 0x1861, (short) 0x2802,
            (short) 0x3823, (short) 0x83b9, (short) 0x9398, (short) 0xa3fb, (short) 0xb3da, (short) 0xc33d,
            (short) 0xd31c, (short) 0xe37f, (short) 0xf35e, (short) 0x02b1, (short) 0x1290, (short) 0x22f3,
            (short) 0x32d2, (short) 0x4235, (short) 0x5214, (short) 0x6277, (short) 0x7256, (short) 0xb5ea,
            (short) 0xa5cb, (short) 0x95a8, (short) 0x8589, (short) 0xf56e, (short) 0xe54f, (short) 0xd52c,
            (short) 0xc50d, (short) 0x34e2, (short) 0x24c3, (short) 0x14a0, (short) 0x0481, (short) 0x7466,
            (short) 0x6447, (short) 0x5424, (short) 0x4405, (short) 0xa7db, (short) 0xb7fa, (short) 0x8799,
            (short) 0x97b8, (short) 0xe75f, (short) 0xf77e, (short) 0xc71d, (short) 0xd73c, (short) 0x26d3,
            (short) 0x36f2, (short) 0x0691, (short) 0x16b0, (short) 0x6657, (short) 0x7676, (short) 0x4615,
            (short) 0x5634, (short) 0xedae, (short) 0xfd8f, (short) 0xcdec, (short) 0xddcd, (short) 0xad2a,
            (short) 0xbd0b, (short) 0x8d68, (short) 0x9d49, (short) 0x7e97, (short) 0x6eb6, (short) 0x5ed5,
            (short) 0x4ef4, (short) 0x3e13, (short) 0x2e32, (short) 0x1e51, (short) 0x0e70, (short) 0xff9f,
            (short) 0xefbe, (short) 0xdfdd, (short) 0xcffc, (short) 0xbf1b, (short) 0xaf3a, (short) 0x9f59,
            (short) 0x8f78, (short) 0x9188, (short) 0x81a9, (short) 0xb1ca, (short) 0xa1eb, (short) 0xd10c,
            (short) 0xc12d, (short) 0xf14e, (short) 0xe16f, (short) 0x1080, (short) 0x00a1, (short) 0x30c2,
            (short) 0x20e3, (short) 0x5004, (short) 0x4025, (short) 0x7046, (short) 0x6067, (short) 0x7c26,
            (short) 0x6c07, (short) 0x5c64, (short) 0x4c45, (short) 0x3ca2, (short) 0x2c83, (short) 0x1ce0,
            (short) 0x0cc1, (short) 0xef1f, (short) 0xff3e, (short) 0xcf5d, (short) 0xdf7c, (short) 0xaf9b,
            (short) 0xbfba, (short) 0x8fd9, (short) 0x9ff8, (short) 0x6e17, (short) 0x7e36, (short) 0x4e55,
            (short) 0x5e74, (short) 0x2e93, (short) 0x3eb2, (short) 0x0ed1, (short) 0x1ef0 };
    static short[] crc8_tab = { (short) 0x00, (short) 0x07, (short) 0x0E, (short) 0x09, (short) 0x1C, (short) 0x1B,
            (short) 0x12, (short) 0x15, (short) 0x38, (short) 0x3F, (short) 0x36, (short) 0x31, (short) 0x24,
            (short) 0x23, (short) 0x2A, (short) 0x2D, (short) 0x70, (short) 0x77, (short) 0x7E, (short) 0x79,
            (short) 0x6C, (short) 0x6B, (short) 0x62, (short) 0x65, (short) 0x48, (short) 0x4F, (short) 0x46,
            (short) 0x41, (short) 0x54, (short) 0x53, (short) 0x5A, (short) 0x5D, (short) 0xE0, (short) 0xE7,
            (short) 0xEE, (short) 0xE9, (short) 0xFC, (short) 0xFB, (short) 0xF2, (short) 0xF5, (short) 0xD8,
            (short) 0xDF, (short) 0xD6, (short) 0xD1, (short) 0xC4, (short) 0xC3, (short) 0xCA, (short) 0xCD,
            (short) 0x90, (short) 0x97, (short) 0x9E, (short) 0x99, (short) 0x8C, (short) 0x8B, (short) 0x82,
            (short) 0x85, (short) 0xA8, (short) 0xAF, (short) 0xA6, (short) 0xA1, (short) 0xB4, (short) 0xB3,
            (short) 0xBA, (short) 0xBD, (short) 0xC7, (short) 0xC0, (short) 0xC9, (short) 0xCE, (short) 0xDB,
            (short) 0xDC, (short) 0xD5, (short) 0xD2, (short) 0xFF, (short) 0xF8, (short) 0xF1, (short) 0xF6,
            (short) 0xE3, (short) 0xE4, (short) 0xED, (short) 0xEA, (short) 0xB7, (short) 0xB0, (short) 0xB9,
            (short) 0xBE, (short) 0xAB, (short) 0xAC, (short) 0xA5, (short) 0xA2, (short) 0x8F, (short) 0x88,
            (short) 0x81, (short) 0x86, (short) 0x93, (short) 0x94, (short) 0x9D, (short) 0x9A, (short) 0x27,
            (short) 0x20, (short) 0x29, (short) 0x2E, (short) 0x3B, (short) 0x3C, (short) 0x35, (short) 0x32,
            (short) 0x1F, (short) 0x18, (short) 0x11, (short) 0x16, (short) 0x03, (short) 0x04, (short) 0x0D,
            (short) 0x0A, (short) 0x57, (short) 0x50, (short) 0x59, (short) 0x5E, (short) 0x4B, (short) 0x4C,
            (short) 0x45, (short) 0x42, (short) 0x6F, (short) 0x68, (short) 0x61, (short) 0x66, (short) 0x73,
            (short) 0x74, (short) 0x7D, (short) 0x7A, (short) 0x89, (short) 0x8E, (short) 0x87, (short) 0x80,
            (short) 0x95, (short) 0x92, (short) 0x9B, (short) 0x9C, (short) 0xB1, (short) 0xB6, (short) 0xBF,
            (short) 0xB8, (short) 0xAD, (short) 0xAA, (short) 0xA3, (short) 0xA4, (short) 0xF9, (short) 0xFE,
            (short) 0xF7, (short) 0xF0, (short) 0xE5, (short) 0xE2, (short) 0xEB, (short) 0xEC, (short) 0xC1,
            (short) 0xC6, (short) 0xCF, (short) 0xC8, (short) 0xDD, (short) 0xDA, (short) 0xD3, (short) 0xD4,
            (short) 0x69, (short) 0x6E, (short) 0x67, (short) 0x60, (short) 0x75, (short) 0x72, (short) 0x7B,
            (short) 0x7C, (short) 0x51, (short) 0x56, (short) 0x5F, (short) 0x58, (short) 0x4D, (short) 0x4A,
            (short) 0x43, (short) 0x44, (short) 0x19, (short) 0x1E, (short) 0x17, (short) 0x10, (short) 0x05,
            (short) 0x02, (short) 0x0B, (short) 0x0C, (short) 0x21, (short) 0x26, (short) 0x2F, (short) 0x28,
            (short) 0x3D, (short) 0x3A, (short) 0x33, (short) 0x34, (short) 0x4E, (short) 0x49, (short) 0x40,
            (short) 0x47, (short) 0x52, (short) 0x55, (short) 0x5C, (short) 0x5B, (short) 0x76, (short) 0x71,
            (short) 0x78, (short) 0x7F, (short) 0x6A, (short) 0x6D, (short) 0x64, (short) 0x63, (short) 0x3E,
            (short) 0x39, (short) 0x30, (short) 0x37, (short) 0x22, (short) 0x25, (short) 0x2C, (short) 0x2B,
            (short) 0x06, (short) 0x01, (short) 0x08, (short) 0x0F, (short) 0x1A, (short) 0x1D, (short) 0x14,
            (short) 0x13, (short) 0xAE, (short) 0xA9, (short) 0xA0, (short) 0xA7, (short) 0xB2, (short) 0xB5,
            (short) 0xBC, (short) 0xBB, (short) 0x96, (short) 0x91, (short) 0x98, (short) 0x9F, (short) 0x8A,
            (short) 0x8D, (short) 0x84, (short) 0x83, (short) 0xDE, (short) 0xD9, (short) 0xD0, (short) 0xD7,
            (short) 0xC2, (short) 0xC5, (short) 0xCC, (short) 0xCB, (short) 0xE6, (short) 0xE1, (short) 0xE8,
            (short) 0xEF, (short) 0xFA, (short) 0xFD, (short) 0xF4, (short) 0xF3 };
    static byte[] crc8_tab2 = { (byte) 0x00, (byte) 0x07, (byte) 0x0E, (byte) 0x09, (byte) 0x1C, (byte) 0x1B,
            (byte) 0x12, (byte) 0x15, (byte) 0x38, (byte) 0x3F, (byte) 0x36, (byte) 0x31, (byte) 0x24, (byte) 0x23,
            (byte) 0x2A, (byte) 0x2D, (byte) 0x70, (byte) 0x77, (byte) 0x7E, (byte) 0x79, (byte) 0x6C, (byte) 0x6B,
            (byte) 0x62, (byte) 0x65, (byte) 0x48, (byte) 0x4F, (byte) 0x46, (byte) 0x41, (byte) 0x54, (byte) 0x53,
            (byte) 0x5A, (byte) 0x5D, (byte) 0xE0, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xFC, (byte) 0xFB,
            (byte) 0xF2, (byte) 0xF5, (byte) 0xD8, (byte) 0xDF, (byte) 0xD6, (byte) 0xD1, (byte) 0xC4, (byte) 0xC3,
            (byte) 0xCA, (byte) 0xCD, (byte) 0x90, (byte) 0x97, (byte) 0x9E, (byte) 0x99, (byte) 0x8C, (byte) 0x8B,
            (byte) 0x82, (byte) 0x85, (byte) 0xA8, (byte) 0xAF, (byte) 0xA6, (byte) 0xA1, (byte) 0xB4, (byte) 0xB3,
            (byte) 0xBA, (byte) 0xBD, (byte) 0xC7, (byte) 0xC0, (byte) 0xC9, (byte) 0xCE, (byte) 0xDB, (byte) 0xDC,
            (byte) 0xD5, (byte) 0xD2, (byte) 0xFF, (byte) 0xF8, (byte) 0xF1, (byte) 0xF6, (byte) 0xE3, (byte) 0xE4,
            (byte) 0xED, (byte) 0xEA, (byte) 0xB7, (byte) 0xB0, (byte) 0xB9, (byte) 0xBE, (byte) 0xAB, (byte) 0xAC,
            (byte) 0xA5, (byte) 0xA2, (byte) 0x8F, (byte) 0x88, (byte) 0x81, (byte) 0x86, (byte) 0x93, (byte) 0x94,
            (byte) 0x9D, (byte) 0x9A, (byte) 0x27, (byte) 0x20, (byte) 0x29, (byte) 0x2E, (byte) 0x3B, (byte) 0x3C,
            (byte) 0x35, (byte) 0x32, (byte) 0x1F, (byte) 0x18, (byte) 0x11, (byte) 0x16, (byte) 0x03, (byte) 0x04,
            (byte) 0x0D, (byte) 0x0A, (byte) 0x57, (byte) 0x50, (byte) 0x59, (byte) 0x5E, (byte) 0x4B, (byte) 0x4C,
            (byte) 0x45, (byte) 0x42, (byte) 0x6F, (byte) 0x68, (byte) 0x61, (byte) 0x66, (byte) 0x73, (byte) 0x74,
            (byte) 0x7D, (byte) 0x7A, (byte) 0x89, (byte) 0x8E, (byte) 0x87, (byte) 0x80, (byte) 0x95, (byte) 0x92,
            (byte) 0x9B, (byte) 0x9C, (byte) 0xB1, (byte) 0xB6, (byte) 0xBF, (byte) 0xB8, (byte) 0xAD, (byte) 0xAA,
            (byte) 0xA3, (byte) 0xA4, (byte) 0xF9, (byte) 0xFE, (byte) 0xF7, (byte) 0xF0, (byte) 0xE5, (byte) 0xE2,
            (byte) 0xEB, (byte) 0xEC, (byte) 0xC1, (byte) 0xC6, (byte) 0xCF, (byte) 0xC8, (byte) 0xDD, (byte) 0xDA,
            (byte) 0xD3, (byte) 0xD4, (byte) 0x69, (byte) 0x6E, (byte) 0x67, (byte) 0x60, (byte) 0x75, (byte) 0x72,
            (byte) 0x7B, (byte) 0x7C, (byte) 0x51, (byte) 0x56, (byte) 0x5F, (byte) 0x58, (byte) 0x4D, (byte) 0x4A,
            (byte) 0x43, (byte) 0x44, (byte) 0x19, (byte) 0x1E, (byte) 0x17, (byte) 0x10, (byte) 0x05, (byte) 0x02,
            (byte) 0x0B, (byte) 0x0C, (byte) 0x21, (byte) 0x26, (byte) 0x2F, (byte) 0x28, (byte) 0x3D, (byte) 0x3A,
            (byte) 0x33, (byte) 0x34, (byte) 0x4E, (byte) 0x49, (byte) 0x40, (byte) 0x47, (byte) 0x52, (byte) 0x55,
            (byte) 0x5C, (byte) 0x5B, (byte) 0x76, (byte) 0x71, (byte) 0x78, (byte) 0x7F, (byte) 0x6A, (byte) 0x6D,
            (byte) 0x64, (byte) 0x63, (byte) 0x3E, (byte) 0x39, (byte) 0x30, (byte) 0x37, (byte) 0x22, (byte) 0x25,
            (byte) 0x2C, (byte) 0x2B, (byte) 0x06, (byte) 0x01, (byte) 0x08, (byte) 0x0F, (byte) 0x1A, (byte) 0x1D,
            (byte) 0x14, (byte) 0x13, (byte) 0xAE, (byte) 0xA9, (byte) 0xA0, (byte) 0xA7, (byte) 0xB2, (byte) 0xB5,
            (byte) 0xBC, (byte) 0xBB, (byte) 0x96, (byte) 0x91, (byte) 0x98, (byte) 0x9F, (byte) 0x8A, (byte) 0x8D,
            (byte) 0x84, (byte) 0x83, (byte) 0xDE, (byte) 0xD9, (byte) 0xD0, (byte) 0xD7, (byte) 0xC2, (byte) 0xC5,
            (byte) 0xCC, (byte) 0xCB, (byte) 0xE6, (byte) 0xE1, (byte) 0xE8, (byte) 0xEF, (byte) 0xFA, (byte) 0xFD,
            (byte) 0xF4, (byte) 0xF3 };
    /**
     * è®¡ç®—数组的CRC8校验值
     *
     * @param data
     *            éœ€è¦è®¡ç®—的数组
     * @return CRC8校验值
     */
    public static byte calcCrc8(byte[] data) {
        return calcCrc8(data, (short) 2, (short) (data.length - 2), (byte) 0);
    }
    /**
     * è®¡ç®—CRC8校验值
     *
     * @param data
     *            æ•°æ®
     * @param offset
     *            èµ·å§‹ä½ç½®
     * @param len
     *            é•¿åº¦
     * @return æ ¡éªŒå€¼
     */
    public static byte calcCrc8(byte[] data, short offset, short len) {
        return calcCrc8(data, offset, len, (byte) 0);
    }
    public static byte calcCrc8(byte[] ucPtr, short offset, short ucLen, byte preval) {
        short ucIndex; // CRC8校验表格索引
        short ucCRC8 = 0; // CRC8字节初始化
        short i = 0;
        // è¿›è¡ŒCRC8位校验
        while ((ucLen--) > 0) {
            short indexI = (short) (i + offset);
            short data = ucPtr[indexI];
            if (data < 0) {
                int sd = Byte.toUnsignedInt(ucPtr[indexI]);
                data = (short) sd;
            }
            ucIndex = (short) (ucCRC8 ^ data);
            ucCRC8 = crc8_tab[(short) ucIndex];
            i++;
        }
        // è¿”回CRC8校验数据
        return (byte) (~ucCRC8);
    }
    public static short crc16Byte(short crc, byte data) {
        return (short) ((crc << 8) ^ gCrc16Table[((crc >> 8) ^ data) & 0xff]);
    }
    public static short calculateCrc16(byte[] buf, short offset, short length) {
        short crc = 0;
        short i = 0;
        while ((length--) > 0) {
            crc = crc16Byte(crc, buf[offset + (i++)]);
        }
        return crc;
    }
}
igds-protocol-zldz/src/main/java/com/ld/igds/protocol/zldz/util/ServerUtils.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,68 @@
package com.ld.igds.protocol.zldz.util;
import java.util.HashMap;
import java.util.Map;
/**
 * å·¥å…·ç±»
 *
 * @author Andy
 */
public class ServerUtils {
    public static final Map<String, String> contextMap = new HashMap<>();
    public static final String MSG_START = "AAAA";
    public static final String MSG_END = "EEEE";
    //默认组织编号
    public static final String DEFAULT_COMPANY = "0000";
    public static final String MSG_TYPE_1115 = "1115";// åŽå°èŽ·å–ç²®æƒ…æ•°æ®è¯·æ±‚
    public static final String MSG_TYPE_8815 = "8815";// ç»ˆç«¯åº”答粮情数据请求
    public static final String MSG_TYPE_1116 = "1116";// é…ç½®è¯»å–分机参数
    public static final String MSG_TYPE_8816 = "8816";// é…ç½®è¯»å–分机参数应答
    public static final String MSG_TYPE_1117 = "1117";// ç»ˆç«¯å‘送粮情数据给后台
    public static final String MSG_TYPE_8817 = "8817";// åŽå°æ”¶åˆ°ç²®æƒ…数据应答
    public static final String MSG_TYPE_1122 = "1122";// åˆå§‹åŒ–电缆电缆
    public static final String MSG_TYPE_1123 = "1123";// ç”µç¼†æ±‡æ€»
    public static final String MSG_TYPE_1125 = "1125";// è¯»å–通道电缆
    public static final String MSG_TYPE_8825 = "8825";//读取通道电缆应答
    public static final String MSG_TYPE_1126 = "1126";// ä¿®æ”¹é€šé“电缆
    public static final String MSG_TYPE_8826 = "8826";// ä¿®æ”¹é€šé“电缆应答
    public static final String MSG_TYPE_1128 = "1128";// è¯»å–有线温湿度
    public static final String MSG_TYPE_8822 = "8822";// åº”答初始化电缆电缆
    public static final String MSG_TYPE_8823 = "8823";// åº”答电缆汇总结果
    public static final String MSG_TYPE_8828 = "8828";// è¯»å–有线温湿度应答
    public static final String MSG_TYPE_1129 = "1129";// ç»ˆç«¯å‘送通道电缆数据给后台
    public static final String MSG_TYPE_8829 = "8829";// åŽå°æ”¶åˆ°ç”µç¼†æ•°æ®åº”ç­”
    public static final String MSG_TYPE_112B = "112B";// é‡å¯åˆ†æœº
    public static final String MSG_TYPE_882B = "882B";// é‡å¯åˆ†æœºåº”ç­”
    public static String getServerKey(String ip, int port) {
        return ip + ":" + port;
    }
}
igds-web/pom.xml
@@ -170,21 +170,21 @@
        </dependency>
        
        <!-- MODBUS-TCP -->
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-protocol-modbus</artifactId>
            <version>${igds.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>com.ld.igds</groupId>-->
<!--            <artifactId>igds-protocol-modbus</artifactId>-->
<!--            <version>${igds.version}</version>-->
<!--            <exclusions>-->
<!--                <exclusion>-->
<!--                    <artifactId>slf4j-log4j12</artifactId>-->
<!--                    <groupId>org.slf4j</groupId>-->
<!--                </exclusion>-->
<!--                <exclusion>-->
<!--                    <artifactId>log4j</artifactId>-->
<!--                    <groupId>log4j</groupId>-->
<!--                </exclusion>-->
<!--            </exclusions>-->
<!--        </dependency>-->
        <!-- ç§æœ‰åè®®-风正致远IOT、制氮机-->
@@ -204,7 +204,7 @@
            </exclusions>
        </dependency>
        <!--  ç§æœ‰åè®®-贝博粮情
        <!--  ç§æœ‰åè®®-贝博粮情-->
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-protocol-beibo</artifactId>
@@ -219,9 +219,9 @@
                    <groupId>log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>-->
        </dependency>
        <!--  ç§æœ‰åè®®-邦海智能
        <!--  ç§æœ‰åè®®-邦海智能-->
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-protocol-bhzn</artifactId>
@@ -236,9 +236,23 @@
                    <groupId>log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>-->
        <!--  æµ·åº·è½¦ç‰Œè¯†åˆ«-SDK
        </dependency>
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-protocol-zldz</artifactId>
            <version>${igds.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--  æµ·åº·è½¦ç‰Œè¯†åˆ«-SDK -->
        <dependency>
            <groupId>com.ld.igds</groupId>
            <artifactId>igds-protocol-sdk</artifactId>
@@ -254,10 +268,7 @@
                </exclusion>
            </exclusions>
        </dependency>
        -->
    </dependencies>
    <dependencyManagement>
        <dependencies>
igds-web/src/main/resources/application-pro1000.yml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,80 @@
##########################  é£Žæ­£è‡´è¿œ-粮情服务器   ##########################
server:
  port: 8201
  context-path: /
  connection-timeout: 5000
  tomcat:
    uri-encoding: UTF-8
##########################  datasourcec   ##########################
spring:
  datasource:
    db-base:
      name: db-base
      type: com.alibaba.druid.pool.DruidDataSource
      url: jdbc:mysql://127.0.0.1:3306/igds_master_v35?useUnicode=true&characterEncoding=utf-8
      driver-class-name: com.mysql.jdbc.Driver
      username: root
      password: ukJp12Qf+elyBvGHkJ5MQMa95pfVm0oFBHefdEgDFKoFSjbgYa9PYfv5vlem5nvoXjQsP9tIIo53DvSbsl160Q==
      public-key:
      config-decrypt: true
      initial-size:  5
      min-idle:  5
      max-active:  50
      max-wait: 60000
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 1 from dual
      test-whileIdle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      filters: stat
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
      use-global-data-source-stat: true
      remove-abandoned: true
      remove-abandoned-timeout: 1800
      log-abandoned: true
    db-sqlite:
      name: db-sqlite
      url: jdbc:sqlite:D:/app/igds/db/iot_cfg.db
      driver-class-name: org.sqlite.JDBC
      type: com.alibaba.druid.pool.DruidDataSource
      username:
      password:
  # Redis相关配置
  redis:
    database: 0
    host: 127.0.0.1
    port: 6379
    password: Abc123..
    # è¿žæŽ¥æ± æœ€å¤§è¿žæŽ¥æ•°ï¼ˆä½¿ç”¨è´Ÿå€¼è¡¨ç¤ºæ²¡æœ‰é™åˆ¶ï¼‰
    pool:
      max-active: 200
      max-wait: -1
      max-idle: 10
      min-idle: 0
      timeout: 6000
license:
  subject: ld_license
  publicAlias: publicCert
  storePass: PUBLICFZZYXXJSGFYXGS888888
  licensePath: C:/license/license.lic
  publicKeysStorePath: C:/license/publicCerts.keystore
##########################  IGDS   ##########################
## ç³»ç»ŸæŽ¥å£è·¯ç”±é…ç½® æ³¨æ„æ•°å­—如果以0开头的话,后台会出现转义,请添加""
igds:
  default:
    companyId: 1000
    sys-name: æ™ºæ…§ç²®åº“管理系统
    logo: logo-default.png
    logo-title: logo-title-default.png
    support: æ™ºæ…§ç²®æƒ…粮情云管理平台
    grian-add-point: N
  media-ip: 124.71.162.207
  media-port: 18000
  file-path: C:/IGDS-PLATFORM/
igds-web/src/main/resources/application-pro5322.yml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,80 @@
##########################   å¹¿ä¸œå¾é—»é¡¹ç›®   ##########################
server:
  port: 8888
  context-path: /
  connection-timeout: 5000
  tomcat:
    uri-encoding: UTF-8
##########################  datasourcec   ##########################
spring:
  datasource:
    db-base:
      name: db-base
      type: com.alibaba.druid.pool.DruidDataSource
      url: jdbc:mysql://127.0.0.1:3306/igds_master?useUnicode=true&characterEncoding=utf-8
      driver-class-name: com.mysql.jdbc.Driver
      username: root
      password: ukJp12Qf+elyBvGHkJ5MQMa95pfVm0oFBHefdEgDFKoFSjbgYa9PYfv5vlem5nvoXjQsP9tIIo53DvSbsl160Q==
      public-key:
      config-decrypt: true
      initial-size:  5
      min-idle:  5
      max-active:  50
      max-wait: 60000
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 1 from dual
      test-whileIdle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      filters: stat
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
      use-global-data-source-stat: true
      removeAbandoned: true
      removeAbandonedTimeout: 90
      logAbandoned: true
      poolPreparedStatements: true
      maxPoolPreparedStatementPerConnectionSize: 20
    db-sqlite:
      name: db-sqlite
      url: jdbc:sqlite:D:/app/igds/db/iot_cfg.db
      driver-class-name: org.sqlite.JDBC
      type: com.alibaba.druid.pool.DruidDataSource
      username:
      password:
  # Redis相关配置
  redis:
    database: 0
    host: 127.0.0.1
    port: 6379
    password: Abc123..
    # è¿žæŽ¥æ± æœ€å¤§è¿žæŽ¥æ•°ï¼ˆä½¿ç”¨è´Ÿå€¼è¡¨ç¤ºæ²¡æœ‰é™åˆ¶ï¼‰
    pool:
      max-active: 200
      max-wait: -1
      max-idle: 10
      min-idle: 0
      timeout: 6000
license:
  subject: ld_license
  publicAlias: publicCert
  storePass: PUBLICFZZYXXJSGFYXGS888888
  licensePath: D:/IGDS/license/license.lic
  publicKeysStorePath: D:/IGDS/license/publicCerts.keystore
##########################  IGDS   ##########################
## ç³»ç»ŸæŽ¥å£è·¯ç”±é…ç½® æ³¨æ„æ•°å­—如果以0开头的话,后台会出现转义,请添加""
igds:
  default:
    companyId: 5322
    sys-name: æ™ºæ…§ç²®åº“管理系统
    logo: logo-default.png
    logo-title: logo-title-default.png
    support: æ™ºæ…§ç²®åº“综合管理平台
    grian-add-point: N
  file-path: D:/IGDS/FILE/
pom.xml
@@ -39,6 +39,8 @@
        <module>igds-protocol-fzzy3</module>
        <!--邦海智能-->
        <module>igds-protocol-bhzn</module>
        <!--邦海智能-->
        <module>igds-protocol-zldz</module>
        <!--贝博粮情协议-->
        <module>igds-protocol-beibo</module>
        <!--物联网拓展设备包-->
@@ -54,7 +56,7 @@
        <module>igds-api-phone</module>
        <!--    æŽ¥å£åŒ…,包括三维接口    -->
        <module>igds-api-inte</module>
<!--        <module>igds-api-three</module>-->
        <!-- å¯è§†åŒ–-->
        <module>igds-databoard</module>