当前位置:网站首页>新增订单如何防止重复提交
新增订单如何防止重复提交
2022-07-01 18:45:00 【墨着染霜华】
上篇文章写了幂等性防抖防止重复提交,可以有效阻止连续不停的点击提交,但是现在出现了一个情况,因为网络慢或者后台服务器慢导致提交的数据处理返回超时,等了大概1分钟甚至几分钟之后的提交,幂等性防抖就不起作用,订单生成多次。
为了解决这个问题,我在进入订单页面就请求了一个UUID,除非是重新进入该页面UUID不会变动,然后提交时候带着这个UUID去请求,如果REIDS中该UUID存在那么判断重复请求,不存在那么后台接受到了将UUID存入REDIS中,如果处理失败那么还是要移除这个KEY。
参考代码如下:
String key= MessageFormat.format("INSERT:HYKCZD:{0}:{1}",vo.getTenantId(),vo.getDjbh());
if(redisService.haskey(key)) throw new BusinessException("本页面请求已处理,请勿重复提交");
redisService.setCacheObject(key,vo.getZdr()+"-"+getDateTime(),7, TimeUnit.DAYS);
PosVipCzsz czsz=czszMapper.selectById(vo.getCzszId());
if(czsz.getType()==0){
vo.setJe1(czsz.getJe2());
vo.setJe2(czsz.getJe());
vo.setJe3(czsz.getJe1());
}else{
validObjectParam(vo, VpczdVO.class, "je2","je3");
Double je1=add(vo.getJe2(), vo.getJe3());
vo.setJe1(je1);
}
String host=getHost(),url="pos/vpczd/cz",json= JSON.toJSONString(vo);
JsonResult jsonResult= doGetJsonResult$post(host, url, json);
if(!jsonResult.isSuccess()) {
redisService.deleteObject(key);
throw new DataIntefaceException(jsonResult.getMsg());
}
return 1;
边栏推荐
- Enabling "new Chinese enterprises", SAP process automation landing in China
- Go Language Advanced
- 科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
- Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
- GB28181的NAT穿透
- Salesmartly has some tricks for Facebook chat!
- 703. 数据流中的第 K 大元素
- 使用环信提供的uni-app Demo,快速实现一对一单聊
- Transaction isolation level gap lock deadlock
- 论文阅读【Discriminative Latent Semantic Graph for Video Captioning】
猜你喜欢
sql查询去重统计的方法总结
GB28181之SIP协议
Dom4j parsing XML, XPath retrieving XML
【AI服务器搭建】CUDA环境
【To .NET】C#集合类源码解析
Solution and summary of Nacos startup failure
Shell advanced
nacos启动失败问题解决与总结
ddr4测试-2
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
随机推荐
The use of subplot function in MATLAB
Facebook聊单,SaleSmartly有妙招!
Thesis reading [distinctive late semantic graph for video capturing]
118. 杨辉三角
JDBC中如何添加事务
[info() method in org.slf4j.logger]
torch. nn. functional. Interpolate function
Collect Tiktok video
Methods of finding various limits
The intelligent epidemic prevention system provides safety guarantee for the resumption of work and production at the construction site
118. Yanghui triangle
新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
Botu V16 obtains the system time and converts it into a string
大厂音视频职位面试题目--今日头条
Live HLS protocol
Detailed explanation of JUnit unit test framework
为什么一定要从DevOps走向BizDevOps?
Reading the paper [learning to discretely compose reasoning module networks for video captioning]
【org.slf4j.Logger中info()方法】