vince
2024-01-27 facc0ea3fa37091a98aa1e0a0d1081fd32fba28e
优化协议
已修改16个文件
330 ■■■■■ 文件已修改
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/ProtocolRunner.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-pro5308.yml 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-proGateway.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
@@ -34,6 +34,7 @@
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(TCP_FZZY_V3.getCode(), TCP_FZZY_V3.getName()));
        list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName()));
        list.add(new ApiTrigger(GRAIN_BHZN_V0_WEB.getCode(), GRAIN_BHZN_V0_WEB.getName()));
        list.add(new ApiTrigger(GRAIN_FZZY_BHZN_WEB.getCode(), GRAIN_FZZY_BHZN_WEB.getName()));
        list.add(new ApiTrigger(GRAIN_FZZY_ZLDZ_WEB.getCode(), GRAIN_FZZY_ZLDZ_WEB.getName()));
        list.add(new ApiTrigger(GRAIN_YOUXIAN0_2023.getCode(), GRAIN_YOUXIAN0_2023.getName()));
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -2,13 +2,17 @@
import com.alibaba.fastjson.JSON;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.DateUtil;
import com.fzzy.data.ConfigData;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.data.WeatherWebDto;
import com.fzzy.gateway.entity.GatewayConf;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayConfService;
import com.fzzy.gateway.service.GatewayDeviceTestPR;
import com.fzzy.gateway.util.GatewayHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@@ -16,10 +20,7 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * 网关相关的定时器
@@ -43,6 +44,8 @@
    @Resource
    private ConfigData configData;
    @Resource
    private GatewayDeviceTestPR gatewayDeviceTestPR;
    /**
     * <p>
@@ -55,7 +58,46 @@
        doHeartbeat();
    }
    /**
     * <p>
     * 粮情每天11点穿上区
     */
    @Scheduled(cron = "0 0 11 * * ?")
    public void scheduledGrain() {
        //获取设备配置,只针对粮情设备进行执行
        log.info("定时kafka粮情推送");
        List<GatewayDevice> list = gatewayDeviceTestPR.listAll();
        if (null == list || list.isEmpty()) {
            log.error("为获取到系统中设备配置,取消执行\"");
            return ;
        }
        BaseReqData reqData;
        BaseResp resp;
        for (GatewayDevice device : list) {
            //如果不是粮情分机跳过
            if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
                continue;
            }
            reqData = new BaseReqData();
            reqData.setProductId(device.getProductId());
            reqData.setDeviceName(device.getDeviceName());
            reqData.setDeviceId(device.getDeviceId());
            reqData.setDayTime(new Date());
            reqData.setDevice(device);
            //获取到
            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData);
            log.info("resp = "+resp.toString());
            //自动推送
            if (BaseResp.CODE_200 == resp.getCode()) {
                reqData.setData(resp.getData());
                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByHand(reqData);
            }
        }
    }
    /**
     * <p>
     * 每间隔3秒执行一次事件
src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
@@ -4,6 +4,7 @@
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.DateUtil;
import com.fzzy.async.fzzy40.Fzzy40CommonService;
import com.fzzy.async.fzzy40.entity.Fz40Grain;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.api.GatewayRemoteManager;
@@ -35,8 +36,8 @@
    @Resource
    private GatewayDeviceRep gatewayDeviceRep;
//    @Resource
//    private Fzzy40CommonService fzzy40CommonService;
    @Resource
    private Fzzy40CommonService fzzy40CommonService;
    @Resource
    private GatewayRemoteManager gatewayRemoteManager;
//    @Resource
@@ -119,7 +120,7 @@
    }
    private String pushByV40(List<GatewayDevice> list, Date start, Date end) {
    public String pushByV40(List<GatewayDevice> list, Date start, Date end) {
        String depotIdSys;
        List<Fz40Grain> listGrain;
@@ -138,8 +139,8 @@
            }
            //TODO ----》
           // listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
            listGrain = null;
            listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
            //listGrain = null;
            if (null == listGrain || listGrain.isEmpty()) {
                log.info("---------设备---{}--未同步到粮情信息,请确认当前条件下是否有数据", device.getDeviceName());
                continue;
@@ -157,7 +158,7 @@
            }
           // deviceReportService.pushGrainData2Cloud(pushData);
           // deviceReportService.reportGrainDataByHand(pushData);
        }
src/main/java/com/fzzy/protocol/ProtocolRunner.java
@@ -1,6 +1,7 @@
package com.fzzy.protocol;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine;
import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine;
import com.fzzy.protocol.fzzy.server.FzzyServerEngine;
import com.fzzy.protocol.weightyh.YhScaleServerEngine;
import com.fzzy.protocol.zldz.server.ZldzServerEngine;
@@ -34,7 +35,8 @@
        //邦海智能纯网口设备协议
        BhznGrainV2ServerEngine.start(null);
        //邦海智能无线主机设备协议
        BhznGrainV0ServerEngine.start(null);
    }
}
src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java
@@ -108,19 +108,19 @@
    private void analysisGrain(IoMessage message) {
        try {
            //根据分机SN获取设备配置信息
            GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(message.getAddr());
            GatewayDevice gatewayDevice = BhznGrainV0ServerUtils.contextOrder;
            if (null == gatewayDevice) {
                replayGrain(message);
                log.error("主机-------->>平台,解析粮情失败,未获取到系统设备配置信息:" + message.getAddr());
                return;
            }
            //根据分机地址获取分机信息
            ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
            if (commonDevice == null) {
                replayGrain(message);
                log.error("主机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + message.getAddr());
                return;
            }
//            ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp());
//            if (commonDevice == null) {
//                replayGrain(message);
//                log.error("主机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + message.getAddr());
//                return;
//            }
            //获取请求信息
            BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys());
@@ -188,7 +188,7 @@
        String hexStr = CommandBuild.getMsgGrainReply(message.getAddr());
        log.info("平台--------->>>主机,返回粮情报文收到信息,报文={}", hexStr);
        BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
        BhznGrainV0ServerEngine.pushByMin(hexStr);
    }
    /**
@@ -562,7 +562,7 @@
        } finally {
            String hexStr = CommandBuild.getMsgTHReply(message.getAddr());
            log.info("平台--------->>>主机,返回仓温仓湿收到信息,报文={}", hexStr);
            BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr));
            BhznGrainV0ServerEngine.pushByMin(hexStr);
        }
    }
src/main/java/com/fzzy/protocol/bhzn/v0/cmd/CommandBuild.java
@@ -2,7 +2,7 @@
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerUtils;
/**
 * 命令生成
@@ -31,8 +31,8 @@
        StringBuffer sb = new StringBuffer();
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
        sb.append(BhznGrainV0ServerUtils.MSG_START);
        sb.append(BhznGrainV0ServerUtils.MSG_START2);
        //分机地址
        int i = Integer.parseInt(grainAddr);
@@ -42,7 +42,7 @@
        sb.append("0001");
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_F2);
        sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_F2);
        //数据长度-01
        sb.append("01");
@@ -51,10 +51,10 @@
        sb.append("01");
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
        sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
        sb.append(BhznGrainV0ServerUtils.MSG_END_16);
        return sb.toString();
    }
@@ -71,8 +71,8 @@
        StringBuffer sb = new StringBuffer();
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
        sb.append(BhznGrainV0ServerUtils.MSG_START);
        sb.append(BhznGrainV0ServerUtils.MSG_START2);
        //分机地址
        int i = Integer.parseInt(grainAddr);
@@ -82,7 +82,7 @@
        sb.append("0001");
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_83);
        sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_83);
        //数据长度-01
        sb.append("01");
@@ -92,10 +92,10 @@
        sb.append(BytesUtil.intToHexStr1(i));
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
        sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
        sb.append(BhznGrainV0ServerUtils.MSG_END_16);
        return sb.toString();
    }
@@ -111,8 +111,8 @@
        StringBuffer sb = new StringBuffer();
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
       // sb.append(BhznGrainV0ServerUtils.MSG_START);
        sb.append(BhznGrainV0ServerUtils.MSG_START2);
        //分机地址
        int i = Integer.parseInt(grainAddr);
@@ -122,7 +122,7 @@
        sb.append("0001");
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_93);
        sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_93);
        //数据长度-01
        sb.append("01");
@@ -131,10 +131,10 @@
        sb.append("01");
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
        sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
        sb.append(BhznGrainV0ServerUtils.MSG_END_16);
        return sb.toString();
    }
@@ -149,8 +149,8 @@
        StringBuffer sb = new StringBuffer();
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
        sb.append(BhznGrainV0ServerUtils.MSG_START);
        sb.append(BhznGrainV0ServerUtils.MSG_START2);
        //分机地址
        int i = Integer.parseInt(grainAddr);
@@ -160,7 +160,7 @@
        sb.append("0001");
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_92);
        sb.append(BhznGrainV0ServerUtils.FUNCTION_ID_92);
        //数据长度-01
        sb.append("01");
@@ -169,10 +169,10 @@
        sb.append("01");
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
        sb.append(BhznGrainV0ServerUtils.getCheck(sb.toString()));
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
        sb.append(BhznGrainV0ServerUtils.MSG_END_16);
        return sb.toString();
    }
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0HeartbeatImpl.java
@@ -17,8 +17,10 @@
    @Override
    public byte[] provide(IoSession session) {
        //直接根据主机SESSIOn判断
        IoSession session1 = BhznGrainV0ServerUtils.getSession();
        Long lastBeatTime = BhznGrainV0ServerUtils.getHearBeat(session);
        Long lastBeatTime = BhznGrainV0ServerUtils.getHearBeat(session1);
        if (null == lastBeatTime) {
            return null;
@@ -29,7 +31,8 @@
        if (deTime > (BhznGrainV0ServerUtils.HEART_BEAT_TIME * 3 * 1000)) {
            log.info("-----------超过{}秒未获取到心跳信息,判定终端离线,踢出连接------------{}-{}", deTime, session.getAddress(), session.getPort());
            session.destroy();
           // session.destroy();
        }
        return null;
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0MessageConsumer.java
@@ -1,6 +1,7 @@
package com.fzzy.protocol.bhzn.v0.server;
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.api.utils.SpringUtil;
import com.fzzy.protocol.bhzn.v0.analysis.AnalysisService;
import com.fzzy.protocol.bhzn.v0.cmd.ReMessageBuilder;
import com.fzzy.protocol.bhzn.v0.data.IoMessage;
@@ -38,7 +39,7 @@
        BhznGrainV0ServerUtils.addHeartBeat(ioSession);
        //默认设置主通讯服务
        //BhznGrainV2ServerUtils.addSession(ioSession);
        BhznGrainV0ServerUtils.addSession(ioSession);
        try {
            String hexStr = BytesUtil.bytesToString(bytes);
@@ -48,7 +49,7 @@
            IoMessage ioMessage = ReMessageBuilder.getInstance().buildMessage(hexStr);
            ioMessage.setIp(ioSession.getAddress());
            ioMessage.setPort(ioSession.getPort());
            analysisService = SpringUtil.getBean(AnalysisService.class);
            analysisService.analysis(ioSession.getBusinessKey(), ioMessage);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerEngine.java
@@ -1,5 +1,7 @@
package com.fzzy.protocol.bhzn.v0.server;
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
import com.fzzy.protocol.fzzy.server.ServerUtils;
import com.ld.io.api.*;
import com.ld.io.netty.NettyServer;
@@ -15,7 +17,7 @@
public class BhznGrainV0ServerEngine {
    public static final Integer PORT = 19302;
    public static final Integer PORT = 19303;
    public static NettyServer ioServer = null;
@@ -39,8 +41,13 @@
        }
        //确认结尾标志-没有固定结束符号
        ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT);
        //确认结尾标志
        //ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
//        ioServerOption.setSplitDecoderType(SplitByteDecoderType.NO_LIMIT);
        ioServerOption.setDelimiter(BhznGrainV2ServerUtils.MSG_END.getBytes());
        ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL);
        // 配置系统心跳间隔
        ioServerOption.setReaderIdleTime(5 * 60);
@@ -64,28 +71,17 @@
    }
    /**
     * 发送信息
     *
     * @param ip
     * @param port
     * @param msg
     * @return
     * 直接使用内存的Session执行
     */
    public static InvokeResult push(String ip, int port, byte[] msg) {
        IoSessionQuery sessionFactory = ioServer.getSessionQuery();
        List<IoSession> sessions = sessionFactory.getAllSession();
        IoSession session = null;
        for (IoSession ioSession : sessions) {
            if (ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) {
                session = ioSession;
                break;
            }
        }
    public static InvokeResult pushByMin(String hexStr) {
        IoSession session = BhznGrainV0ServerUtils.getSession();
        if (null == session) {
            return InvokeResult.CHANNEL_CLOSED;
        }
        byte[] msg = BytesUtil.hexStrToBytes(hexStr);
        return session.invoke(msg);
    }
}
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0ServerUtils.java
@@ -2,7 +2,7 @@
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
import com.fzzy.gateway.entity.GatewayDevice;
import com.ld.io.api.IoSession;
import java.util.HashMap;
@@ -20,15 +20,16 @@
     * 记录每个连接的最后一次信息时间 key = 连接的KYE,data =当前时间戳
     */
    public static Map<String, Long> contextMapHeart = new HashMap<>();
    public static Map<String, IoSession> contextIoSession = new HashMap<>();
    public static  GatewayDevice contextOrder = new GatewayDevice();
    public static int HEART_BEAT_TIME = 30;//心跳间隔时间
    public static String MSG_START = "3C42485A4E3E";//<BHZN>
    public static String MSG_START2 = "AA";
    public static String MSG_END = "<END>";//<END>
    public static String MSG_END_16 = "3C454E443E";//<END>
    public static String MSG_END_16 = "3C454E443E";//<END>3C454E443E
    public static final String CHARSET = "UTF-8";
