Browse Source

[库存][修改]

release_toaliyun_real
Stormeye Wu 6 years ago
parent
commit
86e016f398
2 changed files with 8 additions and 6 deletions
  1. +8
    -5
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java
  2. +0
    -1
      mallinkService/src/main/java/com/iformall/utils/RedisLock.java

+ 8
- 5
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java View File

@@ -487,12 +487,17 @@ public class WxOrderServiceImpl implements WxOrderService {


try { try {
// 减库存 // 减库存
wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory());
int num = wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory());
if (num <= 0) {
logger.error("此券减库存失败, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
// 解锁
redisLock.unlock(couponIdStr, timeStr);
logger.error("此券减库存失败, couponId: " + couponIdStr); logger.error("此券减库存失败, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
} finally {
// 解锁
redisLock.unlock(couponIdStr, timeStr);
} }
} }


@@ -527,8 +532,6 @@ public class WxOrderServiceImpl implements WxOrderService {
try { try {
int num = wxCouponMapper.backInventory(coupon.getId(), 1, coupon.getRemainInventory()); int num = wxCouponMapper.backInventory(coupon.getId(), 1, coupon.getRemainInventory());
if (num <= 0) { if (num <= 0) {
// 解锁
redisLock.unlock(couponIdStr, timeStr);
logger.error("此券加库存失败, couponId: " + couponIdStr); logger.error("此券加库存失败, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
} }


+ 0
- 1
mallinkService/src/main/java/com/iformall/utils/RedisLock.java View File

@@ -34,7 +34,6 @@ public class RedisLock {
public boolean lock(String key,String value){ public boolean lock(String key,String value){
ValueOperations<String, String> operations = stringRedisTemplate.opsForValue(); ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
if(operations.setIfAbsent(key,value)){//对应setnx命令 if(operations.setIfAbsent(key,value)){//对应setnx命令
operations.set(key, value, 1, TimeUnit.SECONDS);
//可以成功设置,也就是key不存在 //可以成功设置,也就是key不存在
return true; return true;
} }


Loading…
Cancel
Save