订单打印修改,发送方控制结算单打印

This commit is contained in:
张松 2025-03-17 11:28:11 +08:00
parent 066f70a3dd
commit d8a33f184f
5 changed files with 18 additions and 8 deletions

View File

@ -54,8 +54,16 @@ public class PrintMqListener {
}
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE})
public void orderPrint(String orderId) {
invokeFun("orderPrint", "java.order", orderId, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.ONE_AND_ORDER));
public void orderPrint(String req) {
invokeFun("orderPrint", "java.order", req, (data) -> {
JSONObject jsonObject = JSONObject.parseObject(data);
String orderId = jsonObject.getString("orderId");
if (orderId == null) {
throw new RuntimeException("订单打印失败未传递orderId");
}
Boolean printOrder = jsonObject.getBoolean("printOrder");
printerHandler.handler(data, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ORDER : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
});
}
/**

View File

@ -1,5 +1,6 @@
package com.czg.config;
import com.alibaba.fastjson2.JSONObject;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
@ -45,10 +46,11 @@ public class RabbitPublisher {
/**
* 订单打印消息
* @param orderId 订单id
* @param printOrder 是否打印结算单
*/
public void sendOrderPrintMsg(String orderId) {
public void sendOrderPrintMsg(String orderId, boolean printOrder) {
//厨房票
sendMsg(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, orderId);
sendMsg(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, new JSONObject().fluentPut("orderId", orderId).fluentPut("printOrder", printOrder).toString());
//前台票
sendMsg(RabbitConstants.Queue.ORDER_PRINT_QUEUE, orderId);
}

View File

@ -442,7 +442,7 @@ public abstract class PrinterHandler {
// 判断订单是否是先付费或者已结算
if (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) {
log.warn("此订单未支付或已取消, 订单信息: {}", orderInfo);
return;
// return;
}
if (tbOrderDetailList.isEmpty()) {

View File

@ -231,7 +231,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
);
if ("after-pay".equals(orderInfo.getPayMode())) {
//发送打票信息 后付费推送多次 需要处理
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString());
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString(), false);
} else {
redisService.set(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId(), "", 60 * 15);
}
@ -706,7 +706,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderDetailService.updateChain().set(OrderDetail::getStatus, OrderStatusEnums.DONE.getCode()).eq(OrderDetail::getOrderId, orderInfo.getId()).update();
// if (!"after-pay".equals(orderInfo.getPayMode())) {
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString());
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString(), true);
// }
}

View File

@ -105,7 +105,7 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = orderInfoService.checkOrderPay(checkOrderPay);
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString());
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString(), true);
throw new PaySuccessException();
}
return orderInfo;