商品模块代码提交
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czg.account.vo.HandoverCategoryListVo;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoRpcService;
|
||||
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 jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单Rpc ServiceImpl
|
||||
@@ -26,6 +38,12 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
@Resource
|
||||
private OrderInfoMapper orderInfoMapper;
|
||||
|
||||
@Resource
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
|
||||
@DubboReference
|
||||
private ProductRpcService productRpcService;
|
||||
|
||||
@Override
|
||||
public BigDecimal getHandoverWechatAmount(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoMapper.getHandoverWechatAmount(shopId, loginTime, handoverTime);
|
||||
@@ -85,4 +103,33 @@ public class OrderInfoRpcServiceImpl implements OrderInfoRpcService {
|
||||
public List<HandoverCategoryListVo> getHandoverCategoryList(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoMapper.getHandoverCategoryList(shopId, loginTime, handoverTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void paySuccessCallback(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();
|
||||
data.put("shopId", shopId);
|
||||
data.put("productId", productId);
|
||||
data.put("num", num);
|
||||
dataList.add(data);
|
||||
}
|
||||
// 调用商品服务扣减库存
|
||||
productRpcService.paySuccessSubtractStock(orderId, dataList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user