后付费多余的打印
This commit is contained in:
@@ -1,10 +1,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.config.RabbitConstants;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.entity.MqLog;
|
||||
import com.czg.order.entity.SysPrintData;
|
||||
import com.czg.order.service.MqLogService;
|
||||
@@ -59,19 +61,33 @@ public class PrintMqListener {
|
||||
// 执行核心打印逻辑
|
||||
invokeFun(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, "orderPrint", "java.order", req, (data) -> {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
String orderId = jsonObject.getString("orderId");
|
||||
if (orderId == null) {
|
||||
String orderIdStr = jsonObject.getString("orderId");
|
||||
|
||||
if (StrUtil.isBlank(orderIdStr)) {
|
||||
throw new RuntimeException("订单打印失败,未传递orderId");
|
||||
}
|
||||
|
||||
String[] split = orderIdStr.split("_");
|
||||
if (split.length < 3) {
|
||||
throw new CzgException("订单ID格式不正确:" + orderIdStr);
|
||||
}
|
||||
|
||||
Long orderId = Long.parseLong(split[0]);
|
||||
//付费类型 0后付费/1先付费
|
||||
Integer payType = Integer.parseInt(split[1]);
|
||||
//订单状态 0未完成/1完成
|
||||
Integer orderStatus = Integer.parseInt(split[2]);
|
||||
//该字段表示 网络打印机是否打印订单 本地传参来的
|
||||
Boolean printOrder = jsonObject.getBoolean("printOrder");
|
||||
redisService.runFunAndCheckKey(() -> {
|
||||
if (printOrder) {
|
||||
printConfig.orderHandler(orderId, PrinterHandler.PrintTypeEnum.ORDER, null);
|
||||
}
|
||||
//菜品打印 全是后端
|
||||
printConfig.orderHandler(orderId, PrinterHandler.PrintTypeEnum.ALL_KITCHEN, null);
|
||||
printConfig.orderHandler(orderId, PrinterHandler.PrintTypeEnum.ONLY_KITCHEN, null);
|
||||
if (payType == 1 || orderStatus == 0) {
|
||||
//菜品打印 全是后端
|
||||
printConfig.orderHandler(orderId, PrinterHandler.PrintTypeEnum.ALL_KITCHEN, null);
|
||||
printConfig.orderHandler(orderId, PrinterHandler.PrintTypeEnum.ONLY_KITCHEN, null);
|
||||
}
|
||||
return null;
|
||||
}, RedisCst.getLockKey("orderPrint", orderId));
|
||||
});
|
||||
|
||||
@@ -53,28 +53,26 @@ public class RabbitPublisher {
|
||||
/**
|
||||
* 后付费订单打印消息
|
||||
*
|
||||
* @param orderId 订单id
|
||||
*/
|
||||
public void sendOrderPrintMsg(String orderId, boolean printOrder, String source) {
|
||||
log.info("订单打印消息, orderId: {}, printOrder: {}, source: {}", orderId, printOrder, source);
|
||||
//结算票 预结算单 客看单
|
||||
if (printOrder) {
|
||||
sendMsg(RabbitConstants.Queue.ORDER_PRINT_QUEUE, orderId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 厨房票打印消息
|
||||
*
|
||||
* @param orderId 订单id
|
||||
* @param before 0后付费/1先付费
|
||||
* @param status 订单状态 0未完成/1完成
|
||||
* @param placeNum 第几次下单
|
||||
* @param printOrder 是否打印结算单
|
||||
*/
|
||||
public void sendKitchenOrderPrintMsg(String orderId, boolean printOrder, String source) {
|
||||
log.info("厨房菜品单打印消息, orderId: {}, printOrder: {}, source: {}", orderId, printOrder, source);
|
||||
//厨房票
|
||||
sendMsg(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, new JSONObject().fluentPut("orderId", orderId).fluentPut("printOrder", printOrder).toString());
|
||||
public void sendOrderPrintMsg(Long orderId, Integer before, Integer status, Integer placeNum, boolean printOrder, String source) {
|
||||
log.info("开始发送订单打印消息, orderId: {}, {}, : {}, 第: {}次下单, 通知本地: {}, source: {}",
|
||||
orderId, before==0?"后付":"先付", status==0?"未完成":"完成", placeNum, printOrder, source);
|
||||
log.info("订单打印消息, orderId: {}, printOrder: {}, source: {}", orderId, printOrder, source);
|
||||
String sendOrderId = orderId + "_" + before + "_" + status + "_" + placeNum;
|
||||
//本地打印机 消息通知
|
||||
if (printOrder) {
|
||||
sendMsg(RabbitConstants.Queue.ORDER_PRINT_QUEUE, sendOrderId);
|
||||
}
|
||||
//厨房单 printOrder 表示打不打结算单
|
||||
sendMsg(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, new JSONObject().fluentPut("orderId", sendOrderId).fluentPut("printOrder", printOrder).toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商品信息变动消息
|
||||
*
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PrintConfig implements ApplicationRunner {
|
||||
* @param data 传递的数据
|
||||
* @param printTypeEnum GUEST_ORDER ORDER PRE_ORDER ONLY_KITCHEN ALL_KITCHEN
|
||||
*/
|
||||
public void orderHandler(String data, PrinterHandler.PrintTypeEnum printTypeEnum, Integer placeNum) {
|
||||
public void orderHandler(Long data, PrinterHandler.PrintTypeEnum printTypeEnum, Integer placeNum) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(data);
|
||||
if (orderInfo == null) {
|
||||
throw new RuntimeException("订单打印失败,订单不存在");
|
||||
@@ -114,7 +114,6 @@ public class PrintConfig implements ApplicationRunner {
|
||||
orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
|
||||
default -> orderDetailList;
|
||||
};
|
||||
redisService.set("order:print:" + orderInfo.getId(), "", 180);
|
||||
for (PrintMachine machine : getPrintMachine(orderInfo.getShopId(), printTypeEnum)) {
|
||||
PrinterHandler printer = getPrinter(machine.getBrand());
|
||||
switch (printTypeEnum) {
|
||||
@@ -125,7 +124,6 @@ public class PrintConfig implements ApplicationRunner {
|
||||
case PrinterHandler.PrintTypeEnum.ORDER:
|
||||
log.info("准备开始打印订单");
|
||||
printer.orderPrintBefore(machine, orderInfo, orderDetailList);
|
||||
|
||||
break;
|
||||
case PrinterHandler.PrintTypeEnum.PRE_ORDER:
|
||||
log.info("准备开始打印预结算订单");
|
||||
|
||||
@@ -692,7 +692,7 @@ public interface PrinterImpl {
|
||||
String actualStr = pro.getActualAmount().stripTrailingZeros().toPlainString();
|
||||
String salesStr = pro.getSalesAmount().stripTrailingZeros().toPlainString();
|
||||
// 商品名称前加2个空格,实现缩进效果
|
||||
String productLine = key4(" " + pro.getProductName(), numStr, actualStr, salesStr, 12, 6, 6);
|
||||
String productLine = key4(" " + pro.getProductName(), numStr, actualStr, salesStr, 12, 8, 8);
|
||||
builder.append(getFormatLabel(productLine, signLabelInfo.s)).append(signLabelInfo.br);
|
||||
}
|
||||
}
|
||||
@@ -732,7 +732,7 @@ public interface PrinterImpl {
|
||||
builder.append(getFormatLabel(leftRightAlign("充值后余额:", record.getBalance().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
|
||||
builder.append(getDividingLine()).append(signLabelInfo.br);
|
||||
// 支付信息
|
||||
builder.append(getFormatLabel(leftRightAlign("已付金额:", record.getRechargeAmount().stripTrailingZeros().toPlainString(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
||||
builder.append(getFormatLabel(leftRightAlign("已付金额:", record.getRechargeAmount().stripTrailingZeros().toPlainString(), 24), signLabelInfo.bold)).append(signLabelInfo.br);
|
||||
builder.append(getFormatLabel(leftRightAlign("支付方式:", record.getPayType(), 32), signLabelInfo.s)).append(signLabelInfo.br);
|
||||
builder.append(getDividingLine()).append(signLabelInfo.br);
|
||||
builder.append(getFormatLabel(StrUtil.format("操作员: {}", StrUtil.isNotBlank(record.getOperator()) ? record.getOperator() : ""), signLabelInfo.s)).append(signLabelInfo.br);
|
||||
|
||||
@@ -332,13 +332,9 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
//
|
||||
log.info("后付费生成订单{},第{}", orderInfo.getId(), orderInfo.getPlaceNum());
|
||||
//客看单
|
||||
printConfig.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.GUEST_ORDER, orderInfo.getPlaceNum());
|
||||
//orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成_第几次下单
|
||||
//orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0"
|
||||
//后付费 菜品单
|
||||
rabbitPublisher.sendKitchenOrderPrintMsg(orderInfo.getId() + "_0_0", false, "后付费打印");
|
||||
printConfig.orderHandler(orderInfo.getId(), PrinterHandler.PrintTypeEnum.GUEST_ORDER, orderInfo.getPlaceNum());
|
||||
// 消息通知 本地打印机执行
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId() + "_0_0_" + orderInfo.getPlaceNum(), true, "后付费打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), 0, 0, orderInfo.getPlaceNum(), true, "后付费打印");
|
||||
} else {
|
||||
redisService.set(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId(), "", 60 * 15);
|
||||
}
|
||||
@@ -1300,19 +1296,15 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
}
|
||||
if (payType != PayEnums.BACK_SCAN) {
|
||||
// 事务成功提交后执行消息发送
|
||||
String printParam = orderId + "_" + (!"after-pay".equals(payMode) ? 1 : 0) + "_1";
|
||||
rabbitPublisher.sendKitchenOrderPrintMsg(printParam, isPrint, "事务环境打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(printParam, isPrint, "事务环境打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, isPrint, "事务环境打印");
|
||||
}
|
||||
// log.info("订单{}事务提交后,发送打印消息", orderId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (payType != PayEnums.BACK_SCAN) {
|
||||
// 非事务环境下直接发送(兼容无事务场景)
|
||||
String printParam = orderId + "_" + (!"after-pay".equals(payMode) ? 1 : 0) + "_1";
|
||||
rabbitPublisher.sendOrderPrintMsg(printParam, isPrint, "非事务环境打印");
|
||||
rabbitPublisher.sendKitchenOrderPrintMsg(printParam, isPrint, "非事务环境打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, isPrint, "非事务环境打印");
|
||||
|
||||
}
|
||||
// log.info("非事务环境下,直接发送订单{}打印消息", orderId);
|
||||
}
|
||||
@@ -1618,10 +1610,10 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
|
||||
switch (orderInfoPrintDTO.getType()) {
|
||||
case 1://预结算单
|
||||
printConfig.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.PRE_ORDER, null);
|
||||
printConfig.orderHandler(orderInfo.getId(), PrinterHandler.PrintTypeEnum.PRE_ORDER, null);
|
||||
break;
|
||||
case 2://结算单
|
||||
printConfig.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ORDER, null);
|
||||
printConfig.orderHandler(orderInfo.getId(), PrinterHandler.PrintTypeEnum.ORDER, null);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -114,12 +114,7 @@ public class OrderPayServiceImpl implements OrderPayService {
|
||||
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay);
|
||||
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
|
||||
//发送打票信息
|
||||
//orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成
|
||||
//orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0"
|
||||
rabbitPublisher.sendKitchenOrderPrintMsg(orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1",
|
||||
orderInfo.getIsPrint() == 1, "0元付款");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1",
|
||||
orderInfo.getIsPrint() == 1, "0元付款");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, orderInfo.getIsPrint() == 1, "0元付款");
|
||||
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
|
||||
throw new PaySuccessException("支付成功");
|
||||
}
|
||||
@@ -360,10 +355,7 @@ public class OrderPayServiceImpl implements OrderPayService {
|
||||
if (mapCzgResult.getCode() == 200) {
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN);
|
||||
// 事务成功提交后执行消息发送
|
||||
String printParam = orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1";
|
||||
rabbitPublisher.sendKitchenOrderPrintMsg(printParam, orderInfo.getIsPrint() == 1, "事务环境打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(printParam, orderInfo.getIsPrint() == 1, "事务环境打印");
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, orderInfo.getIsPrint() == 1, "扫码收款");
|
||||
} else {
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
|
||||
Reference in New Issue
Block a user