保存时间

This commit is contained in:
Guoqs
2024-08-28 09:09:12 +08:00
parent 4dd35c2051
commit 552db1841e
5 changed files with 9 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ public abstract class AbstractEBikeHandler implements InitializingBean {
*/
protected void saveLastTimeAndCheckChannel(String pileSn, ChannelHandlerContext ctx) {
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的关系
PileChannelEntity.checkChannel(pileSn, ctx);

View File

@@ -36,6 +36,8 @@ public class GetServerTimeHandler extends AbstractEBikeHandler {
// 解析字节数组
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
log.info("设备获取服务器时间:{}", JSON.toJSONString(message));
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
// 获取当前服务器10位时间戳
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));

View File

@@ -35,6 +35,8 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
log.info("设备心跳包:{}", JSON.toJSONString(message));
return getResult(dataProtocol, Constants.zeroByteArray);

View File

@@ -35,6 +35,8 @@ public class RegistrationHandler extends AbstractEBikeHandler {
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
log.info("设备注册包:{}", JSON.toJSONString(message));
return getResult(dataProtocol, Constants.zeroByteArray);

View File

@@ -34,6 +34,8 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd03 message = (EBikeMessageCmd03) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
log.info("结算消费信息上传:{}", JSON.toJSONString(message));
return null;