@@ -78,7 +79,7 @@
     * @return
     */
    public static String getCheck(String content) {
        int start = BhznGrainV2ServerUtils.MSG_START.length() + BhznGrainV2ServerUtils.MSG_START2.length();
        int start = BhznGrainV0ServerUtils.MSG_START.length() + BhznGrainV0ServerUtils.MSG_START2.length();
        content = content.substring(start);
        int sum = 0;
        String hex;
@@ -91,4 +92,12 @@
        return BytesUtil.intToHexStr(256 - check).substring(2);
    }
    public static void addSession(IoSession session) {
        contextIoSession.put(DEFAULT_MAC_ID, session);
    }
    public static IoSession getSession() {
        return contextIoSession.get(DEFAULT_MAC_ID);
    }
}
src/main/java/com/fzzy/protocol/bhzn/v0/server/BhznGrainV0SessionListener.java
@@ -2,11 +2,15 @@
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.SpringUtil;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayDeviceService;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
 *
@@ -23,13 +27,31 @@
     */
    @Override
    public void onCreate(IoSession session) {
        //添加到内存
        BhznGrainV0ServerUtils.addSession(session);
        log.info("++++新建连接++++-IP={},PORT={}", session.getAddress(), session.getPort());
        // 添加自定义业务ID
        session.setBusinessKey(BhznGrainV0ServerUtils.getServerKey(session.getAddress(), session.getPort()));
        //执行分机上线
//        GatewayDeviceService gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class);
//        List<GatewayDevice> devices = gatewayDeviceService.listAll();
//        //执行分机上线
//        if(devices!= null && devices.size()>0){
//            ApiCommonDevice device =null;
//            for (GatewayDevice d:devices) {
//                device = new ApiCommonDevice();
//                device.setIp(d.getIp());
//                device.setPort(d.getPort());
//                device.setStatus(Constant.YN_N);
//                device.setSn(d.getDeviceSn());
//                device.setCode("ERROR");
//                device.setMsg("设备离线");
//            }
//
//
//            contextDeviceMap.put(device.getIp(), device);
//
//        }
        Constant.updateCacheOnline(session.getAddress(), session.getPort());
    }
