package com.ruoyi.dataInterchange.server; import com.alibaba.fastjson.JSON; import com.ruoyi.dataInterchange.model.enu.DataType; import com.ruoyi.dataInterchange.netty.client.ChannelMap; import com.ruoyi.dataInterchange.util.jtt809.packet.common.OuterPacket; import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import javax.annotation.Resource; /** * @author zhibing.pu * @Date 2025/3/6 15:46 */ @Slf4j @Component public class UPLinkTestReqService { @Resource private RedisTemplate redisTemplate; @Resource private DOWNConnectRspService downConnectRspService; /** * 主链路连接保持 * * @param ctx * @param out */ public void linkTest(ChannelHandlerContext ctx, OuterPacket out) { if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) { log.error("链路还未登录校验,拒绝连接:{}", out.getGnsscenterId()); ctx.close(); return; } int gnsscenterId = out.getGnsscenterId(); //保存链路 ChannelMap.addServerChannel(gnsscenterId, ctx.channel()); OuterPacket rep = new OuterPacket(DataType.UP_LINKTEST_RSP.getCode(), gnsscenterId, null); rep.setGnsscenterId(gnsscenterId); log.info("主链路连接保持应答({}):{}", DataType.UP_LINKTEST_RSP.getCode(), JSON.toJSONString(rep)); ctx.writeAndFlush(rep); //从链路保持请求 downConnectRspService.downLinkTest(gnsscenterId); } }