dev
袁野 5 months ago
parent 4f1ba3b9bf
commit d49ec20032
  1. 2
      service/src/main/java/com/hfkj/service/goods/GoodsMsgService.java
  2. 13
      service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java

@ -83,6 +83,6 @@ public interface GoodsMsgService {
* @param type 1 增加库存 2 减少库存 * @param type 1 增加库存 2 减少库存
* @return * @return
*/ */
void editSaleNum(Long goodsId , Integer num , Integer type) throws Exception; void editSaleNum(Long goodsId , Integer num , Integer type);
} }

@ -1,5 +1,8 @@
package com.hfkj.service.goods.impl; package com.hfkj.service.goods.impl;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.GoodsMsgMapper; import com.hfkj.dao.GoodsMsgMapper;
import com.hfkj.entity.GoodsBrand; import com.hfkj.entity.GoodsBrand;
import com.hfkj.entity.GoodsMsg; import com.hfkj.entity.GoodsMsg;
@ -101,10 +104,11 @@ public class GoodsMsgServiceImpl implements GoodsMsgService {
} }
@Override @Override
public void editSaleNum(Long goodsId, Integer num , Integer type) throws Exception { public void editSaleNum(Long goodsId, Integer num , Integer type) {
String key = "GOODS" + goodsId; String key = "GOODS" + goodsId;
try {
// 分布式锁占坑 // 分布式锁占坑
Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, goodsId); Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, goodsId);
@ -130,5 +134,12 @@ public class GoodsMsgServiceImpl implements GoodsMsgService {
} }
} catch (Exception e) {
e.printStackTrace();
} finally {
// 删除key,释放锁
redisTemplate.delete(key);
}
} }
} }

Loading…
Cancel
Save