src/main/java/com/fzzy/protocol/bhzn/v0/service/Bhzn0GatewayGrainService.java
@@ -9,8 +9,9 @@
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.protocol.ProtocolUtils;
import com.fzzy.protocol.bhzn.cmd.CommandBuild;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine;
import com.fzzy.protocol.bhzn.v0.cmd.CommandBuild;
import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine;
import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerUtils;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -33,26 +34,26 @@
        BaseResp resp = new BaseResp();
        GatewayDevice device = reqData.getDevice();
        BhznGrainV0ServerUtils.contextOrder = device;
        //获取连接中的设备信息
        ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCache(device.getIp());
//        ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCacheBySn(device.getDeviceSn());
//
//        if (null == apiCommonDevice) {
//            resp.setCode(500);
//            resp.setMsg("系统未获取到下行连接设备信息,无法执行");
//            log.error("----------------系统未获取到下行连接设备信息,无法执行---------");
//            return resp;
//        }
//
//        if (Constant.YN_N.equals(apiCommonDevice.getStatus())) {
//            resp.setCode(500);
//            resp.setMsg("下行设备不在线---无法执行----" + device.getDeviceName());
//            log.error("下行设备不在线---无法执行----" + device.getDeviceName());
//            return resp;
//        }
        if (null == apiCommonDevice) {
            resp.setCode(500);
            resp.setMsg("系统未获取到下行连接设备信息,无法执行");
            log.error("----------------系统未获取到下行连接设备信息,无法执行---------");
            return resp;
        }
        if (Constant.YN_N.equals(apiCommonDevice.getStatus())) {
            resp.setCode(500);
            resp.setMsg("下行设备不在线---无法执行----" + device.getDeviceName());
            log.error("下行设备不在线---无法执行----" + device.getDeviceName());
            return resp;
        }
        device.setIp(apiCommonDevice.getIp());
        device.setPort(apiCommonDevice.getPort());
