系统过滤重复的请求

This commit is contained in:
2023-12-25 15:12:34 +08:00
parent 471f84af10
commit 894eccb186
3 changed files with 47 additions and 26 deletions

View File

@@ -74,4 +74,19 @@ public abstract class AbstractHandler implements InitializingBean {
PileChannelEntity.checkChannel(pileSn, channel);
}
/**
* 阻止重复帧
*/
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;
}
}

View File

@@ -7,7 +7,6 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.LoginRequestData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
@@ -30,6 +29,7 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
@Component
public class LoginRequestHandler extends AbstractHandler {
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.LOGIN_CODE.getBytes());
@Autowired
private IPileBasicInfoService pileBasicInfoService;
@@ -40,11 +40,6 @@ public class LoginRequestHandler extends AbstractHandler {
@Autowired
private IPileMsgRecordService pileMsgRecordService;
@Autowired
private RedisCache redisCache;
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.LOGIN_CODE.getBytes());
private List<String> newProgramVersionList = Lists.newArrayList("c6-30");
@Override
@@ -111,7 +106,6 @@ public class LoginRequestHandler extends AbstractHandler {
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
// log.info("[===执行登录逻辑===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString());
// 获取消息体
byte[] msgBody = ykcDataProtocol.getMsgBody();
@@ -121,7 +115,6 @@ public class LoginRequestHandler extends AbstractHandler {
// 桩编码
byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileSn = BytesUtil.binary(pileSnByte, 16);
// log.info("桩号:{}", pileSn);
// 保存时间
saveLastTimeAndCheckChannel(pileSn, channel);
@@ -140,7 +133,6 @@ public class LoginRequestHandler extends AbstractHandler {
// 通信协议版本 版本号乘 10v1.0 表示 0x0A
startIndex += length;
byte[] communicationVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// int i = Integer.parseInt(BytesUtil.bcd2Str(communicationVersionByteArr)); // 0F --> 15
BigDecimal bigDecimal = new BigDecimal(BytesUtil.bcd2Str(communicationVersionByteArr));
BigDecimal communicationVersionTemp = bigDecimal.divide(new BigDecimal(10));
String communicationVersion = "v" + communicationVersionTemp;
@@ -170,6 +162,10 @@ public class LoginRequestHandler extends AbstractHandler {
byte[] businessTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String business = BytesUtil.bcd2Str(businessTypeByteArr);
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
verifyTheDuplicateRequest(ykcDataProtocol, channel);
LoginRequestData loginRequestData = LoginRequestData.builder()
.pileSn(pileSn)
.pileType(pileType)