mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-16 15:58:41 +08:00
系统过滤重复的请求
This commit is contained in:
@@ -376,7 +376,7 @@ public class RedisCache {
|
|||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param expireTime 过期时间,单位秒
|
* @param expireTime 过期时间,单位秒
|
||||||
* @return
|
* @return true: set成功; false失败表示已有值
|
||||||
*/
|
*/
|
||||||
public Boolean setnx(String key, String value, long expireTime) {
|
public Boolean setnx(String key, String value, long expireTime) {
|
||||||
return redisTemplate.opsForValue().setIfAbsent(key, value, expireTime, TimeUnit.SECONDS);
|
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) {
|
protected boolean verifyTheDuplicateRequest(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
||||||
// 获取序列号域
|
// 获取序列号域
|
||||||
int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
|
int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
|
||||||
// 获取channelId
|
// 获取channelId
|
||||||
String channelId = channel.id().asShortText();
|
String channelId = channel.id().asShortText();
|
||||||
|
|
||||||
String redisKey = "Request_" + channelId + "_" + serialNumber;
|
String redisKey = "Request_" + channelId + "_" + serialNumber;
|
||||||
|
Boolean result = redisCache.setnx(redisKey, ykcDataProtocol.getHEXString(), 30);
|
||||||
|
// result返回false说明没有设置成功,就是说已经有相同请求了,所以返回true重复
|
||||||
return false;
|
return !result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -163,8 +163,9 @@ public class LoginRequestHandler extends AbstractHandler {
|
|||||||
String business = BytesUtil.bcd2Str(businessTypeByteArr);
|
String business = BytesUtil.bcd2Str(businessTypeByteArr);
|
||||||
|
|
||||||
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
||||||
verifyTheDuplicateRequest(ykcDataProtocol, channel);
|
if (verifyTheDuplicateRequest(ykcDataProtocol, channel)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
LoginRequestData loginRequestData = LoginRequestData.builder()
|
LoginRequestData loginRequestData = LoginRequestData.builder()
|
||||||
.pileSn(pileSn)
|
.pileSn(pileSn)
|
||||||
|
|||||||
Reference in New Issue
Block a user