This commit is contained in:
Lemon
2025-07-02 10:12:56 +08:00
parent 5776bf2505
commit a951e079b7
5 changed files with 31 additions and 20 deletions

View File

@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@@ -149,8 +150,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
// 响应客户端
ByteBuf buffer = ctx.alloc().buffer().writeBytes(response);
this.channelWrite(channel.id(), buffer);
// 获取桩号
String pileSn = PileChannelEntity.getPileSnByChannelId(ctx.channel().id().asLongText());
// 批量响应客户端
// this.channelWriteBatch(ctx, buffer);
this.channelWriteBatch(pileSn, buffer);
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
// 应答帧类型
byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes);
@@ -172,7 +175,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
* @param ctx
* @param msg
*/
private void channelWriteBatch(String pileSn, ChannelHandlerContext ctx, Object msg) {
private void channelWriteBatch(String pileSn, Object msg) {
// 获取该桩下的所有channel
List<ChannelHandlerContext> list = PileChannelEntity.pileMap.get(pileSn);
if(CollectionUtils.isEmpty(list)) {
@@ -304,7 +307,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
}
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size());
// 删除连接
// PileChannelEntity.deleteChannel(pileSn, ctx);
PileChannelEntity.deleteChannel(pileSn, ctx);
ctx.channel().close();
}
} finally {

View File

@@ -88,7 +88,7 @@ public class YKCBusinessServiceImpl implements YKCBusinessService {
pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, "");
// 删除连接
// PileChannelEntity.deleteChannel(pileSn, ctx);
PileChannelEntity.deleteChannel(pileSn, ctx);
// 删除桩编号和channel的关系
// PileChannelEntity.removeByPileSn(pileSn);