mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
使用ChannelHandlerContext
This commit is contained in:
@@ -97,11 +97,11 @@ public abstract class AbstractHandler implements InitializingBean {
|
||||
* 阻止重复帧
|
||||
* @return true 重复
|
||||
*/
|
||||
protected boolean verifyTheDuplicateRequest(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
||||
protected boolean verifyTheDuplicateRequest(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext ctx) {
|
||||
// 获取序列号域
|
||||
int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
|
||||
// 获取channelId
|
||||
String channelId = channel.id().asShortText();
|
||||
String channelId = ctx.channel().id().asShortText();
|
||||
String redisKey = "Request_" + channelId + "_" + serialNumber;
|
||||
Boolean result = redisCache.setnx(redisKey, ykcDataProtocol.getHEXString(), 30);
|
||||
// result返回false说明没有设置成功,就是说已经有相同请求了,所以返回true重复
|
||||
|
||||
@@ -106,7 +106,7 @@ public class LoginRequestHandler extends AbstractHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
|
||||
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext ctx) {
|
||||
// 获取消息体
|
||||
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
||||
|
||||
@@ -118,7 +118,7 @@ public class LoginRequestHandler extends AbstractHandler {
|
||||
String pileSn = BytesUtil.binary(pileSnByte, 16);
|
||||
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(pileSn, channel);
|
||||
saveLastTimeAndCheckChannel(pileSn, ctx);
|
||||
|
||||
// 桩类型 0 表示直流桩, 1 表示交流桩
|
||||
startIndex += length;
|
||||
@@ -164,7 +164,7 @@ public class LoginRequestHandler extends AbstractHandler {
|
||||
String business = BytesUtil.bcd2Str(businessTypeByteArr);
|
||||
|
||||
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
||||
if (verifyTheDuplicateRequest(ykcDataProtocol, channel)) {
|
||||
if (verifyTheDuplicateRequest(ykcDataProtocol, ctx)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user