mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
系统过滤重复的请求
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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