//        device.setIp(apiCommonDevice.getIp());
//        device.setPort(apiCommonDevice.getPort());
        reqData.setDevice(device);
@@ -63,7 +64,7 @@
            // 生成粮情信息
            String hexStr = CommandBuild.getInstance().getMsgCheck(device.getDeviceSn(), device.getDepotIdSys());
            // 发送命令
            InvokeResult message = BhznGrainV2ServerEngine.push(device.getIp(), device.getPort(), BytesUtil.hexStrToBytes(hexStr));
            InvokeResult message = BhznGrainV0ServerEngine.pushByMin(hexStr);
            log.error("平台------>>>>控制柜:发送粮情检测命令-{}", message);
src/main/java/com/fzzy/protocol/youxian0/client/ClientEngine.java
@@ -103,6 +103,7 @@
            return InvokeResult.SOCKET_NOT_CREATE;
        }
        if (!defaultChannel.isActive()) {
            defaultChannel = null;
            return InvokeResult.CHANNEL_CLOSED;
        }
@@ -143,6 +144,7 @@
            return InvokeResult.SOCKET_NOT_CREATE;
        }
        if (!channel.isActive()) {
            defaultChannel = null;
            return InvokeResult.CHANNEL_CLOSED;
        }
        channel.writeAndFlush(Unpooled.copiedBuffer(BytesUtil.hexStrToBytes(hex))).sync();
