Commit f3ace699 by 徐康

下单加锁

parent 632ec565
......@@ -175,7 +175,21 @@ public class OrderAdapterServiceImpl implements OrderAdapterService {
if(ObjectUtils.notEqual(baseResponse.getCode(),ResponseResult.SUCCESS.getCode())){
return baseResponse;
}
return mcCafeOrderService.createMCCafeOrder(createOrderVo);
// 添加分布式锁,如果没有取得锁直接返回失败;整个方法执行完毕后会删掉该锁
// 锁定秒数从apollo获取,如果apollo没有设置,默认5秒
String createOrderKey = CREATE_ORDER_KEY + assortmentCustomerInfoVo.getMemberId();
try {
Long expire = Long.valueOf(createOrderKeyExpire);
if(!LockUtils.lock(redisCache.getRedisTemplate(),createOrderKey,expire)){
return ResponseUtil.error(ResponseResult.ORDER_NOT_CREATE_ERROR);
}
return mcCafeOrderService.createMCCafeOrder(createOrderVo);
} catch (Exception e) {
throw e;
} finally {
//LockUtils.unlock(redisCache.getRedisTemplate(),createOrderKey);
}
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment