mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-06 15:08:05 +08:00
Merge branch 'dev' of http://192.168.2.46:8099/jsowell/jsowell-charger-web into dev
This commit is contained in:
@@ -58,7 +58,7 @@ public abstract class AbstractEBikeHandler implements InitializingBean {
|
|||||||
*/
|
*/
|
||||||
protected void saveLastTimeAndCheckChannel(String pileSn, ChannelHandlerContext ctx) {
|
protected void saveLastTimeAndCheckChannel(String pileSn, ChannelHandlerContext ctx) {
|
||||||
String redisKey = CacheConstants.PILE_LAST_CONNECTION + pileSn;
|
String redisKey = CacheConstants.PILE_LAST_CONNECTION + pileSn;
|
||||||
redisCache.setCacheObject(redisKey, DateUtils.getDateTime(), CacheConstants.cache_expire_time_1d);
|
redisCache.setCacheObject(redisKey, DateUtils.getDateTime(), CacheConstants.cache_expire_time_30d);
|
||||||
|
|
||||||
// 保存桩号和channel的关系
|
// 保存桩号和channel的关系
|
||||||
PileChannelEntity.checkChannel(pileSn, ctx);
|
PileChannelEntity.checkChannel(pileSn, ctx);
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public class GetServerTimeHandler extends AbstractEBikeHandler {
|
|||||||
// 解析字节数组
|
// 解析字节数组
|
||||||
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||||
log.info("设备获取服务器时间:{}", JSON.toJSONString(message));
|
log.info("设备获取服务器时间:{}", JSON.toJSONString(message));
|
||||||
|
// 保存时间
|
||||||
|
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||||
|
|
||||||
// 获取当前服务器10位时间戳
|
// 获取当前服务器10位时间戳
|
||||||
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));
|
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
|||||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||||
// 解析字节数组
|
// 解析字节数组
|
||||||
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||||
|
// 保存时间
|
||||||
|
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||||
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
||||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class RegistrationHandler extends AbstractEBikeHandler {
|
|||||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||||
// 解析字节数组
|
// 解析字节数组
|
||||||
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||||
|
// 保存时间
|
||||||
|
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||||
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
|
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
|
||||||
log.info("设备注册包:{}", JSON.toJSONString(message));
|
log.info("设备注册包:{}", JSON.toJSONString(message));
|
||||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
|
|||||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||||
// 解析字节数组
|
// 解析字节数组
|
||||||
EBikeMessageCmd03 message = (EBikeMessageCmd03) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
EBikeMessageCmd03 message = (EBikeMessageCmd03) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||||
|
// 保存时间
|
||||||
|
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||||
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
|
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
|
||||||
log.info("结算消费信息上传:{}", JSON.toJSONString(message));
|
log.info("结算消费信息上传:{}", JSON.toJSONString(message));
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
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 java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -123,13 +124,20 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
|
|||||||
String channelIdShortText = channelId.asShortText();
|
String channelIdShortText = channelId.asShortText();
|
||||||
String pileSn = PileChannelEntity.getPileSnByChannelId(channelIdShortText);
|
String pileSn = PileChannelEntity.getPileSnByChannelId(channelIdShortText);
|
||||||
log.error("发生异常 channelId:{}, pileSn:{}", channelIdShortText, pileSn, cause);
|
log.error("发生异常 channelId:{}, pileSn:{}", channelIdShortText, pileSn, cause);
|
||||||
cause.printStackTrace();
|
// cause.printStackTrace();
|
||||||
// 如果桩连到平台,在1分钟内没有发送数据过来,会报ReadTimeoutException异常
|
// 如果桩连到平台,在1分钟内没有发送数据过来,会报ReadTimeoutException异常
|
||||||
if (cause instanceof ReadTimeoutException) {
|
if (cause instanceof ReadTimeoutException) {
|
||||||
if (log.isTraceEnabled()) {
|
// if (log.isTraceEnabled()) {
|
||||||
log.trace("Connection timeout 【{}】", ctx.channel().remoteAddress());
|
// log.trace("Connection timeout 【{}】", ctx.channel().remoteAddress());
|
||||||
}
|
// }
|
||||||
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount());
|
log.error("【{}】发生了错误: 读取超时, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount());
|
||||||
|
ctx.channel().close();
|
||||||
|
}
|
||||||
|
if (cause instanceof IOException) {
|
||||||
|
// if (log.isTraceEnabled()) {
|
||||||
|
// log.trace("客户端断开链接 【{}】", ctx.channel().remoteAddress());
|
||||||
|
// }
|
||||||
|
log.error("【{}】发生了错误: 客户端强制断开链接, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount());
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
}
|
}
|
||||||
// close(channelId, pileSn);
|
// close(channelId, pileSn);
|
||||||
|
|||||||
Reference in New Issue
Block a user