商品模块代码提交

This commit is contained in:
Tankaikai
2025-03-04 09:33:02 +08:00
parent 6e2e73fdcd
commit 23f4e36bda
8 changed files with 190 additions and 10 deletions

View File

@@ -163,4 +163,60 @@ public class ProductRpcServiceImpl implements ProductRpcService {
}
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}
@Override
public void orderRefundReturnStock(List<Map<String, Object>> dataList) {
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
if (CollUtil.isEmpty(list)) {
return;
}
Long shopId = null;
for (ProductStockSubtractDTO dto : list) {
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
// 查询商品绑定耗材信息
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
if (CollUtil.isEmpty(relationList)) {
continue;
}
for (ProdConsRelation prodConsRelation : relationList) {
// 耗材id
Long consInfoId = prodConsRelation.getConsInfoId();
// 耗材消耗数量
BigDecimal surplusStock = prodConsRelation.getSurplusStock();
if (surplusStock == null) {
continue;
}
// 实际消耗数量 = 耗材消耗数量 * 商品购买数量
surplusStock = NumberUtil.mul(surplusStock, dto.getNum());
ConsInfo consInfo = consInfoMapper.selectOneById(consInfoId);
if (consInfo == null) {
continue;
}
BigDecimal stockNumber = consInfo.getStockNumber();
consInfo.setStockNumber(NumberUtil.add(stockNumber, surplusStock));
// 更新耗材库存数量
consInfoMapper.update(consInfo);
// 插入耗材流水记录
ConsStockFlow consStockFlow = new ConsStockFlow();
consStockFlow.setShopId(consInfo.getShopId());
consStockFlow.setInOutType(InOutTypeEnum.IN.value());
consStockFlow.setInOutItem(InOutItemEnum.ORDER_IN.value());
consStockFlow.setInOutDate(LocalDate.now());
consStockFlow.setConId(consInfo.getId());
consStockFlow.setConName(consInfo.getConName());
consStockFlow.setUnitName(consInfo.getConUnit());
consStockFlow.setBeforeNumber(stockNumber);
consStockFlow.setInOutNumber(surplusStock);
consStockFlow.setAfterNumber(consInfo.getStockNumber());
consStockFlow.setSubTotal(NumberUtil.mul(surplusStock, consInfo.getPrice()));
consStockFlow.setProductId(dto.getProductId());
// consStockFlow.setSkuId(0L);
// TODO 需要订单id
// consStockFlow.setOrderId(orderId);
shopId = consInfo.getShopId();
consStockFlowMapper.insert(consStockFlow);
}
}
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}
}