diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java index ad8aa85..4fd096a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java @@ -47,4 +47,8 @@ public interface RabbitConstants { String EXCHANGE_STOCK_RECORD = "exchange.stock.record"; String ROUTING_STOCK_RECORD_SALE = "routing.stock.record.sale"; + + // 库存记录 + public static final String QUEUE_STOCK_RECORD = "queue.stock.record"; + public static final String ROUTING_STOCK_RECORD= "routing.stock.record"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 187b9ef..89851f7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -71,4 +71,9 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { public void sendStockSaleMsg(T data) { sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, data, "商品售出增加库存记录"); } + + public void sendStockRecordMsg(T data) { + sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD, data, "增加库存记录"); + + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 7c3d5df..584a49d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO; import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect; +import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.DateUtils; @@ -46,6 +47,12 @@ public class ProductService { @Autowired private LimitSubmitAspect limitSubmitAspect; + private final RabbitProducer producer; + + public ProductService(RabbitProducer producer) { + this.producer = producer; + } + public Result queryCategory(String shopId,Integer page,Integer pageSize){ PageHelperUtil.startPage(page, pageSize); @@ -261,6 +268,16 @@ public class ProductService { }else { tbProductMapper.updateStock(productStockDTO.getShopId(), productStockDTO.getProductId(), productStockDTO.getStock()); tbProductSkuMapper.updateStock(productStockDTO.getShopId(), productStockDTO.getProductId(), productStockDTO.getStock()); + + List tbProductSkus = tbProductSkuMapper.selectByProductId(product.getId()); + JSONObject data = new JSONObject(); + data.put("shopId", productStockDTO.getShopId()); + data.put("skuId", tbProductSkus.isEmpty() ? null : tbProductSkus.get(0).getId()); + data.put("productId", productStockDTO.getProductId()); + data.put("type", "pc收银机修改库存"); + data.put("subType", product.getStockNumber() > productStockDTO.getStock() ? -1 : 1); + data.put("number",productStockDTO.getStock() - product.getStockNumber()); + producer.sendStockRecordMsg(data); } } }