From 0e7cd0b33ca4c93e1fd7d2a69a2f8c2f9a28ddec Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 14:23:50 +0800 Subject: [PATCH 1/7] =?UTF-8?q?update=20=20netty=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../netty/server/NettyServerManager.java | 2 ++ .../yunkuaichong/EchoServerHandler.java | 31 +++++++++++++++++++ .../NettyServerChannelInitializer.java | 10 ++++-- .../yunkuaichong/NettyServerHandler.java | 8 ++--- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/NettyServerManager.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/NettyServerManager.java index 95dfd9e06..e886a19ab 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/NettyServerManager.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/NettyServerManager.java @@ -16,6 +16,8 @@ import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.ResourceLeakDetector; +import io.netty.util.concurrent.DefaultEventExecutorGroup; +import io.netty.util.concurrent.EventExecutorGroup; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java new file mode 100644 index 000000000..17de54448 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java @@ -0,0 +1,31 @@ +package com.jsowell.netty.server.yunkuaichong; + +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * 回复消息Handler + * + * @author Lemon + * @Date 2025/7/22 14:00:03 + */ +@ChannelHandler.Sharable +@Slf4j +@Component +public class EchoServerHandler extends ChannelInboundHandlerAdapter { + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg == null || msg == "") { + log.info("服务端响应空的消息"); + return; + } + //将客户端的信息直接返回写入ctx + ctx.write(msg); + //刷新缓存区 + ctx.flush(); + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java index a8ecf9fab..cb713237d 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java @@ -6,6 +6,8 @@ import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.bytes.ByteArrayDecoder; import io.netty.handler.timeout.IdleStateHandler; +import io.netty.util.concurrent.DefaultEventExecutorGroup; +import io.netty.util.concurrent.EventExecutorGroup; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -14,8 +16,8 @@ import java.util.concurrent.TimeUnit; @Component public class NettyServerChannelInitializer extends ChannelInitializer { - @Resource - NettyServerHandler nettyServerHandler; + // 引入业务线程池 + final EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(16); @Override protected void initChannel(SocketChannel channel) throws Exception { @@ -28,7 +30,9 @@ public class NettyServerChannelInitializer extends ChannelInitializer Date: Tue, 22 Jul 2025 16:22:37 +0800 Subject: [PATCH 2/7] =?UTF-8?q?bugfix=20=20=E4=BF=AE=E5=A4=8D0x01=E4=B8=AD?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E4=BF=AE=E6=94=B9=E6=A1=A9=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E9=97=B2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index 553007469..941784c67 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -555,7 +555,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { 0x01 登陆认证 登陆成功,把充电桩和枪口的状态都更新为【在线】 */ - if (StringUtils.equals(frameType, String.valueOf(YKCFrameTypeCode.LOGIN_CODE.getCode()))) { + if (StringUtils.equals(frameType, BytesUtil.bcd2Str(YKCFrameTypeCode.LOGIN_CODE.getBytes()))) { // 枪口状态设置为【空闲】 pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.FREE.getValue()); } From dda3751cda3d4bf45291ae00162860cb90b9a54d Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 16:23:18 +0800 Subject: [PATCH 3/7] =?UTF-8?q?update=20=20netty=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/yunkuaichong/EchoServerHandler.java | 16 ++++++++++++++++ .../server/yunkuaichong/NettyServerHandler.java | 11 +++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java index 17de54448..12960f617 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/EchoServerHandler.java @@ -27,5 +27,21 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { ctx.write(msg); //刷新缓存区 ctx.flush(); + + // ByteBuf byteBuf = (ByteBuf) msg; + // ByteBuf byteBuf = Unpooled.copiedBuffer("680d01000004882300000001290100d510", StandardCharsets.UTF_8); + // // byteBuf.readBytes(bytes); + // YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(new byte[]{}); + // + // // 获取帧类型 + // byte[] frameTypeBytes = ykcDataProtocol.getFrameType(); + // String frameType = YKCUtils.frameType2Str(frameTypeBytes); + // // 获取序列号域 + // int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber()); + // if (!CollectionUtils.containsAny(NettyServerHandler.notPrintFrameTypeList, frameType)) { + // log.info("【>>>>>平台响应消息>>>>>】channel:{}, 响应帧类型:{}, 响应帧名称:{}, 序列号域:{}, response:{}", + // ctx.channel().id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber, + // BytesUtil.binary(ykcDataProtocol.getBytes(), 16)); + // } } } diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java index 2c801c821..724c37983 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java @@ -8,6 +8,7 @@ import com.jsowell.common.util.BytesUtil; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.YKCUtils; import com.jsowell.netty.service.yunkuaichong.YKCBusinessService; +import com.jsowell.netty.service.yunkuaichong.impl.YKCBusinessServiceImpl; import io.netty.buffer.ByteBuf; import io.netty.channel.*; import io.netty.handler.timeout.IdleState; @@ -19,6 +20,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.net.InetSocketAddress; import java.util.List; import java.util.Objects; @@ -32,15 +34,17 @@ import java.util.concurrent.ConcurrentHashMap; @Component public class NettyServerHandler extends ChannelInboundHandlerAdapter { - @Autowired - private YKCBusinessService ykcService; + // @Resource + // private YKCBusinessService ykcService; /** * 管理一个全局map,保存连接进服务端的通道数量 */ private static final ConcurrentHashMap CHANNEL_MAP = new ConcurrentHashMap<>(); - private final List notPrintFrameTypeList = Lists.newArrayList("0x03"); // "0x03" + protected static final List notPrintFrameTypeList = Lists.newArrayList(); // "0x03" + + private final YKCBusinessService ykcService = new YKCBusinessServiceImpl(); /** * 有客户端连接服务器会触发此函数 @@ -150,7 +154,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ByteBuf buffer = ctx.alloc().buffer().writeBytes(response); // this.channelWrite(channel.id(), buffer); super.channelRead(ctx, buffer); - if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) { // 应答帧类型 byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes); From 028e7849ff9b8b9e1d13880d40ae848abd67fe7e Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 16:38:12 +0800 Subject: [PATCH 4/7] =?UTF-8?q?pre=E7=8E=AF=E5=A2=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=94=B9=E4=B8=BApre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-pre.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jsowell-admin/src/main/resources/application-pre.yml b/jsowell-admin/src/main/resources/application-pre.yml index 793a9ba7f..d405daf46 100644 --- a/jsowell-admin/src/main/resources/application-pre.yml +++ b/jsowell-admin/src/main/resources/application-pre.yml @@ -8,8 +8,8 @@ spring: # redis 配置 redis: # 地址 - host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com -# host: 106.14.94.149 +# host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com + host: 106.14.94.149 # 端口,默认为6379 port: 6379 # 数据库索引 @@ -17,8 +17,8 @@ spring: # 账号 username: jsowell # 密码 - password: js@160829 -# password: js160829 +# password: js@160829 + password: js160829 # 连接超时时间 timeout: 10s lettuce: @@ -38,12 +38,12 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: jsowell - password: js@160829 -# url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 -# username: jsowell_pre -# password: Js@160829 +# url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 +# username: jsowell +# password: js@160829 + url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: jsowell_pre + password: Js@160829 # 从库数据源 slave: # 从数据源开关/默认关闭 From 56fe5c1f71a9dd42955718772b6984ef813240d5 Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 16:48:27 +0800 Subject: [PATCH 5/7] =?UTF-8?q?pre=E7=8E=AF=E5=A2=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=94=B9=E4=B8=BApre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jsowell-admin/src/main/resources/application-pre.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsowell-admin/src/main/resources/application-pre.yml b/jsowell-admin/src/main/resources/application-pre.yml index d405daf46..a970fb4c5 100644 --- a/jsowell-admin/src/main/resources/application-pre.yml +++ b/jsowell-admin/src/main/resources/application-pre.yml @@ -15,7 +15,7 @@ spring: # 数据库索引 database: 0 # 账号 - username: jsowell +# username: jsowell # 密码 # password: js@160829 password: js160829 From eabac85e4edbd131ee87e781d0f6bd7b89ce3ced Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 17:23:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?update=20=20netty=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/yunkuaichong/NettyServerChannelInitializer.java | 5 ++++- .../netty/server/yunkuaichong/NettyServerHandler.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java index cb713237d..770820279 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java @@ -16,6 +16,9 @@ import java.util.concurrent.TimeUnit; @Component public class NettyServerChannelInitializer extends ChannelInitializer { + @Resource + private NettyServerHandler nettyServerHandler; + // 引入业务线程池 final EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(16); @@ -31,7 +34,7 @@ public class NettyServerChannelInitializer extends ChannelInitializer notPrintFrameTypeList = Lists.newArrayList(); // "0x03" - private final YKCBusinessService ykcService = new YKCBusinessServiceImpl(); + // private final YKCBusinessService ykcService = new YKCBusinessServiceImpl(); /** * 有客户端连接服务器会触发此函数 From b44487e9e4270e56f5e0af0423cabbc0ed0595f0 Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 22 Jul 2025 17:29:05 +0800 Subject: [PATCH 7/7] =?UTF-8?q?update=20=20netty=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/yunkuaichong/NettyServerChannelInitializer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java index 770820279..492518baa 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerChannelInitializer.java @@ -19,6 +19,9 @@ public class NettyServerChannelInitializer extends ChannelInitializer