96SEO 2026-02-19 11:26 17
。

添加用户锁#xff0c;在用户第二次点击按钮时#xff0c;拦击用…用户锁的作用
秒杀、支付等场景用户频繁点击按钮会造成同一时刻调用多次接口【第一次请求接口还没响应数据用户又进行了第二次请求】造成数据异常和网络拥堵。
添加用户锁在用户第二次点击按钮时拦击用户请求。
限制用户在操作未完成前不能再进行下一次相同操作
RedisDistributedUserLock分布式锁实现类
DistributedUserLockAspect切面类【核心】
自定义锁注解利用切面给所有加注解的方法加分布式锁防止用户重复点击按钮。
DistributedUserLockAspect用redis的setIfAbsent
Around(annotation(com.nascent.ecrp.mall.common.distribute.Dul))public
distributedLock(ProceedingJoinPoint
proceedingJoinPoint.proceed();}String
proceedingJoinPoint.proceed();}MethodSignature
proceedingJoinPoint.getSignature();Method
methodSignature.getMethod();String
method.getDeclaringClass().getName()
method.getAnnotation(Dul.class);int
distributedKey.lockTimeSeconds();TimeUnit
USER_LOCK_KEY_OF_类名方法名token作为redis的keylockKey
(distributedUserLock.lock(lockKey,
proceedingJoinPoint.proceed();}
WmDefinitelyRuntimeException(操作过于频繁请稍后再试);}}
{Thread.currentThread().interrupt();throw
WmDefinitelyRuntimeException(e);}
{distributedUserLock.unlock(lockKey);}}3.全部代码
Retention(RetentionPolicy.RUNTIME)
SuppressWarnings({UnusedReturnValue,
UnsupportedOperationException();}Overridepublic
InterruptedException();}Overridepublic
UnsupportedOperationException();}/***
InterruptedException*/Overridepublic
redisTemplate.opsForValue().get(lockKey);if
false;}redisTemplate.opsForValue().set(lockKey,
加锁如果key不存在进行加锁如果key已经存在返回加锁失败return
redisTemplate.opsForValue().setIfAbsent(lockKey,
UnsupportedOperationException();}/***
{redisTemplate.delete(lockKey);}Overridepublic
UnsupportedOperationException();}SuppressWarnings(NullableProblems)Overridepublic
UnsupportedOperationException();}}DistributedUserLockAspect
distributedUserLock;Autowiredprivate
proceedingJoinPoint*/Around(annotation(com.nascent.ecrp.mall.common.distribute.Dul))public
distributedLock(ProceedingJoinPoint
proceedingJoinPoint.proceed();}String
proceedingJoinPoint.proceed();}MethodSignature
proceedingJoinPoint.getSignature();Method
methodSignature.getMethod();String
method.getDeclaringClass().getName()
method.getAnnotation(Dul.class);int
distributedKey.lockTimeSeconds();TimeUnit
USER_LOCK_KEY_OF_类名方法名token作为redis的keylockKey
(distributedUserLock.lock(lockKey,
proceedingJoinPoint.proceed();}
WmDefinitelyRuntimeException(操作过于频繁请稍后再试);}}
{Thread.currentThread().interrupt();throw
WmDefinitelyRuntimeException(e);}
{distributedUserLock.unlock(lockKey);}}
秒杀活动开始用户点击按钮进行上锁lockTimeSeconds【默认10秒】内不能再点击lockTimeSeconds秒后自动释放锁。
doSeckill(WmMarketingSeckillPostVo
checkGoodsSeckillInfo(seckillPostVo.getSeckillOrderInfoList(),seckillPostVo.getShopId());if(checkResult.equals(ErrorCode.SECKILL_ACTIVITY_UPDATE.getCode())){return
CommonResult().setFailed().setCode(ErrorCode.SECKILL_ACTIVITY_UPDATE.getCode()).setMsg(活动状态已变更请重新下单);}ListJSONObject
ArrayList();//下单校验ListSecKillBuyInfo
ArrayList();SeckillOrderCheckRequest
SeckillOrderCheckRequest();seckillOrderCheckRequest.setCustomerId(getCustomerId());seckillOrderCheckRequest.setShopId(seckillPostVo.getShopId());for(WmMarketingSeckillPostVo.SeckillOrderInfo
seckillPostVo.getSeckillOrderInfoList()){SecKillBuyInfo
SecKillBuyInfo();secKillBuyInfo.setActivityId(seckillOrderInfo.getMarketingGuid());ListSeckillBuyGoodsInfo
ArrayList();SeckillBuyGoodsInfo
SeckillBuyGoodsInfo();seckillBuyGoodsInfo.setGoodsId(seckillOrderInfo.getGoodsId());seckillBuyGoodsInfo.setGoodsLibId(seckillOrderInfo.getGoodsLibId());ListSeckillBuySkuInfo
SeckillBuySkuInfo();seckillBuySkuInfo.setGoodsSkuId(StringUtil.isBlank(seckillOrderInfo.getGoodsSkuId())
seckillOrderInfo.getGoodsSkuId());seckillBuySkuInfo.setBuyCount(seckillOrderInfo.getGoodsNum());seckillBuySkuInfos.add(seckillBuySkuInfo);seckillBuyGoodsInfo.setSkuInfos(seckillBuySkuInfos);seckillBuyGoodsInfos.add(seckillBuyGoodsInfo);secKillBuyInfo.setGoodsList(seckillBuyGoodsInfos);buyInfos.add(secKillBuyInfo);}seckillOrderCheckRequest.setBuyInfos(buyInfos);seckillOrderCheckRequest.setGroupId(getGroupId());SeckillOrderCheckResponse
OpenPlatformClient.exec(getGroupId(),
seckillOrderCheckRequest);log.info(【调用中台下单校验接口响应结果】seckillOrderCheckResponseJSON.toJSONString(seckillOrderCheckResponse));if(!seckillOrderCheckResponse.successseckillOrderCheckResponse.getCode().equals(50402)){log.info(【秒杀下单已达限购上限】);return
CommonResult().setFailed().setCode(50402).setMsg(已达限购上限);}if(!seckillOrderCheckResponse.successseckillOrderCheckResponse.getCode().equals(50404)){log.info(【秒杀剩余库存不足】);return
CommonResult().setFailed().setCode(50404).setMsg(剩余库存不足);}if(!seckillOrderCheckResponse.successseckillOrderCheckResponse.getCode().equals(50005)){log.info(【秒杀活动已结束】);return
CommonResult().setFailed().setCode(50005).setMsg(活动已结束);}AssertUtil.assertTrue(seckillOrderCheckResponse.getSuccess()seckillOrderCheckResponse.getResult().isSeckillSuccess(),秒杀活动校验失败);MapString,ActivitySeckillCheckInfo
HashMap();for(ActivitySeckillCheckInfo
seckillOrderCheckResponse.getResult().getCheckInfos()){Long
activitySeckillCheckInfo.getItemInfos().get(0).getGoodsId();Long
activitySeckillCheckInfo.getItemInfos().get(0).getGoodsLibId();String
activitySeckillCheckInfo.getItemInfos().get(0).getSkuInfos().get(0).getSkuId();//无sku也会返回到sku级skuid为0activityCheckInfoMap.put(activitySeckillCheckInfo.getActivityId()_goodsLibId_goodsId_skuId,activitySeckillCheckInfo);}MapString,
getGoodsInfos(seckillPostVo.getShopId(),seckillPostVo.getSeckillOrderInfoList());Integer
seckillOrderCheckResponse.getResult().getExpireMinute();for(WmMarketingSeckillPostVo.SeckillOrderInfo
:seckillPostVo.getSeckillOrderInfoList()){ItemDetailsInfo
itemInfoMap.get(seckillOrderInfo.getGoodsId()_seckillOrderInfo.getGoodsLibId());Long
seckillOrderInfo.getMarketingGuid();Long
seckillOrderInfo.getGoodsId();Long
seckillOrderInfo.getGoodsLibId();String
seckillOrderInfo.getGoodsSkuId()null?0:seckillOrderInfo.getGoodsSkuId();//无sku也会返回到sku级skuid为0ActivitySeckillCheckInfo
activityCheckInfoMap.get(marketGuid_goodsLibId_goodsId_goodsSkuId);String
activitySeckillCheckInfo.getActivityName();//秒杀价BigDecimal
itemInfo.getPrice();for(ActivitySeckillCheckItemInfo
activitySeckillCheckInfo.getItemInfos()){if(activitySeckillCheckItemInfo.getGoodsId().longValue()
seckillOrderInfo.getGoodsId().longValue()
activitySeckillCheckItemInfo.getGoodsLibId().longValue()
seckillOrderInfo.getGoodsLibId().longValue()){for(ActivitySeckillCheckSkuInfo
activitySeckillCheckItemInfo.getSkuInfos()){if(seckillCheckSkuInfo.getSkuId().equals(0)||seckillCheckSkuInfo.getSkuId().equals(seckillOrderInfo.getGoodsSkuId())){price
seckillCheckSkuInfo.getPrice();}}}}JSONObject
createOrderDetail(marketGuid,activityName,expireMinute,seckillOrderInfo.getGoodsNum(),
itemInfo);seckillOrderList.add(orderJson);}return
CommonResult(seckillOrderList);}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback