master
袁野 6 months ago
parent 1aa0dc90ff
commit a1f3409ad8
  1. 5
      service/src/main/java/com/hfkj/service/goods/GoodsMsgService.java
  2. 8
      service/src/main/java/com/hfkj/service/goods/GoodsSpecsService.java
  3. 10
      service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java
  4. 10
      service/src/main/java/com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java
  5. 1
      service/src/main/java/com/hfkj/service/order/OrderCreateService.java
  6. 5
      service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java

@ -77,11 +77,12 @@ public interface GoodsMsgService {
/**
* 查询订单列表
* 编辑商品库存
* @param goodsId
* @param num
* @param type 1 增加库存 2 减少库存
* @return
*/
void addSaleNum(Long goodsId , Integer num) throws Exception;
void editSaleNum(Long goodsId , Integer num , Integer type) throws Exception;
}

@ -79,11 +79,13 @@ public interface GoodsSpecsService {
/**
* @Author Sum1Dream
* @Name decreaseStockNum
* @Description // 减少库存
* @Description // 编辑库存
* @Date 17:34 2023/4/19
* @Param [skuId, num]
* @Param [skuId]
* @Param [num]
* @Param [type] 1 增加库存 2 减少库存
* @Return void
*/
void decreaseStockNum(Long specsId , Integer num);
void editStockNum(Long specsId , Integer num , Integer type);
}

@ -101,7 +101,7 @@ public class GoodsMsgServiceImpl implements GoodsMsgService {
}
@Override
public void addSaleNum(Long goodsId, Integer num) throws Exception {
public void editSaleNum(Long goodsId, Integer num , Integer type) throws Exception {
String key = "GOODS" + goodsId;
@ -113,12 +113,18 @@ public class GoodsMsgServiceImpl implements GoodsMsgService {
if (goodsMsg != null) {
if(Boolean.TRUE.equals(lock)) {
if (type == 1) {
goodsMsg.setSaleNum(goodsMsg.getSaleNum() + num);
} else if (type == 2){
goodsMsg.setSaleNum(goodsMsg.getSaleNum() - num);
}
update(goodsMsg);
} else {
// 加锁失败,重试
Thread.sleep(100);
addSaleNum(goodsId , num);
editSaleNum(goodsId , num , type);
}

@ -98,7 +98,7 @@ public class GoodsSpecsServiceImpl implements GoodsSpecsService {
}
@Override
public void decreaseStockNum(Long specsId, Integer num) {
public void editStockNum(Long specsId, Integer num , Integer type) {
String key = "GOODS_STOCK_NUM";
GoodsSpecs goodsSpecs = queryDetailByGoodsId(specsId);
@ -108,18 +108,24 @@ public class GoodsSpecsServiceImpl implements GoodsSpecsService {
Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, specsId);
if(Boolean.TRUE.equals(lock)) {
if (type == 1) {
// 加锁成功,处理业务
goodsSpecs.setStock(goodsSpecs.getStock() + num);
} else {
if (goodsSpecs.getStock() < num) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, goodsSpecs.getName() + "库存不足");
}
// 加锁成功,处理业务
goodsSpecs.setStock(goodsSpecs.getStock() - num);
}
update(goodsSpecs);
} else {
// 加锁失败,重试
Thread.sleep(100);
decreaseStockNum(specsId , num);
editStockNum(specsId , num , type);
}
} catch (Exception e) {

@ -218,7 +218,6 @@ public class OrderCreateService {
bsOrderGoodsService.create(orderGoods);
goodsMsgService.addSaleNum(orderGoods.getGoodsId() , orderGoods.getGoodsCount());
jsonObject.put("orderGoodsId", orderGoods.getId());

@ -17,6 +17,7 @@ import com.hfkj.service.coupon.channel.PetroConfig;
import com.hfkj.service.goods.BsOrderGoodsService;
import com.hfkj.service.goods.GoodsMsgService;
import com.hfkj.service.goods.GoodsVpdService;
import com.hfkj.service.goods.impl.GoodsSpecsServiceImpl;
import com.hfkj.service.hlt.HuiLianTongUnionCardService;
import com.hfkj.sysenum.GoodsVpdSourceEnum;
import com.hfkj.sysenum.order.OrderChildProductTypeEnum;
@ -48,6 +49,7 @@ public class OrderPaySuccessService {
private GoodsMsgService goodsMsgService;
@Resource
private GoodsVpdService goodsVpdService;
private GoodsSpecsServiceImpl goodsSpecsService;
/**
* 订单业务处理
@ -186,6 +188,9 @@ public class OrderPaySuccessService {
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "未查询到相关内容");
}
goodsMsgService.editSaleNum(goodsOrder.getGoodsId() , goodsOrder.getGoodsCount() , 1);
goodsOrder.setUpdateTime(new Date());
goodsOrder.setStatus(1);
bsOrderGoodsService.update(goodsOrder);

Loading…
Cancel
Save