1.增加库存记录mq处理
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package cn.ysk.cashier.rabbit;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.ysk.cashier.config.RabbitConfig;
|
||||
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
|
||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||
import cn.ysk.cashier.service.TbProductStockOperateService;
|
||||
import cn.ysk.cashier.service.product.TbProductStockDetailService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -15,8 +18,11 @@ public class StockListener {
|
||||
|
||||
private final TbProductStockDetailService productStockDetailService;
|
||||
|
||||
public StockListener(TbProductStockDetailService productStockDetailService) {
|
||||
private final TbProductStockOperateService productStockOperateService;
|
||||
|
||||
public StockListener(TbProductStockDetailService productStockDetailService, TbProductStockOperateService productStockOperateService) {
|
||||
this.productStockDetailService = productStockDetailService;
|
||||
this.productStockOperateService = productStockOperateService;
|
||||
}
|
||||
|
||||
@RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD_SALE)
|
||||
@@ -33,4 +39,22 @@ public class StockListener {
|
||||
log.error("执行保存库存mq失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
// @RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD_SALE)
|
||||
public void recordStockHandler(String message) {
|
||||
log.info("接收到下单保存库存信息mq消息,消息内容: {}", message);
|
||||
|
||||
if (StrUtil.isBlank(message)) {
|
||||
log.warn("错误消息体");
|
||||
return;
|
||||
}
|
||||
|
||||
StockRecordMsg stockRecordMsg = JSONObject.parseObject(message, StockRecordMsg.class);
|
||||
|
||||
try {
|
||||
productStockOperateService.addStockRecord(stockRecordMsg);
|
||||
}catch (Exception e) {
|
||||
log.error("执行保存库存mq失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user