系统过滤重复的请求

This commit is contained in:
2023-12-25 15:24:37 +08:00
parent 894eccb186
commit 81e435e4a0
3 changed files with 8 additions and 7 deletions

View File

@@ -376,7 +376,7 @@ public class RedisCache {
* @param key 键
* @param value 值
* @param expireTime 过期时间,单位秒
* @return
* @return true: set成功; false失败表示已有值
*/
public Boolean setnx(String key, String value, long expireTime) {
return redisTemplate.opsForValue().setIfAbsent(key, value, expireTime, TimeUnit.SECONDS);

View File

@@ -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;
}
}

View File

@@ -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)