This commit is contained in:
2023-12-07 16:19:47 +08:00
parent 829e9f02f7
commit e9fa001da9
29 changed files with 47 additions and 39 deletions

View File

@@ -66,7 +66,7 @@ public abstract class AbstractHandler implements InitializingBean {
* 保存桩最后链接到平台的时间 * 保存桩最后链接到平台的时间
* @param pileSn 桩编号 * @param pileSn 桩编号
*/ */
protected void saveLastTime(String pileSn, Channel channel) { protected void saveLastTimeAndCheckChannel(String pileSn, Channel channel) {
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_1d);

View File

@@ -46,7 +46,7 @@ public class BMSAbortDuringChargingPhaseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class BMSDemandAndChargerOutputHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class BMSInformationHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class BillingTemplateRequestHandler extends AbstractHandler{
// log.info("桩号:{}", pileSn); // log.info("桩号:{}", pileSn);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 根据桩号查询计费模板 // 根据桩号查询计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn); BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);

View File

@@ -36,7 +36,7 @@ public class BillingTemplateResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 设置结果 0x00 失败 0x01 成功 // 设置结果 0x00 失败 0x01 成功
byte[] settingResultByteArr = BytesUtil.copyBytes(msgBody, 7, 1); byte[] settingResultByteArr = BytesUtil.copyBytes(msgBody, 7, 1);

View File

@@ -51,7 +51,7 @@ public class BillingTemplateValidateRequestHandler extends AbstractHandler{
String pileSn = BytesUtil.binary(pileSnByte, 16); String pileSn = BytesUtil.binary(pileSnByte, 16);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 计费模型编码 // 计费模型编码
startIndex += length; startIndex += length;

View File

@@ -76,7 +76,7 @@ public class ChargeEndHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class ChargerAbortedDuringChargingPhaseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class ChargingHandshakeHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -71,7 +71,7 @@ public class ConfirmStartChargingRequestHandler extends AbstractHandler{
String pileSn = BytesUtil.binary(pileSnByteArr, 16); String pileSn = BytesUtil.binary(pileSnByteArr, 16);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -46,7 +46,7 @@ public class ErrorMessageHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -44,7 +44,7 @@ public class HeartbeatRequestHandler extends AbstractHandler {
String pileSn = BytesUtil.binary(pileSnByte, 16); String pileSn = BytesUtil.binary(pileSnByte, 16);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 校验channel // 校验channel
// PileChannelEntity.checkChannel(pileSn, channel); // PileChannelEntity.checkChannel(pileSn, channel);

View File

@@ -124,7 +124,7 @@ public class LoginRequestHandler extends AbstractHandler {
// log.info("桩号:{}", pileSn); // log.info("桩号:{}", pileSn);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 桩类型 0 表示直流桩, 1 表示交流桩 // 桩类型 0 表示直流桩, 1 表示交流桩
startIndex += length; startIndex += length;
@@ -194,10 +194,15 @@ public class LoginRequestHandler extends AbstractHandler {
if (pileInfoVO != null) { if (pileInfoVO != null) {
flag = Constants.zeroByteArray; flag = Constants.zeroByteArray;
// 登录成功保存桩号和channel的关系
// PileChannelEntity.checkChannel(pileSn, channel); CompletableFuture.runAsync(() -> {
// 更改桩和该桩下的枪口状态分别为 在线、空闲 公共方法修改状态 try {
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, null, null, null); // 更改桩和该桩下的枪口状态分别为 在线、空闲 公共方法修改状态
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, null, null, null);
} catch (Exception e) {
e.printStackTrace();
}
});
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
try { try {
@@ -233,12 +238,17 @@ public class LoginRequestHandler extends AbstractHandler {
} }
}); });
} }
} }
// 保存报文 TODO 没有登录认证通过还要不要保存报文? CompletableFuture.runAsync(() -> {
String jsonMsg = JSONObject.toJSONString(loginRequestData); // 保存报文 没有登录认证通过还要不要保存报文?
pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString()); try {
String jsonMsg = JSONObject.toJSONString(loginRequestData);
pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString());
} catch (Exception e) {
log.error("保存报文失败pileSn:{}", pileSn, e);
}
});
// 消息体 // 消息体
byte[] messageBody = Bytes.concat(pileSnByte, flag); byte[] messageBody = Bytes.concat(pileSnByte, flag);

View File

@@ -39,7 +39,7 @@ public class OfflineCardDataCleaningResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 第 1 个卡物理卡号 // 第 1 个卡物理卡号
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class OfflineCardDataQueryResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 第1个卡物理卡号 // 第1个卡物理卡号
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class OfflineCardDataSynchronizationResponseHandler extends AbstractHandl
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 保存结果 0x00 失败 0x01 成功 // 保存结果 0x00 失败 0x01 成功
startIndex += length; startIndex += length;

View File

@@ -54,7 +54,7 @@ public class ParameterConfigurationHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class PileWorkingParameterSettingResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 设置结果 // 设置结果
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class QueryPileWorkParamsHandler extends AbstractHandler{
String pileSn = BytesUtil.binary(pileSnByte, 16); String pileSn = BytesUtil.binary(pileSnByte, 16);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 充电桩类型 0x00:直流0x01:交流 // 充电桩类型 0x00:直流0x01:交流
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class RemoteAccountBalanceUpdateRequestHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class RemoteIssuedQrCodeResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 下发结果 0x00成功 0x01失败 // 下发结果 0x00成功 0x01失败
startIndex += length; startIndex += length;

View File

@@ -45,7 +45,7 @@ public class RemoteRestartResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 保存报文 // 保存报文
String jsonMsg = JSONObject.toJSONString(ykcDataProtocol); String jsonMsg = JSONObject.toJSONString(ykcDataProtocol);

View File

@@ -53,7 +53,7 @@ public class RemoteStartChargingRequestHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -50,7 +50,7 @@ public class RemoteStopChargingRequestHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号 // 枪号
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class RemoteUpdateResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 升级状态 0x00-成功 0x01-编号错误 0x02-程序与桩型号不符 0x03-下载更新文件超时 // 升级状态 0x00-成功 0x01-编号错误 0x02-程序与桩型号不符 0x03-下载更新文件超时
startIndex += length; startIndex += length;

View File

@@ -39,7 +39,7 @@ public class SettingPileWorkParamsHandler extends AbstractHandler{
String pileSn = BytesUtil.binary(pileSnByte, 16); String pileSn = BytesUtil.binary(pileSnByte, 16);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 设置状态 0x00-成功 0x01-失败 // 设置状态 0x00-成功 0x01-失败
startIndex += length; startIndex += length;

View File

@@ -43,7 +43,7 @@ public class TimeCheckSettingResponseHandler extends AbstractHandler{
String pileSn = BytesUtil.bcd2Str(pileSnByteArr); String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 当前时间 // 当前时间
startIndex += length; startIndex += length;

View File

@@ -1,7 +1,6 @@
package com.jsowell.netty.handler; package com.jsowell.netty.handler;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol; import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
@@ -33,7 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -106,7 +104,7 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler {
realTimeMonitorData.setPileSn(pileSn); realTimeMonitorData.setPileSn(pileSn);
// 保存时间 // 保存时间
saveLastTime(pileSn, channel); saveLastTimeAndCheckChannel(pileSn, channel);
// 校验channel // 校验channel
// PileChannelEntity.checkChannel(pileSn, channel); // PileChannelEntity.checkChannel(pileSn, channel);