当前位置:网站首页>新增订单如何防止重复提交
新增订单如何防止重复提交
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;
边栏推荐
- Basic use of MySQL
- The key to the success of digital transformation enterprises is to create value with data
- How to correctly use vertx to operate redis (3.9.4 with source code analysis)
- 利用win7漏洞进行系统登录密码破解
- Opencv video quality detection -- sharpness detection
- Interview questions for audio and video positions in Dachang -- today's headline
- P2433 【深基1-2】小学数学 N 合一
- 采集抖音视频
- ubuntu14安装MySQL并配置root账户本地与远程访问
- CMU AI PhD 第一年总结
猜你喜欢
[Mori city] random talk on GIS data (I)
微信公众号开发相关流程及功能介绍
Les canaux de culture intensive s'efforcent de développer Fu Xin et Wei Shi jiajie pour organiser une conférence de formation sur les nouveaux produits
What is the essential difference between Bi development and report development?
What must be done in graduation season before going to Shanhai
Summary of SQL query de duplication statistics methods
Reading the paper [learning to discretely compose reasoning module networks for video captioning]
The use of subplot function in MATLAB
数字化转型企业成功的关键,用数据创造价值
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
随机推荐
采集抖音视频
使用环信提供的uni-app Demo,快速实现一对一单聊
[go ~ 0 to 1] day 4 June 30 defer, structure, method
Thesis reading [distinctive late semantic graph for video capturing]
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
Case sharing: basic networking configuration of QinQ
nacos启动失败问题解决与总结
Contos 7 搭建sftp之创建用户、用户组以及删除用户
Learning notes [Gumbel softmax]
Redo和Undo的区别
Regular expression =regex=regular expression
【To .NET】C#集合类源码解析
Summary of SQL query de duplication statistics methods
GetMessage底层机制分析
【英语语法】Unit1 冠词、名词、代词和数词
How to solve the problem of splash screen when the main and sub code streams of easygbs are h.265?
brpc理解
Uni app product classification
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
Opencv video quality diagnosis - VIDEO occlusion diagnosis