1.库存新增上下架接口
2.库存记录返回orderNo 3.增加保存库存记录mq处理
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package cn.ysk.cashier.rabbit;
|
||||
|
||||
import cn.ysk.cashier.config.RabbitConfig;
|
||||
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
|
||||
import cn.ysk.cashier.service.product.TbProductStockDetailService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StockListener {
|
||||
|
||||
private final TbProductStockDetailService productStockDetailService;
|
||||
|
||||
public StockListener(TbProductStockDetailService productStockDetailService) {
|
||||
this.productStockDetailService = productStockDetailService;
|
||||
}
|
||||
|
||||
@RabbitListener(queues = RabbitConfig.QUEUE_STOCK_RECORD_SALE)
|
||||
public void recordSaleHandler(String message) {
|
||||
log.info("接收到下单保存库存信息mq消息,消息内容: {}", message);
|
||||
JSONObject jsonObject = JSONObject.parseObject(message);
|
||||
if (!jsonObject.containsKey("orderId")) {
|
||||
log.info("mq消息体有误,确实orderId");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
productStockDetailService.addSaleRecord(jsonObject.getInteger("orderId"));
|
||||
}catch (Exception e) {
|
||||
log.error("执行保存库存mq失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user