商品模块代码提交
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.czg.mq;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.czg.config.RabbitConstants;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.order.service.MqLogService;
|
||||
import com.czg.order.service.OrderInfoRpcService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 订单mq消息处理器
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class OrderMqListener {
|
||||
|
||||
@Resource
|
||||
private OrderInfoRpcService orderInfoRpcService;
|
||||
@Resource
|
||||
private MqLogService mqLogService;
|
||||
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE})
|
||||
public void orderStockSubtract(String orderId) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
log.info("接收到订单支付成功扣减库存消息:{}", orderId);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_STOCK_QUEUE).setMsg(orderId).setType("orderStockSubtract").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
try {
|
||||
orderInfoRpcService.paySuccessCallback(Long.valueOf(orderId));
|
||||
} catch (Exception e) {
|
||||
log.error("订单支付成功扣减库存失败", e);
|
||||
String errorInfo = ExceptionUtil.stacktraceToString(e);
|
||||
mqLog.setErrInfo(errorInfo);
|
||||
mqLog.setDuration(DateUtil.date().getTime() - startTime);
|
||||
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
|
||||
mqLogService.save(mqLog);
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_CANCEL_QUEUE})
|
||||
public void orderStockRecover(String orderId) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
log.info("接收到订单取消恢复库存消息:{}", orderId);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_CANCEL_QUEUE).setMsg(orderId).setType("orderStockRecover").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
try {
|
||||
orderInfoRpcService.orderCancelCallback(Long.valueOf(orderId));
|
||||
} catch (Exception e) {
|
||||
log.error("订单取消恢复库存失败", e);
|
||||
String errorInfo = ExceptionUtil.stacktraceToString(e);
|
||||
mqLog.setErrInfo(errorInfo);
|
||||
mqLog.setDuration(DateUtil.date().getTime() - startTime);
|
||||
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
|
||||
mqLogService.save(mqLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@ package com.czg.mq;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.account.entity.PrintMachine;
|
||||
import com.czg.order.service.MqLogService;
|
||||
import com.czg.account.service.PrintMachineService;
|
||||
import com.czg.config.RabbitConstants;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.MqLogService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.service.order.print.PrinterHandler;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 打印mq消息处理器
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
@@ -44,7 +45,7 @@ public class PrintMqListener {
|
||||
public void orderPrint(String orderId) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
log.info("接收到订单打印消息:{}", orderId);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(orderId).setType("orderPrint").setPlat("java.account").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(orderId).setType("orderPrint").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
try {
|
||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
||||
if (orderInfo == null) {
|
||||
@@ -57,7 +58,7 @@ public class PrintMqListener {
|
||||
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
|
||||
});
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
log.error("订单打印失败", e);
|
||||
mqLog.setErrInfo(JSONObject.toJSONString(e));
|
||||
mqLog.setDuration(DateUtil.date().getTime() - startTime);
|
||||
@@ -68,10 +69,11 @@ public class PrintMqListener {
|
||||
|
||||
/**
|
||||
* 获取可用打印机
|
||||
* @param shopId 店铺id
|
||||
* @param subType 打印类型(分类)label标签 cash小票 kitchen出品
|
||||
*
|
||||
* @param shopId 店铺id
|
||||
* @param subType 打印类型(分类)label标签 cash小票 kitchen出品
|
||||
* @param printMethod 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
|
||||
* @param printType 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
* @param printType 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
||||
* @return 打印机列表
|
||||
*/
|
||||
private List<PrintMachine> getPrintMachine(Long shopId, String subType, String printMethod, String printType) {
|
||||
|
||||
Reference in New Issue
Block a user