商品模块代码提交
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.czg.account.vo.HandoverCategoryListVo;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
import com.czg.exception.CzgException;
|
||||
@@ -11,6 +12,7 @@ import com.czg.product.service.ProductRpcService;
|
||||
import com.czg.service.order.mapper.OrderDetailMapper;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
@@ -105,6 +107,7 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void paySuccessCallback(Long orderId) {
|
||||
// 下单后商品库存扣减,耗材扣减,流水记录
|
||||
@@ -124,12 +127,44 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
Map<String, Object> data = new HashMap<>(16);
|
||||
Long productId = orderDetail.getProductId();
|
||||
BigDecimal num = orderDetail.getNum();
|
||||
BigDecimal refundNum = orderDetail.getRefundNum();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", productId);
|
||||
data.put("num", num);
|
||||
data.put("num", NumberUtil.sub(num, refundNum));
|
||||
dataList.add(data);
|
||||
}
|
||||
// 调用商品服务扣减库存
|
||||
productRpcService.paySuccessSubtractStock(orderId, dataList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void orderCancelCallback(Long orderId) {
|
||||
// 订单取消后商品库存恢复,耗材恢复,流水记录
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new CzgException("订单不存在");
|
||||
}
|
||||
// 查询订单下商品
|
||||
List<OrderDetail> detailList = orderDetailMapper.selectListByQuery(QueryWrapper.create().eq(OrderDetail::getOrderId, orderId));
|
||||
if (CollUtil.isEmpty(detailList)) {
|
||||
throw new CzgException("该订单下不存在商品");
|
||||
}
|
||||
Long shopId = orderInfo.getShopId();
|
||||
// 封装扣减库存数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (OrderDetail orderDetail : detailList) {
|
||||
Map<String, Object> data = new HashMap<>(16);
|
||||
Long productId = orderDetail.getProductId();
|
||||
BigDecimal num = orderDetail.getNum();
|
||||
BigDecimal refundNum = orderDetail.getRefundNum();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", productId);
|
||||
data.put("num", NumberUtil.sub(num, refundNum));
|
||||
dataList.add(data);
|
||||
}
|
||||
// 调用商品服务恢复库存
|
||||
productRpcService.orderCancelRecoverStock(orderId, dataList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user