mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-13 03:39:55 +08:00
Merge branch 'dev-zza' into dev
This commit is contained in:
@@ -8,17 +8,17 @@ spring:
|
|||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com
|
# host: r-uf6k0uet7mihr5z78f.redis.rds.aliyuncs.com
|
||||||
# host: 106.14.94.149
|
host: 106.14.94.149
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 账号
|
# 账号
|
||||||
username: jsowell
|
# username: jsowell
|
||||||
# 密码
|
# 密码
|
||||||
password: js@160829
|
# password: js@160829
|
||||||
# password: js160829
|
password: js160829
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
@@ -38,12 +38,12 @@ spring:
|
|||||||
druid:
|
druid:
|
||||||
# 主库数据源
|
# 主库数据源
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://rm-uf6ra51u33dc3798l.mysql.rds.aliyuncs.com:3306/jsowell_prd?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
# 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
|
# username: jsowell
|
||||||
password: js@160829
|
# password: js@160829
|
||||||
# url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
url: jdbc:mysql://106.14.94.149:3306/jsowell_pre?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
# username: jsowell_pre
|
username: jsowell_pre
|
||||||
# password: Js@160829
|
password: Js@160829
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
slave:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import io.netty.handler.logging.LogLevel;
|
|||||||
import io.netty.handler.logging.LoggingHandler;
|
import io.netty.handler.logging.LoggingHandler;
|
||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
import io.netty.util.ResourceLeakDetector;
|
import io.netty.util.ResourceLeakDetector;
|
||||||
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||||
|
import io.netty.util.concurrent.EventExecutorGroup;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.handler.codec.bytes.ByteArrayDecoder;
|
import io.netty.handler.codec.bytes.ByteArrayDecoder;
|
||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||||
|
import io.netty.util.concurrent.EventExecutorGroup;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -15,7 +17,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
|
public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
NettyServerHandler nettyServerHandler;
|
private NettyServerHandler nettyServerHandler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EchoServerHandler echoServerHandler;
|
||||||
|
|
||||||
|
// 引入业务线程池
|
||||||
|
final EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(16);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel channel) throws Exception {
|
protected void initChannel(SocketChannel channel) throws Exception {
|
||||||
@@ -28,7 +36,9 @@ public class NettyServerChannelInitializer extends ChannelInitializer<SocketChan
|
|||||||
pipeline.addLast("encoder", new ByteArrayDecoder());
|
pipeline.addLast("encoder", new ByteArrayDecoder());
|
||||||
// 读超时时间设置为30s,0表示不监控
|
// 读超时时间设置为30s,0表示不监控
|
||||||
pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS));
|
pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS));
|
||||||
pipeline.addLast("handler", nettyServerHandler);
|
// pipeline.addLast("handler", nettyServerHandler);
|
||||||
|
pipeline.addLast(businessGroup, nettyServerHandler); // 消息先进入业务线程池
|
||||||
|
pipeline.addLast(echoServerHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.jsowell.common.util.BytesUtil;
|
|||||||
import com.jsowell.common.util.StringUtils;
|
import com.jsowell.common.util.StringUtils;
|
||||||
import com.jsowell.common.util.YKCUtils;
|
import com.jsowell.common.util.YKCUtils;
|
||||||
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
|
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
|
||||||
|
import com.jsowell.netty.service.yunkuaichong.impl.YKCBusinessServiceImpl;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.handler.timeout.IdleState;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -32,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@Component
|
@Component
|
||||||
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private YKCBusinessService ykcService;
|
private YKCBusinessService ykcService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +42,9 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
*/
|
*/
|
||||||
private static final ConcurrentHashMap<ChannelId, ChannelHandlerContext> CHANNEL_MAP = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<ChannelId, ChannelHandlerContext> CHANNEL_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final List<String> notPrintFrameTypeList = Lists.newArrayList("0x03"); // "0x03"
|
protected static final List<String> notPrintFrameTypeList = Lists.newArrayList(); // "0x03"
|
||||||
|
|
||||||
|
// private final YKCBusinessService ykcService = new YKCBusinessServiceImpl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 有客户端连接服务器会触发此函数
|
* 有客户端连接服务器会触发此函数
|
||||||
@@ -148,11 +152,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
if (Objects.nonNull(response)) {
|
if (Objects.nonNull(response)) {
|
||||||
// 响应客户端
|
// 响应客户端
|
||||||
ByteBuf buffer = ctx.alloc().buffer().writeBytes(response);
|
ByteBuf buffer = ctx.alloc().buffer().writeBytes(response);
|
||||||
this.channelWrite(channel.id(), buffer);
|
// this.channelWrite(channel.id(), buffer);
|
||||||
// 获取桩号
|
super.channelRead(ctx, buffer);
|
||||||
// String pileSn = PileChannelEntity.getPileSnByChannelId(ctx.channel().id().asLongText());
|
|
||||||
// 批量响应客户端
|
|
||||||
// this.channelWriteBatch(pileSn, buffer);
|
|
||||||
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
|
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
|
||||||
// 应答帧类型
|
// 应答帧类型
|
||||||
byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes);
|
byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes);
|
||||||
|
|||||||
@@ -555,7 +555,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
|
|||||||
0x01 登陆认证
|
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());
|
pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.FREE.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user