src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java
@@ -32,7 +32,7 @@
        InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
        log.info("连接终端掉线,IP={},port={}", socketAddress.getAddress(), socketAddress.getPort());
        //ClientEngine.defaultChannel = null;
        ClientEngine.defaultChannel = null;
    }
src/main/resources/application-pro5308.yml
@@ -1,20 +1,18 @@
server:
  port: 8081
  jetty:
    max-http-post-size: 209715200
  tomcat:
    max-http-post-size: 209715200
  port: 8090
spring:
  datasource:
    #主数据源
    primary:
      url: jdbc:mysql://127.0.0.1:3306/igds_api?useUnicode=true&characterEncoding=utf-8
      url: jdbc:mysql://127.0.0.1:3306/igds_api_2023?useUnicode=true&useSSL=false&characterEncoding=utf-8
      username: root
      password: Abc123..
      driver-class-name: com.mysql.jdbc.Driver
    #次数据源
    secondary:
      url: jdbc:mysql://127.0.0.1:3306/igds_3.5?useUnicode=true&characterEncoding=utf-8
      url: jdbc:mysql://127.0.0.1:3306/igds_3.5?useUnicode=true&useSSL=false&characterEncoding=utf-8
      username: root
      password: Abc123..
      driver-class-name: com.mysql.jdbc.Driver
@@ -37,7 +35,7 @@
          dialect: org.hibernate.dialect.MySQL5InnoDBDialect
  # Redis相关配置
  redis:
    database: 0
    database: 5
    host: 127.0.0.1
    port: 6379
    password:
@@ -48,3 +46,51 @@
      max-idle: 10
      min-idle: 0
      timeout: 6000
  kafka:
    bootstrap-servers: 103.203.217.16:9092
    producer:
      retries: 0
      acks: 1
      batch-size: 16384
      buffer-memory: 33554432
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
    properties:
      security.protocol: SASL_PLAINTEXT
      sasl.mechanism: PLAIN
      sasl.username: sc001
      sasl.password: wCV0ISwmoKwbx1lpBKMW
      sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username='sc001' password='wCV0ISwmoKwbx1lpBKMW';
    consumer:
      group-id: fzzygroup
      enable-auto-commit: true
      auto-commit-interval: 100
      auto-offset-reset: latest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
  mqtt:
    host: tcp://127.0.0.1:1883
    username: admin
    password: admin123321
    client-inId: fzzy_client_id_in_igds_api
    client-outId: fzzy_client_id_out_igds_api
    completionTimeout: 3000
    keep-alive-interval: 2
    max-connect-times: 5
    qos: 0
    isOpen: false
    default-topic: mqtt/+/test1
    topics: /device-message-sender/#
license:
  subject: ld_license
  publicAlias: publicCert
  storePass: PUBLICFZZYXXJSGFYXGS888888
  licensePath: D:/IGDS/license/license.lic
  publicKeysStorePath: D:/IGDS/license/publicCerts.keystore
igds:
  default:
  companyId: 5308
  file-path: D:/app/igds-api
  img-path: D:/IGDS/FILE/
  weather-url: https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}
src/main/resources/application-proGateway.yml
@@ -35,7 +35,7 @@
          dialect: org.hibernate.dialect.MySQL5InnoDBDialect
  # Redis相关配置
  redis:
    database: 0
    database: 5
    host: 127.0.0.1
    port: 6379
    password: