mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
系统过滤重复的请求
This commit is contained in:
@@ -76,17 +76,17 @@ public abstract class AbstractHandler implements InitializingBean {
|
||||
|
||||
/**
|
||||
* 阻止重复帧
|
||||
* @return true 重复
|
||||
*/
|
||||
protected boolean verifyTheDuplicateRequest(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
||||
// 获取序列号域
|
||||
int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
|
||||
// 获取channelId
|
||||
String channelId = channel.id().asShortText();
|
||||
|
||||
String redisKey = "Request_" + channelId + "_" + serialNumber;
|
||||
|
||||
|
||||
return false;
|
||||
Boolean result = redisCache.setnx(redisKey, ykcDataProtocol.getHEXString(), 30);
|
||||
// result返回false说明没有设置成功,就是说已经有相同请求了,所以返回true重复
|
||||
return !result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,8 +163,9 @@ public class LoginRequestHandler extends AbstractHandler {
|
||||
String business = BytesUtil.bcd2Str(businessTypeByteArr);
|
||||
|
||||
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
||||
verifyTheDuplicateRequest(ykcDataProtocol, channel);
|
||||
|
||||
if (verifyTheDuplicateRequest(ykcDataProtocol, channel)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LoginRequestData loginRequestData = LoginRequestData.builder()
|
||||
.pileSn(pileSn)
|
||||
|
||||
Reference in New Issue
Block a user