update 将桩与连接channel的关系改为一对多

This commit is contained in:
Lemon
2025-05-27 10:34:35 +08:00
parent 8ec72f0f12
commit 9731a53205
6 changed files with 333 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.protocol.SyncPromise;
import com.jsowell.common.util.*;
import com.jsowell.common.util.Cp56Time2a.Cp56Time2aUtil;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.ykcCommond.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.web.BillingTemplateVO;
@@ -22,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@@ -29,6 +31,7 @@ import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/**
@@ -53,6 +56,9 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
// 需要记录报文的数据帧类型
private final List<String> frameTypeList = Lists.newArrayList(
YKCUtils.frameType2Str(YKCFrameTypeCode.REMOTE_RESTART_CODE.getBytes()),
@@ -118,6 +124,16 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
log.info("【push结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), value, wholeMsg);
log.error("push发送命令失败, pileSn:{}", pileSn, cause);
// 异步删除Map中的保存关系(带关闭连接)
// CompletableFuture.runAsync(() -> {
// try {
// // 删除Map中的保存关系
// PileChannelEntity.deleteChannel(pileSn, ctx);
// } catch (Exception e) {
// log.error("异步删除、关闭连接 error", e);
// }
// }, executor);
}
});
@@ -213,6 +229,16 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
log.info("【push结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), frameTypeName, wholeMsg);
log.error("push发送命令失败, pileSn:{}", pileSn, cause);
// 异步删除Map中的保存关系(带关闭连接)
// CompletableFuture.runAsync(() -> {
// try {
// // 删除Map中的保存关系
// PileChannelEntity.deleteChannel(pileSn, ctx);
// } catch (Exception e) {
// log.error("异步删除、关闭连接 error", e);
// }
// }, executor);
}
});