This commit is contained in:
2026-04-02 16:57:12 +08:00
parent 384557e914
commit fbbc6b8d30
8 changed files with 607 additions and 421 deletions

View File

@@ -59,7 +59,7 @@ public class PrintMqListener {
} }
Boolean printOrder = jsonObject.getBoolean("printOrder"); Boolean printOrder = jsonObject.getBoolean("printOrder");
redisService.runFunAndCheckKey(() -> { redisService.runFunAndCheckKey(() -> {
printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER); printerHandler.orderHandler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER, null);
return null; return null;
}, RedisCst.getLockKey("orderPrint", orderId)); }, RedisCst.getLockKey("orderPrint", orderId));
}); });
@@ -71,7 +71,7 @@ public class PrintMqListener {
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE}) @RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE})
public void handoverPrint(String id) { public void handoverPrint(String id) {
invokeFun(RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE, "handoverPrint", "java.order", id, (data) -> invokeFun(RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE, "handoverPrint", "java.order", id, (data) ->
printerHandler.handler(data, PrinterHandler.PrintTypeEnum.HANDOVER)); printerHandler.handoverHandler(data));
} }
/** /**
@@ -80,6 +80,6 @@ public class PrintMqListener {
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.CALL_TABLE_QUEUE}) @RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.CALL_TABLE_QUEUE})
public void callTablePrint(String id) { public void callTablePrint(String id) {
invokeFun(RabbitConstants.Queue.CALL_TABLE_QUEUE, "callTable", "java.order", id, (data) -> invokeFun(RabbitConstants.Queue.CALL_TABLE_QUEUE, "callTable", "java.order", id, (data) ->
printerHandler.handler(data, PrinterHandler.PrintTypeEnum.CALL)); printerHandler.callHandler(data));
} }
} }

View File

@@ -20,7 +20,11 @@ public class OrderInfoPrintDTO implements Serializable {
@NotNull(message = "id不为空") @NotNull(message = "id不为空")
private Long id; private Long id;
/** /**
* 0结算单 1退款单 * 0 菜品和结算单同时打印
* 1 预结算单
* 2 结算单
* 3 退菜/退款
* 4 交班
*/ */
@NotNull(message = "打印类型不为空") @NotNull(message = "打印类型不为空")
private Integer type; private Integer type;

View File

@@ -66,94 +66,60 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
} }
@Override @Override
protected void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { protected void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
String remark = orderDetail.getRemark(); String buildDishPrintData = buildDishPrintData(false, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(),
String content = buildDishPrintData(false, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent());
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), remark, orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
String o = sendPrintRequest(machine.getAddress(), content, null, "1"); if (1 == machine.getVolumeSwitch()) {
printMachineLogService.save(orderInfo.getId(), machine, "新订单", content, o); voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
} }
String resp = sendPrintRequest(machine.getAddress(), buildDishPrintData, voiceJson, "1");
printMachineLogService.save(orderInfo.getId(), machine, "新订单", buildDishPrintData, resp);
@Override
protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
String remark = orderDetail.getRemark();
String content = buildDishPrintData(true, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getReturnNum(), remark, orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent());
String o = sendPrintRequest(machine.getAddress(), content, null, "1");
printMachineLogService.save(orderInfo.getId(), machine, "退款单", content, o);
} }
@Override @Override
protected void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List<OrderDetail> detailList) { protected void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(),
String printerNum = "1"; orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent());
if (StrUtil.isNotBlank(machine.getPrintQty())) { String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
printerNum = machine.getPrintQty().split("\\^")[1]; String resp = sendPrintRequest(machine.getAddress(), buildDishPrintData, voiceJson, "1");
} printMachineLogService.save(orderInfo.getId(), machine, "厨房退菜", buildDishPrintData, resp);
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName())
.setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
.setOrderNo(orderInfo.getOrderNo())
.setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))
.setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
.setOriginalAmount((orderInfo.getOriginAmount().add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString())
.setReturn(isReturn(orderInfo))
.setBalance(balance)
.setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()))
.setIntegral("0")
.setOutNumber(orderInfo.getTakeCode())
.setPrintTitle("结算单")
.setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额,如果为 null 则用原价减去实付计算
.setDiscountAmount(calculateDiscountAmount(orderInfo));
if (orderInfo.getPayAmount() != null && orderInfo.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
// 设置支付金额为 订单原价-订单优惠金额
printInfoDTO.setPayAmount((new BigDecimal(printInfoDTO.getOriginalAmount()).subtract(new BigDecimal(printInfoDTO.getDiscountAmount()))).toPlainString());
}
String string = buildOrderPrintData(printInfoDTO, detailList);
String o = sendPrintRequest(machine.getAddress(), string, null, printerNum);
printMachineLogService.save(orderInfo.getId(), machine, "结算单", string, o);
} }
@Override @Override
protected void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List<OrderDetail> detailList) { public PrintInfoDTO returnOrderPrint(String printTitle,String operator, String refundAmount, String refundReason, String refundType,
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
long count = orderInfoService.queryChain() PrintInfoDTO printInfoDTO = super.returnOrderPrint(printTitle,operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList);
.eq(OrderInfo::getTradeDay, orderInfo.getTradeDay()) String data = buildRefundOrderPrintData(printInfoDTO, detailList);
.eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()) sendOrderPrint(data, orderInfo.getId(), machine, "退款单");
.eq(OrderInfo::getShopId, orderInfo.getShopId()) return null;
.le(OrderInfo::getCreateTime, orderInfo.getCreateTime()).count(); }
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()) @Override
.setCount(count) public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
.setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) PrintInfoDTO printInfoDTO = super.guestOrderPrint(operator, orderInfo, machine, detailList);
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString()) String data = buildGuestOrderPrintData(printInfoDTO, detailList);
.setOriginalAmount((orderInfo.getOriginAmount().add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()).setReturn(isReturn(orderInfo)) sendOrderPrint(data, orderInfo.getId(), machine, "客看单");
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") return null;
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") }
.setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额,如果为 null 则用原价减去实付计算
.setDiscountAmount(calculateDiscountAmount(orderInfo));
printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().toPlainString());
}
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString());
}
String string = buildOrderPrintData(printInfoDTO, detailList); @Override
String resp = sendPrintRequest(machine.getAddress(), string, null, printerNum); public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
printMachineLogService.save(orderInfo.getId(), machine, "结算单", string, resp); PrintInfoDTO printInfoDTO = super.preOrderPrint(operator, orderInfo, machine, detailList);
String data = buildOrderPrintData(printInfoDTO, detailList);
sendOrderPrint(data, orderInfo.getId(), machine, "预结算单");
return null;
}
@Override
public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = super.orderPrint(operator, orderInfo, machine, detailList);
String data = buildOrderPrintData(printInfoDTO, detailList);
sendOrderPrint(data, orderInfo.getId(), machine, "结算单");
return null;
} }
@Override @Override
@@ -181,6 +147,19 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
return DigestUtils.sha1Hex(FeiPrinter.USER + FeiPrinter.UKEY + timeStamp); return DigestUtils.sha1Hex(FeiPrinter.USER + FeiPrinter.UKEY + timeStamp);
} }
private void sendOrderPrint(String data, Long orderId, PrintMachine machine, String bizType) {
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
if (1 == machine.getVolumeSwitch()) {
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
}
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum);
printMachineLogService.save(orderId, machine, bizType, data, resp);
}
@Override @Override
public String sendPrintRequest(String address, String metaPrintData, String voiceData, String printerNum) { public String sendPrintRequest(String address, String metaPrintData, String voiceData, String printerNum) {
log.info("飞蛾打印机开始发送打印请求, 设备地址: {}, 元数据: {}", address, metaPrintData); log.info("飞蛾打印机开始发送打印请求, 设备地址: {}, 元数据: {}", address, metaPrintData);

View File

@@ -1,7 +1,7 @@
package com.czg.service.order.print; package com.czg.service.order.print;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
@@ -37,6 +37,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -84,11 +85,17 @@ public abstract class PrinterHandler {
@Getter @Getter
public enum PrintTypeEnum { public enum PrintTypeEnum {
HANDOVER("交班", "handover"), HANDOVER("交班", "handover"),
ORDER("订单", "order"),
ONE("菜品", "one"),
CALL("叫号", "call"),
ONE_AND_ORDER("菜品和结算单同时打印", "oneAndOrder"), ONE_AND_ORDER("菜品和结算单同时打印", "oneAndOrder"),
PRE_ORDER("预结算单", "preOrder"); PRE_ORDER("预结算单", "preOrder"),
ORDER("订单结算单", "order"),
GUEST_ORDER("客看单", "guestOrder"),
RETURN_FOOD("退菜", "returnFood"),
RETURN_ORDER("退单", "returnOrder"),
ONE("菜品", "one"),
CALL("叫号", "call");
private final String name; private final String name;
private final String code; private final String code;
@@ -113,29 +120,40 @@ public abstract class PrinterHandler {
@Accessors(chain = true) @Accessors(chain = true)
public static class PrintInfoDTO { public static class PrintInfoDTO {
private long count; private long count;
// 打印标题 退款单/结算单 // 打印标题 结算单/客看单/结算单 退菜单/退款单
private String printTitle; private String printTitle;
private String shopName; private String shopName;
//打印类型 收银-堂食
private String printType; private String printType;
//台桌区域-台桌号
private String pickupNum; private String pickupNum;
private String orderNo; private String orderNo;
//结账时间
private String tradeDate; private String tradeDate;
//操作人名称
private String operator; private String operator;
private String payAmount; private String payAmount;
private String originalAmount; private String originalAmount;
private String balance; //余额
// private String balance;
private String payType; private String payType;
private String integral;
private String remark; private String remark;
//取餐码
private String outNumber; private String outNumber;
private String discountAmount; private String discountAmount;
private String discountRadio; // private String discountRadio;
private String orderNum; // private String orderNum;
private String seatNum; private String seatNum;
private String seatAmount; private String seatAmount;
private String packFee; private String packFee;
// 是否退款单 // 是否退款单
private boolean isReturn; private boolean isReturn;
//退款单用
private String refundAmount;
//退款方式 现金退款/原路退回
private String refundType;
//退款原因
private String refundReason;
} }
@@ -187,96 +205,109 @@ public abstract class PrinterHandler {
} }
/** /**
* 处理打印 * 处理订单打印
* *
* @param data 传递的数据 * @param data 传递的数据
* @param printTypeEnum order returnOrder preOrder one call handover * @param printTypeEnum order preOrder one
*/ */
public void handler(String data, PrintTypeEnum printTypeEnum) { public void orderHandler(String data, PrintTypeEnum printTypeEnum, Integer placeNum) {
Long shopId; String printMethod;
String printMethod = ""; OrderInfo orderInfo = orderInfoService.getById(data);
String printType = ""; if (orderInfo == null) {
Object obj; throw new RuntimeException("订单打印失败,订单不存在");
OrderInfo orderInfo; }
switch (printTypeEnum) { switch (printTypeEnum) {
case PrintTypeEnum.HANDOVER: case PrintTypeEnum.GUEST_ORDER:
HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data)); case PrintTypeEnum.PRE_ORDER:
if (record == null) {
throw new RuntimeException("交班票打印失败,交班记录不存在");
}
obj = record;
shopId = record.getShopId();
printType = "handover";
break;
case PrintTypeEnum.ORDER: case PrintTypeEnum.ORDER:
orderInfo = orderInfoService.getById(data);
if (orderInfo == null) {
throw new RuntimeException("订单打印失败,订单不存在");
}
obj = orderInfo;
shopId = orderInfo.getShopId();
printMethod = "normal"; printMethod = "normal";
break; break;
case PrintTypeEnum.ONE: case PrintTypeEnum.ONE:
orderInfo = orderInfoService.getById(data);
if (orderInfo == null) {
throw new RuntimeException("订单打印失败,订单不存在");
}
shopId = orderInfo.getShopId();
obj = orderInfo;
printMethod = "one"; printMethod = "one";
break; break;
case PrintTypeEnum.PRE_ORDER:
orderInfo = orderInfoService.getById(data);
if (orderInfo == null) {
throw new RuntimeException("订单打印失败,订单不存在");
}
shopId = orderInfo.getShopId();
obj = orderInfo;
printMethod = "normal";
break;
case PrintTypeEnum.ONE_AND_ORDER: case PrintTypeEnum.ONE_AND_ORDER:
orderInfo = orderInfoService.getById(data);
if (orderInfo == null) {
throw new RuntimeException("订单打印失败,订单不存在");
}
shopId = orderInfo.getShopId();
obj = orderInfo;
printMethod = "all"; printMethod = "all";
break; break;
case PrintTypeEnum.CALL:
CallQueue queue = callQueueService.getById(data);
if (queue == null) {
throw new RuntimeException("叫号信息不存在: " + data);
}
shopId = queue.getShopId();
obj = queue;
printType = "queue";
break;
default: default:
throw new RuntimeException("未知打印类型"); throw new RuntimeException("未知打印类型");
} }
if (shopId == null) { getPrintMachine(orderInfo.getShopId(), "cash", printMethod, "").forEach(machine -> {
throw new RuntimeException("店铺不存在, id:" + shopId); handleRequest(machine, placeNum, orderInfo, printTypeEnum);
}
Object finalObj = obj;
getPrintMachine(shopId, "cash", printMethod, printType).forEach(machine -> {
handleRequest(machine, finalObj, printTypeEnum);
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
}); });
} }
private void handleRequest(PrintMachine machine, Object data, PrintTypeEnum printTypeEnum) { /**
* 处理退菜退款订单打印
* @param printTitle 退菜单 / 退款单
* @param operator 操作人
* @param refundAmount 退款金额
* @param refundReason 退款原因
* @param refundType 退款方式
* @param orderInfo 订单信息
* @param detailList 退菜/退款 列表
*/
public void refundOrderHandler(String printTitle, String operator, String refundAmount, String refundReason, String refundType,
OrderInfo orderInfo, List<OrderDetail> detailList) {
getPrintMachine(orderInfo.getShopId(), "cash", "normal", "").forEach(machine -> {
refundHandleRequest(machine, printTitle, operator, refundAmount, refundReason, refundType, orderInfo, detailList);
});
}
/**
* 叫号打印
*
* @param data 传递的数据
*/
public void callHandler(String data) {
CallQueue queue = callQueueService.getById(data);
if (queue == null) {
throw new RuntimeException("叫号信息不存在: " + data);
}
Long shopId = queue.getShopId();
if (shopId == null) {
throw new RuntimeException("店铺不存在, id:" + shopId);
}
getPrintMachine(shopId, "cash", "", "queue").forEach(machine -> handleRequest(machine, null, queue, PrintTypeEnum.CALL));
}
/**
* 交班打印
*
* @param data 传递的数据
*/
public void handoverHandler(String data) {
HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data));
if (record == null) {
throw new RuntimeException("交班票打印失败,交班记录不存在");
}
Long shopId = record.getShopId();
if (shopId == null) {
throw new RuntimeException("店铺不存在, id:" + shopId);
}
getPrintMachine(shopId, "cash", "", "handover").forEach(machine -> handleRequest(machine, null, record, PrintTypeEnum.HANDOVER));
}
private void handleRequest(PrintMachine machine, Integer placeNum, Object data, PrintTypeEnum printTypeEnum) {
if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) { if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) {
log.info("打印机: {}, 传递信息: {}", machine.getName(), data); log.info("打印机: {}, 传递信息: {}", machine.getName(), data);
print(machine, data, printTypeEnum); print(machine, placeNum, data, printTypeEnum);
} else if (nextPrinter != null) { } else if (nextPrinter != null) {
log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this.printerBrand, nextPrinter.printerBrand); log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this.printerBrand, nextPrinter.printerBrand);
nextPrinter.handleRequest(machine, data, printTypeEnum); nextPrinter.handleRequest(machine, placeNum, data, printTypeEnum);
} else {
log.warn("未找到匹配打印机");
}
}
private void refundHandleRequest(PrintMachine machine, String printTitle, String operator, String refundAmount, String refundReason, String refundType,
OrderInfo orderInfo, List<OrderDetail> detailList) {
if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) {
log.info("退款打印机: {}, 传递信息: {}", machine.getName(), orderInfo.getId());
returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList);
} else if (nextPrinter != null) {
log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this.printerBrand, nextPrinter.printerBrand);
nextPrinter.refundHandleRequest(machine, printTitle, operator, refundAmount, refundReason, refundType, orderInfo, detailList);
} else { } else {
log.warn("未找到匹配打印机"); log.warn("未找到匹配打印机");
} }
@@ -329,7 +360,7 @@ public abstract class PrinterHandler {
} }
protected void print(PrintMachine machine, Object data, PrintTypeEnum printTypeEnum) { protected void print(PrintMachine machine, Integer placeNum, Object data, PrintTypeEnum printTypeEnum) {
switch (printTypeEnum) { switch (printTypeEnum) {
case PrintTypeEnum.HANDOVER: case PrintTypeEnum.HANDOVER:
log.info("准备开始打印交班"); log.info("准备开始打印交班");
@@ -339,12 +370,22 @@ public abstract class PrinterHandler {
throw new RuntimeException("传递数据类型有误"); throw new RuntimeException("传递数据类型有误");
} }
break; break;
case PrintTypeEnum.GUEST_ORDER:
log.info("准备开始打印客看订单");
if (data instanceof OrderInfo orderInfo) {
redisService.set("order:print:" + orderInfo.getId(), "", 180);
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()).eq(OrderDetail::getPackNumber, placeNum));
guestOrderPrint("", orderInfo, machine, orderDetailList);
} else {
throw new RuntimeException("传递数据类型有误");
}
break;
case PrintTypeEnum.ORDER: case PrintTypeEnum.ORDER:
log.info("准备开始打印订单"); log.info("准备开始打印订单");
if (data instanceof OrderInfo orderInfo) { if (data instanceof OrderInfo orderInfo) {
redisService.set("order:print:" + orderInfo.getId(),"", 180); redisService.set("order:print:" + orderInfo.getId(), "", 180);
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
onlyFrontDesk(machine, false, orderInfo, orderDetailList); orderPrint(machine, orderInfo, orderDetailList);
} else { } else {
throw new RuntimeException("传递数据类型有误"); throw new RuntimeException("传递数据类型有误");
} }
@@ -352,9 +393,9 @@ public abstract class PrinterHandler {
case PrintTypeEnum.PRE_ORDER: case PrintTypeEnum.PRE_ORDER:
log.info("准备开始打印预结算订单"); log.info("准备开始打印预结算订单");
if (data instanceof OrderInfo orderInfo) { if (data instanceof OrderInfo orderInfo) {
redisService.set("order:print:" + orderInfo.getId(),"", 180); redisService.set("order:print:" + orderInfo.getId(), "", 180);
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
onlyFrontDesk(machine, true, orderInfo, orderDetailList); preOrderPrint(machine, orderInfo, orderDetailList);
} else { } else {
throw new RuntimeException("传递数据类型有误"); throw new RuntimeException("传递数据类型有误");
} }
@@ -362,7 +403,7 @@ public abstract class PrinterHandler {
case PrintTypeEnum.ONE: case PrintTypeEnum.ONE:
log.info("准备开始打印菜品单"); log.info("准备开始打印菜品单");
if (data instanceof OrderInfo orderInfo) { if (data instanceof OrderInfo orderInfo) {
redisService.set("order:print:" + orderInfo.getId(),"", 180); redisService.set("order:print:" + orderInfo.getId(), "", 180);
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
onlyKitchen(machine, orderInfo, orderDetailList); onlyKitchen(machine, orderInfo, orderDetailList);
} else { } else {
@@ -380,11 +421,11 @@ public abstract class PrinterHandler {
case PrintTypeEnum.ONE_AND_ORDER: case PrintTypeEnum.ONE_AND_ORDER:
log.info("准备开始打印菜品以及结算单"); log.info("准备开始打印菜品以及结算单");
if (data instanceof OrderInfo orderInfo) { if (data instanceof OrderInfo orderInfo) {
redisService.set("order:print:" + orderInfo.getId(),"", 180); redisService.set("order:print:" + orderInfo.getId(), "", 180);
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
switch (machine.getPrintMethod()) { switch (machine.getPrintMethod()) {
case "all": case "all":
onlyFrontDesk(machine, false, orderInfo, orderDetailList); orderPrint(machine, orderInfo, orderDetailList);
onlyKitchen(machine, orderInfo, orderDetailList); onlyKitchen(machine, orderInfo, orderDetailList);
break; break;
case "one": case "one":
@@ -393,7 +434,7 @@ public abstract class PrinterHandler {
break; break;
case "normal": case "normal":
log.info("打印机仅打印normal"); log.info("打印机仅打印normal");
onlyFrontDesk(machine, false, orderInfo, orderDetailList); orderPrint(machine, orderInfo, orderDetailList);
break; break;
default: default:
throw new RuntimeException("打印方法有误"); throw new RuntimeException("打印方法有误");
@@ -413,7 +454,6 @@ public abstract class PrinterHandler {
// 判断订单是否是先付费或者已结算 // 判断订单是否是先付费或者已结算
if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) { if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) {
log.warn("此订单未支付, 订单信息: {}", orderInfo); log.warn("此订单未支付, 订单信息: {}", orderInfo);
// return;
} }
List<?> categoryIds = JSONObject.parseObject(StrUtil.emptyToDefault(machine.getCategoryIds(), "[]"), List.class); List<?> categoryIds = JSONObject.parseObject(StrUtil.emptyToDefault(machine.getCategoryIds(), "[]"), List.class);
@@ -429,7 +469,6 @@ public abstract class PrinterHandler {
if (item.getNum().compareTo(BigDecimal.ZERO) <= 0 && item.getReturnNum().compareTo(BigDecimal.ZERO) <= 0) { if (item.getNum().compareTo(BigDecimal.ZERO) <= 0 && item.getReturnNum().compareTo(BigDecimal.ZERO) <= 0) {
return; return;
} }
log.info("开始打印菜品,商品名:{}", item.getProductName());
Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0); Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0);
if (isWaitCall == 1) { if (isWaitCall == 1) {
if (!item.getProductName().contains("【等叫】")) { if (!item.getProductName().contains("【等叫】")) {
@@ -455,11 +494,11 @@ public abstract class PrinterHandler {
} }
if (item.getReturnNum().compareTo(BigDecimal.ZERO) > 0) { if (item.getReturnNum().compareTo(BigDecimal.ZERO) > 0) {
returnDishesPrint(orderInfo, item, machine); returnDishesPrint("操作人名称", orderInfo, item, machine);
} }
if (item.getNum().compareTo(BigDecimal.ZERO) > 0) { if (item.getNum().compareTo(BigDecimal.ZERO) > 0) {
normalDishesPrint(orderInfo, item, machine); normalDishesPrint("操作人名称", orderInfo, item, machine);
} }
// 保存已打印信息 // 保存已打印信息
@@ -472,10 +511,60 @@ public abstract class PrinterHandler {
} }
/**
* 打印预结算单「前台」
*/
private void preOrderPrint(PrintMachine machine, OrderInfo orderInfo, List<OrderDetail> orderDetail) {
// 判断订单是否是先付费或者已结算
if (OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) {
log.warn("已取消, 订单信息: {}", orderInfo);
}
if (orderDetail.isEmpty()) {
log.info("待打印列表为空");
return;
}
List<PrintOrderDetailDTO> detailList = new ArrayList<>();
orderDetail.forEach(it -> {
Integer isTemporary = ObjectUtil.defaultIfNull(it.getIsTemporary(), 0);
String remark = "";
if (isTemporary == 0) {
ProdSku prodSku = prodSkuService.getById(it.getSkuId());
if (ObjectUtil.isNotEmpty(prodSku) && ObjectUtil.isNotEmpty(prodSku.getSpecInfo())) {
remark = prodSku.getSpecInfo();
}
}
Integer isWaitCall = ObjectUtil.defaultIfNull(it.getIsWaitCall(), 0);
if (isWaitCall == 1) {
it.setProductName("【等叫】%s".formatted(it.getProductName()));
}
if (isTemporary == 1) {
it.setProductName("【临】%s".formatted(it.getProductName()));
}
it.setPackAmount(it.getPackAmount() == null ? BigDecimal.ZERO : it.getPackAmount());
boolean isGift = it.getIsGift() != null && it.getIsGift() == 1;
if (isGift) {
it.setProductName("【赠】%s".formatted(it.getProductName()));
}
BigDecimal unitPrice = it.getPrice();
if (isGift) {
unitPrice = BigDecimal.ZERO;
}
PrintOrderDetailDTO detail = new PrintOrderDetailDTO(it.getProductName(), it.getNum().toString(), unitPrice.stripTrailingZeros().toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail);
});
if (!detailList.isEmpty()) {
preOrderPrint("操作人名称", orderInfo, machine, orderDetail);
}
}
/** /**
* 仅打印结算单「前台」 * 仅打印结算单「前台」
*/ */
private void onlyFrontDesk(PrintMachine machine, boolean isPre, OrderInfo orderInfo, List<OrderDetail> tbOrderDetailList) { private void orderPrint(PrintMachine machine, OrderInfo orderInfo, List<OrderDetail> tbOrderDetailList) {
// 判断订单是否是先付费或者已结算 // 判断订单是否是先付费或者已结算
if (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) { if (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) {
log.warn("此订单未支付或已取消, 订单信息: {}", orderInfo); log.warn("此订单未支付或已取消, 订单信息: {}", orderInfo);
@@ -514,23 +603,9 @@ public abstract class PrinterHandler {
} }
PrintOrderDetailDTO detail = new PrintOrderDetailDTO(it.getProductName(), it.getNum().toString(), unitPrice.stripTrailingZeros().toPlainString(), remark, it.getProGroupInfo()); PrintOrderDetailDTO detail = new PrintOrderDetailDTO(it.getProductName(), it.getNum().toString(), unitPrice.stripTrailingZeros().toPlainString(), remark, it.getProGroupInfo());
detailList.add(detail); detailList.add(detail);
}); });
String balance = "0";
if ("deposit".equals(orderInfo.getPayType())) {
ShopUser user = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, orderInfo.getShopId()).eq(ShopUser::getUserId, orderInfo.getUserId()));
if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
balance = user.getAmount().toPlainString();
}
}
if (!detailList.isEmpty()) { if (!detailList.isEmpty()) {
if (isReturn(orderInfo)) { orderPrint("操作人名称", orderInfo, machine, tbOrderDetailList);
returnOrderPrint(orderInfo, machine, balance, tbOrderDetailList);
} else {
normalOrderPrint(orderInfo, isPre, machine, balance, tbOrderDetailList);
}
} }
} }
@@ -567,36 +642,136 @@ public abstract class PrinterHandler {
return StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getTakeCode() : orderInfo.getTableName(); return StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getTakeCode() : orderInfo.getTableName();
} }
/**
* 根据订单信息判断是否是退单 public PrintInfoDTO returnOrderPrint(String printTitle, String operator, String refundAmount, String refundReason, String refundType,
* OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
* @param orderInfo 顶动感信息 ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
* @return 是否退款 PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("收银-堂食")
*/ .setPickupNum(orderInfo.getTableName())
protected static boolean isReturn(OrderInfo orderInfo) { .setOrderNo(orderInfo.getOrderNo())
return ArrayUtil.contains(new String[]{"refunding", "part_refund", "refund"}, orderInfo.getStatus()); .setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))
.setOperator(operator)
.setReturn(true)
.setPrintTitle(printTitle);
printInfoDTO.setRefundAmount(refundAmount);
printInfoDTO.setRefundReason(refundReason);
printInfoDTO.setRefundType("cash".equals(refundType) ? "现金退款" : "原路退回");
return printInfoDTO;
} }
public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "客看单");
BigDecimal originalAmount = BigDecimal.ZERO;
for (OrderDetail orderDetail : detailList) {
if (orderDetail.getIsGift() == 1) {
continue;
} else if (orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice()));
} else {
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice()));
}
}
printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString());
printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())
.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
}
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString());
}
return printInfoDTO;
}
public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "预结算单");
BigDecimal originalAmount = BigDecimal.ZERO;
for (OrderDetail orderDetail : detailList) {
if (orderDetail.getIsGift() == 1) {
continue;
} else if (orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice()));
} else {
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice()));
}
}
printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString());
printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())
.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
}
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString());
}
return printInfoDTO;
}
public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "结算单");
BigDecimal originalAmount = orderInfo.getOriginAmount() == null ? BigDecimal.ZERO : orderInfo.getOriginAmount();
printInfoDTO.setOriginalAmount(originalAmount.toPlainString());
printInfoDTO.setPayAmount(originalAmount.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
}
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString());
}
return printInfoDTO;
}
private PrintInfoDTO getPrintInfoDTO(String operator, OrderInfo orderInfo, String printTitle) {
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getTradeDay, orderInfo.getTradeDay())
.eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
.eq(OrderInfo::getShopId, orderInfo.getShopId())
.le(OrderInfo::getCreateTime, orderInfo.getCreateTime()));
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName())
.setPrintTitle(printTitle).setPrintType("收银-堂食").setPickupNum(getPickupNum(orderInfo))
.setOrderNo(orderInfo.getOrderNo())
.setOperator(operator).setPayAmount(orderInfo.getPayAmount().toPlainString()).setReturn(false)
.setOutNumber(orderInfo.getTakeCode()).setCount(count).setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额null 表示没有优惠
.setDiscountAmount(orderInfo.getDiscountAllAmount() != null
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00");
if ("结算单".equals(printTitle)) {
if (StrUtil.isNotBlank(orderInfo.getPayType())) {
switch (orderInfo.getPayType()) {
case "main_scan" -> printInfoDTO.setPayType("二维码收款");
case "back_scan" -> printInfoDTO.setPayType("扫码收款");
case "wechat_mini" -> printInfoDTO.setPayType("微信小程序");
case "alipay_mini" -> printInfoDTO.setPayType("支付宝小程序");
case "vip_pay" -> printInfoDTO.setPayType("会员支付");
case "cash_pay" -> printInfoDTO.setPayType("现金支付");
case "credit_pay" -> printInfoDTO.setPayType("挂账支付");
case "free_pay" -> printInfoDTO.setPayType("霸王餐支付");
}
}
printInfoDTO.setTradeDate(DateUtil.format(orderInfo.getPaidTime(), "yyyy-MM-dd HH:mm:ss"));
}
return printInfoDTO;
}
/** /**
* 菜品打印 * 菜品打印
*/ */
protected abstract void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); protected abstract void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine);
/** /**
* 菜品 退菜打印 * 菜品 退菜打印
*/ */
protected abstract void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); protected abstract void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine);
/**
* 退单打印
*/
protected abstract void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List<OrderDetail> detailList);
/**
* 订单打印
*/
protected abstract void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List<OrderDetail> detailList);
/** /**
* 叫号打印 * 叫号打印

View File

@@ -127,11 +127,11 @@ public interface PrinterImpl {
// 剩余的行单独换行输出 // 剩余的行单独换行输出
for (int i = 1; i < lines.size(); i++) { for (int i = 1; i < lines.size(); i++) {
if (i+1 != lines.size()) { if (i + 1 != lines.size()) {
// sb.append(signLabelInfo.getRs(1)); // sb.append(signLabelInfo.getRs(1));
sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s)); sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s));
sb.append(signLabelInfo.br); sb.append(signLabelInfo.br);
}else { } else {
sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s)); sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s));
} }
// sb.append(startSplitSign).append(lines.get(i)).append(endSplitSign).append("BR>"); // sb.append(startSplitSign).append(lines.get(i)).append(endSplitSign).append("BR>");
@@ -158,7 +158,7 @@ public interface PrinterImpl {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintSignLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder() StringBuilder builder = new StringBuilder()
.append(getFormatLabel(handoverRecord.getShopName(), signLabelInfo.center, signLabelInfo.f)).append(signLabelInfo.br) .append(getFormatLabel(handoverRecord.getShopName(), signLabelInfo.center, signLabelInfo.f)).append(signLabelInfo.br)
.append(getFormatLabel("交班小票", signLabelInfo.l,signLabelInfo.center)).append(signLabelInfo.br) .append(getFormatLabel("交班小票", signLabelInfo.l, signLabelInfo.center)).append(signLabelInfo.br)
.append("交班时间: ").append(DateUtil.format(handoverRecord.getHandoverTime(), "yyyy-MM-dd HH:mm:ss")).append(signLabelInfo.br) .append("交班时间: ").append(DateUtil.format(handoverRecord.getHandoverTime(), "yyyy-MM-dd HH:mm:ss")).append(signLabelInfo.br)
.append("收银员: ").append(handoverRecord.getStaffName()).append(signLabelInfo.br) .append("收银员: ").append(handoverRecord.getStaffName()).append(signLabelInfo.br)
.append("当班总收入: ").append(handoverRecord.getHandAmount()).append(signLabelInfo.br) .append("当班总收入: ").append(handoverRecord.getHandAmount()).append(signLabelInfo.br)
@@ -222,7 +222,7 @@ public interface PrinterImpl {
} }
/** /**
* 构建订单打印元数据 * 构建结算单 预结算单订单打印元数据
* *
* @param printInfoDTO 打印信息 * @param printInfoDTO 打印信息
* @param detailList 订单详情 * @param detailList 订单详情
@@ -231,51 +231,24 @@ public interface PrinterImpl {
default String buildOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List<OrderDetail> detailList) { default String buildOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintSignLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.center, signLabelInfo.f)).append(signLabelInfo.br); data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
// data.append(StrUtil.format("<C><F>{}</F></C><BR>", printInfoDTO.getShopName())); data.append(getFormatLabel(printInfoDTO.getPrintTitle(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
// data.append("<BR>"); data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br);
// data.append("<OUT:30>"); data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("{} #{}", printInfoDTO.getPrintTitle(), printInfoDTO.getCount()), signLabelInfo.l, signLabelInfo.center)) if (StrUtil.isNotBlank(printInfoDTO.getTradeDate())) {
.append(signLabelInfo.br); data.append(getFormatLabel(StrUtil.format("结账时间:{}", printInfoDTO.getTradeDate()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("桌号: {}", printInfoDTO.getPickupNum()), signLabelInfo.l, signLabelInfo.center)) }
.append(signLabelInfo.br); data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel("品名 单价 数量 ", signLabelInfo.s)).append(signLabelInfo.br);
// data.append(StrUtil.format("<C><BOLD>{}【{}】</BOLD></C><BR>", printInfoDTO.getPrintTitle(), printInfoDTO.getPickupNum()));
//if (Objects.nonNull(printInfoDTO.getOutNumber())) {
// data.append(StrUtil.format("<CB><BOLD>{}</BOLD></CB>",printInfoDTO.getOutNumber()));
//}
// data.append("<OUT:30>");
// data.append("<BR>");
data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>订单号:{}</S><BR>", printInfoDTO.getOrderNo()));
data.append(getFormatLabel(StrUtil.format("交易时间:{}", printInfoDTO.getTradeDate()), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>交易时间:{}</S><BR>", printInfoDTO.getTradeDate()));
data.append(getFormatLabel(StrUtil.format("收银员:{}", printInfoDTO.getOperator()), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>收银员:{}</S><BR>", printInfoDTO.getOperator()));
data.append(signLabelInfo.br);
data.append(signLabelInfo.br);
// data.append("<OUT:15>");
// data.append("<BR>");
// 18个空格 12
data.append(getFormatLabel("品名 数量 单价 ", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>品名 数量 小计</S><BR>");
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>--------------------------------</S><BR>");
for (OrderDetail detail : detailList) { for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString(); String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), "", StrUtil.format("{}{}", number, detail.getReturnNum().compareTo(BigDecimal.ZERO) > 0 ? String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString())
"(退" + detail.getReturnNum().stripTrailingZeros().toPlainString() + ")" : ""), , 21, 0, 5, 6);
toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString()), 21, 0, 5, 6);
data.append(row); data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) { if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
.append(signLabelInfo.br); .append(signLabelInfo.br);
// data.append("<S>规格:").append(detail.getSkuName()).append("</S><BR>");
} }
String proGroupInfo = detail.getProGroupInfo(); String proGroupInfo = detail.getProGroupInfo();
if (StrUtil.isBlank(proGroupInfo)) { if (StrUtil.isBlank(proGroupInfo)) {
@@ -295,79 +268,196 @@ public interface PrinterImpl {
}); });
} }
} }
if(StrUtil.isNotBlank(printInfoDTO.getSeatAmount())){ if (StrUtil.isNotBlank(printInfoDTO.getSeatAmount())) {
String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(),""), String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(), ""),
toPlainStr(printInfoDTO.getSeatAmount()), 21, 0, 5, 6); toPlainStr(printInfoDTO.getSeatAmount()), 21, 0, 5, 6);
data.append(row); data.append(row);
} }
if(StrUtil.isNotBlank(printInfoDTO.getPackFee())){ if (StrUtil.isNotBlank(printInfoDTO.getPackFee())) {
String row = getRow("打包费", "", "", String row = getRow("打包费", "", "",
toPlainStr(printInfoDTO.getPackFee()), 21, 0, 5, 6); toPlainStr(printInfoDTO.getPackFee()), 21, 0, 5, 6);
data.append(row); data.append(row);
} }
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("原价: {}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) { if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) {
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) data.append(getFormatLabel(StrUtil.format("优惠金额: -{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>--------------------------------</S><BR>");
data.append(getFormatLabel(StrUtil.format("原价:{}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>原价:{}</S><BR>", toPlainStr(printInfoDTO.getOriginalAmount())));
data.append(getFormatLabel(StrUtil.format("优惠:-{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>折扣:-{}</S><BR>", toPlainStr(printInfoDTO.getDiscountAmount())));
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>--------------------------------</S><BR>");
String t = "" + printInfoDTO.getPayAmount();
if (printInfoDTO.isReturn()) {
data.append(getFormatLabel(StrUtil.format("应退:{}", t), signLabelInfo.f))
.append(signLabelInfo.br);
// data.append("<F>应退").append(t).append("</F><BR>");
} else {
data.append(getFormatLabel(StrUtil.format("应收:{}", t), signLabelInfo.f))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<F>应收:{}</F><BR>", t));
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>--------------------------------</S><BR>");
if (ObjectUtil.isNotEmpty(printInfoDTO.getPayType()) && ObjectUtil.isNotNull(printInfoDTO.getPayType()) && "deposit".equals(printInfoDTO.getPayType())) {
data.append(getFormatLabel(StrUtil.format("储值:{}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>储值:{}</S><BR>", toPlainStr(printInfoDTO.getOriginalAmount())));
data.append(getFormatLabel(StrUtil.format("积分:{}", printInfoDTO.getIntegral()), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>积分:{}</S><BR>", printInfoDTO.getIntegral()));
data.append(getFormatLabel(StrUtil.format("余额:{}", toPlainStr(printInfoDTO.getBalance())), signLabelInfo.s))
.append(signLabelInfo.br);
// data.append(StrUtil.format("<S>余额:{}</S><BR>", toPlainStr(printInfoDTO.getBalance())));
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br); .append(signLabelInfo.br);
} }
// data.append("<S>--------------------------------</S><BR>");
if (StrUtil.isNotBlank(printInfoDTO.getRemark())) { if (StrUtil.isNotBlank(printInfoDTO.getRemark())) {
data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold)) data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold))
.append(signLabelInfo.br); .append(signLabelInfo.br);
// data.append(StrUtil.format("<L><BOLD>备注:{}</BOLD></L><BR>", printInfoDTO.getRemark()));
} }
// if (Objects.nonNull(printInfoDTO.getOutNumber())) { data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
// data.append(getFormatLabel(printInfoDTO.getOutNumber(), signLabelInfo.center, signLabelInfo.qr)) data.append(getFormatLabel(StrUtil.format("应付金额: {}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br);
// .append(signLabelInfo.br); if (StrUtil.isNotBlank(printInfoDTO.getPrintTitle())) {
//// data.append("<QR>".concat(printInfoDTO.getOutNumber()).concat("</QR><BR>")); data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
// } data.append(getFormatLabel(StrUtil.format("已付金额: {}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)) data.append(getFormatLabel(StrUtil.format("支付方式: {}", printInfoDTO.getPayType()), signLabelInfo.s)).append(signLabelInfo.br);
.append(signLabelInfo.br) }
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br); .append(signLabelInfo.br);
// data.append("<S>打印时间:").append(DateUtil.date().toDateStr()).append("</S><BR>"); data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s));
// data.append("<OUT:180>"); data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s));
data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(signLabelInfo.getOut(180)); data.append(signLabelInfo.getOut(180));
data.append(signLabelInfo.cut); data.append(signLabelInfo.cut);
// data.append("<PCUT>");
return data.toString(); return data.toString();
} }
/**
* 构建客看单订单打印元数据
*
* @param printInfoDTO 打印信息
* @param detailList 订单详情
* @return 订单打印元数据
*/
default String buildGuestOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder();
data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
data.append(getFormatLabel("客看单", signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br);
data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel("品名 单价 数量 ", signLabelInfo.s)).append(signLabelInfo.br);
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString())
, 21, 0, 5, 6);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
.append(signLabelInfo.br);
}
String proGroupInfo = detail.getProGroupInfo();
if (StrUtil.isBlank(proGroupInfo)) {
continue;
}
if (!JSONUtil.isTypeJSONArray(proGroupInfo)) {
continue;
}
JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number");
String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6);
data.append(subRow);
});
}
}
if (StrUtil.isNotBlank(printInfoDTO.getSeatAmount())) {
String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(), ""),
toPlainStr(printInfoDTO.getSeatAmount()), 21, 0, 5, 6);
data.append(row);
}
if (StrUtil.isNotBlank(printInfoDTO.getPackFee())) {
String row = getRow("打包费", "", "",
toPlainStr(printInfoDTO.getPackFee()), 21, 0, 5, 6);
data.append(row);
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("原价: {}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) {
data.append(getFormatLabel(StrUtil.format("优惠金额: -{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s))
.append(signLabelInfo.br);
}
if (StrUtil.isNotBlank(printInfoDTO.getRemark())) {
data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold))
.append(signLabelInfo.br);
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("应付金额:{}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br);
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s));
data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s));
data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(signLabelInfo.getOut(180));
data.append(signLabelInfo.cut);
return data.toString();
}
/**
* 构建结算单 预结算单订单打印元数据
*
* @param printInfoDTO 打印信息
* @param detailList 订单详情
* @return 订单打印元数据
*/
default String buildRefundOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder();
data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
data.append(getFormatLabel(printInfoDTO.getPrintTitle(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br);
data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
data.append(getFormatLabel("退款明细 数量 小计 ", signLabelInfo.s)).append(signLabelInfo.br);
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String amount = "";
if ("退款单".equals(printInfoDTO.getPrintTitle())) {
amount = detail.getReturnAmount().stripTrailingZeros().toPlainString();
}
String row = getRow(detail.getProductName(), "", number, amount
, 21, 0, 5, 6);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
.append(signLabelInfo.br);
}
String proGroupInfo = detail.getProGroupInfo();
if (StrUtil.isBlank(proGroupInfo)) {
continue;
}
if (!JSONUtil.isTypeJSONArray(proGroupInfo)) {
continue;
}
JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number");
String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6);
data.append(subRow);
});
}
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
if ("退款单".equals(printInfoDTO.getPrintTitle())) {
data.append(getFormatLabel(StrUtil.format("退款总计 {}", toPlainStr(printInfoDTO.getRefundAmount())), signLabelInfo.f, signLabelInfo.bold))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("退款方式:{}", toPlainStr(printInfoDTO.getRefundType())), signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("退款原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold))
.append(signLabelInfo.br);
} else {
data.append(getFormatLabel(StrUtil.format("退菜原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold))
.append(signLabelInfo.br);
}
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
.append(signLabelInfo.br);
data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s));
data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s));
data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(signLabelInfo.getOut(180));
data.append(signLabelInfo.cut);
return data.toString();
}
/** /**
* 构建菜品单打印数据 * 构建菜品单打印数据
* *

View File

@@ -28,6 +28,7 @@ import java.util.*;
/** /**
* 博实结-云享印打印机 * 博实结-云享印打印机
* 接口文档 <a href="https://bsj2.yuque.com/bsj/izhmfn/rr8b5g?#ZbE6s"> * 接口文档 <a href="https://bsj2.yuque.com/bsj/izhmfn/rr8b5g?#ZbE6s">
*
* @author Administrator * @author Administrator
*/ */
@Slf4j @Slf4j
@@ -103,7 +104,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
} }
@Override @Override
protected void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { protected void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
String buildDishPrintData = buildDishPrintData(false, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), String buildDishPrintData = buildDishPrintData(false, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(),
orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
@@ -116,7 +117,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
} }
@Override @Override
protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { protected void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(),
orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
@@ -126,98 +127,36 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
} }
@Override @Override
protected void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List<OrderDetail> detailList) { public PrintInfoDTO returnOrderPrint(String printTitle, String operator, String refundAmount, String refundReason, String refundType,
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) PrintInfoDTO printInfoDTO = super.returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList);
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))
.setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
.setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo))
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("退款单")
.setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额null 表示没有优惠
.setDiscountAmount(orderInfo.getDiscountAllAmount() != null
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00");
String data = buildOrderPrintData(printInfoDTO, detailList); String data = buildOrderPrintData(printInfoDTO, detailList);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; sendOrderPrint(data, orderInfo.getId(), machine, "退款单");
if (1 == machine.getVolumeSwitch()) { return null;
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
}
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum);
printMachineLogService.save(orderInfo.getId(), machine, "退款单", data, resp);
} }
@Override @Override
protected void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List<OrderDetail> detailList) { public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); PrintInfoDTO printInfoDTO = super.guestOrderPrint(operator, orderInfo, machine, detailList);
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getTradeDay, orderInfo.getTradeDay()) String data = buildGuestOrderPrintData(printInfoDTO, detailList);
.eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()) sendOrderPrint(data, orderInfo.getId(), machine, "客看单");
.eq(OrderInfo::getShopId, orderInfo.getShopId()) return null;
.le(OrderInfo::getCreateTime, orderInfo.getCreateTime())); }
PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName())
.setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo))
.setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))
.setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString())
.setReturn(isReturn(orderInfo))
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
.setOutNumber(orderInfo.getTakeCode())
.setPrintTitle(isPre ? "预结算单" : "结算单")
.setCount(count)
.setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额null 表示没有优惠
.setDiscountAmount(orderInfo.getDiscountAllAmount() != null
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00");
BigDecimal originalAmount = orderInfo.getOriginAmount()==null?BigDecimal.ZERO:orderInfo.getOriginAmount();
printInfoDTO.setOriginalAmount(originalAmount.toPlainString());
if (isPre) {
originalAmount = BigDecimal.ZERO;
for (OrderDetail orderDetail : detailList) {
if(orderDetail.getIsGift()==1){
continue;
}else if(orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0){
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice()));
}else {
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice()));
}
}
printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString());
printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())
.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
}else {
printInfoDTO.setPayAmount(originalAmount.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
}
printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
}
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString());
}
@Override
public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
PrintInfoDTO printInfoDTO = super.preOrderPrint(operator, orderInfo, machine, detailList);
String data = buildOrderPrintData(printInfoDTO, detailList); String data = buildOrderPrintData(printInfoDTO, detailList);
sendOrderPrint(data, orderInfo.getId(), machine, "预结算单");
return null;
}
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; @Override
if (1 == machine.getVolumeSwitch()) { public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List<OrderDetail> detailList) {
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; PrintInfoDTO printInfoDTO = super.orderPrint(operator, orderInfo, machine, detailList);
} String data = buildOrderPrintData(printInfoDTO, detailList);
String printerNum = "1"; sendOrderPrint(data, orderInfo.getId(), machine, "结算单");
if (StrUtil.isNotBlank(machine.getPrintQty())) { return null;
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum);
printMachineLogService.save(orderInfo.getId(), machine, "结算单", data, resp);
} }
/** /**
@@ -249,7 +188,6 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
*/ */
private static String getToken(String timestamp, String requestId) { private static String getToken(String timestamp, String requestId) {
StringBuilder token = new StringBuilder(); StringBuilder token = new StringBuilder();
// StringBuilder encode = new StringBuilder();
SortedMap<String, Object> map = new TreeMap<>(); SortedMap<String, Object> map = new TreeMap<>();
map.put("appId", APP_ID); map.put("appId", APP_ID);
map.put("timestamp", timestamp); map.put("timestamp", timestamp);
@@ -259,15 +197,23 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
String key = next.getKey(); String key = next.getKey();
Object value = next.getValue(); Object value = next.getValue();
token.append(key).append(value); token.append(key).append(value);
// encode.append(key).append("=").append(value).append("&");
} }
// Map<String, String> finalMap = new HashMap<>();
// finalMap.put("ENCODE", encode.toString());
// finalMap.put("TOKEN", SecureUtil.md5(token + APP_SECRET).toUpperCase());
// return finalMap;
return SecureUtil.md5(token + APP_SECRET).toUpperCase(); return SecureUtil.md5(token + APP_SECRET).toUpperCase();
} }
private void sendOrderPrint(String data, Long orderId, PrintMachine machine, String bizType) {
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
if (1 == machine.getVolumeSwitch()) {
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
}
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum);
printMachineLogService.save(orderId, machine, bizType, data, resp);
}
/** /**
* 检查打印状态 * 检查打印状态
@@ -292,14 +238,4 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
log.info("云想印打印机:{},任务:{}状态:{}", devName, taskId, s); log.info("云想印打印机:{},任务:{}状态:{}", devName, taskId, s);
return s; return s;
} }
/**
* 计算优惠金额:优先使用 discountAllAmount如果为 null 则返回 0
*/
private String calculateDiscountAmount(OrderInfo orderInfo) {
return orderInfo.getDiscountAllAmount() != null
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00";
}
} }

View File

@@ -314,7 +314,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
} }
orderDetails.forEach(item -> item.setOrderTime(DateUtil.date().toLocalDateTime())); orderDetails.forEach(item -> item.setOrderTime(DateUtil.date().toLocalDateTime()));
AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空"); AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空");
processOrderDetails(orderDetails, param.getLimitRate(),param); processOrderDetails(orderDetails, param.getLimitRate(), param);
//生成订单 //生成订单
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table); OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails); orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
@@ -324,6 +324,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
.eq(CashierCart::getTableCode, param.getTableCode()) .eq(CashierCart::getTableCode, param.getTableCode())
); );
if ("after-pay".equals(orderInfo.getPayMode())) { if ("after-pay".equals(orderInfo.getPayMode())) {
printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.GUEST_ORDER, orderInfo.getPlaceNum());
//发送打票信息 后付费推送多次 需要处理 //发送打票信息 后付费推送多次 需要处理
//orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成 //orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成
//orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0" //orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0"
@@ -554,7 +555,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
if (param.getTargetOrderId() == null && StrUtil.isBlank(param.getTargetTableCode())) { if (param.getTargetOrderId() == null && StrUtil.isBlank(param.getTargetTableCode())) {
throw new CzgException("转台失败,请选择目标台桌后转台"); throw new CzgException("转台失败,请选择目标台桌后转台");
} }
if(param.getAllMerge()==null){ if (param.getAllMerge() == null) {
param.setAllMerge(0); param.setAllMerge(0);
} }
OrderInfo sourceOrder = orderInfoService.getById(param.getSourceOrderId()); OrderInfo sourceOrder = orderInfoService.getById(param.getSourceOrderId());
@@ -569,13 +570,13 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
ShopTable shopTable = shopTableService.getOneByTableCode(sourceOrder.getShopId(), param.getTargetTableCode()); ShopTable shopTable = shopTableService.getOneByTableCode(sourceOrder.getShopId(), param.getTargetTableCode());
sourceOrder.setTableCode(shopTable.getTableCode()); sourceOrder.setTableCode(shopTable.getTableCode());
sourceOrder.setTableName(shopTable.getName()); sourceOrder.setTableName(shopTable.getName());
if(param.getAllMerge()==1){ if (param.getAllMerge() == 1) {
OrderInfo upOrder = new OrderInfo(); OrderInfo upOrder = new OrderInfo();
upOrder.setTableCode(shopTable.getTableCode()); upOrder.setTableCode(shopTable.getTableCode());
upOrder.setTableName(shopTable.getName()); upOrder.setTableName(shopTable.getName());
orderInfoService.update(upOrder, new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId())); orderInfoService.update(upOrder, new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId()));
targetOrder=sourceOrder; targetOrder = sourceOrder;
}else { } else {
OrderInfoAddDTO addDTO = new OrderInfoAddDTO(); OrderInfoAddDTO addDTO = new OrderInfoAddDTO();
addDTO.setShopId(sourceOrder.getShopId()); addDTO.setShopId(sourceOrder.getShopId());
addDTO.setStaffId(sourceOrder.getStaffId()); addDTO.setStaffId(sourceOrder.getStaffId());
@@ -615,16 +616,16 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
if (count < 1) { if (count < 1) {
throw new CzgException("转台失败,该订单无可转商品"); throw new CzgException("转台失败,该订单无可转商品");
} }
orderDetailService.update(orderDetailUp,new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId())); orderDetailService.update(orderDetailUp, new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId()));
} else { } else {
orderDetailService.update(orderDetailUp, orderDetailService.update(orderDetailUp,
new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId()).in(OrderDetail::getId, param.getDetailIds())); new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId()).in(OrderDetail::getId, param.getDetailIds()));
} }
if(param.getAllMerge()==1){ if (param.getAllMerge() == 1) {
orderInfoService.remove(new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId())); orderInfoService.remove(new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId()));
} }
} }
if(param.getAllMerge()==1){ if (param.getAllMerge() == 1) {
shopTableService.updateStatus(sourceOrder.getShopId(), null, sourceTableCode, ShopTableStatusEnum.IDLE.getValue()); shopTableService.updateStatus(sourceOrder.getShopId(), null, sourceTableCode, ShopTableStatusEnum.IDLE.getValue());
} }
shopTableService.updateStatus(sourceOrder.getShopId(), null, targetOrder.getTableCode(), ShopTableStatusEnum.UNSETTLED.getValue()); shopTableService.updateStatus(sourceOrder.getShopId(), null, targetOrder.getTableCode(), ShopTableStatusEnum.UNSETTLED.getValue());
@@ -1028,7 +1029,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
* *
* @param orderDetails 订单详情 需要回填 * @param orderDetails 订单详情 需要回填
*/ */
private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate,OrderInfoAddDTO param) throws CzgException { private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate, OrderInfoAddDTO param) throws CzgException {
BigDecimal packFee = BigDecimal.ZERO; BigDecimal packFee = BigDecimal.ZERO;
for (OrderDetail detail : orderDetails) { for (OrderDetail detail : orderDetails) {
if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) { if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) {
@@ -1358,7 +1359,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
@Transactional @Transactional
public void expired(Long orderId) { public void expired(Long orderId) {
OrderInfo orderInfo = orderInfoService.getById(orderId); OrderInfo orderInfo = orderInfoService.getById(orderId);
if(orderInfo == null){ if (orderInfo == null) {
log.info("订单取消失败,订单Id:{} 为空", orderId); log.info("订单取消失败,订单Id:{} 为空", orderId);
return; return;
} }
@@ -1581,14 +1582,14 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
} }
switch (orderInfoPrintDTO.getType()) { switch (orderInfoPrintDTO.getType()) {
case 0: case 0://菜品和结算单同时打印
printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ONE_AND_ORDER); printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ONE_AND_ORDER, null);
break; break;
case 1: case 1://预结算单
printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.PRE_ORDER); printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.PRE_ORDER, null);
break; break;
case 2: case 2://结算单
printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ORDER); printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ORDER, null);
break; break;
} }
return true; return true;

View File

@@ -498,6 +498,7 @@ public class OrderPayServiceImpl implements OrderPayService {
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason()); orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
orderInfoService.updateById(orderInfo); orderInfoService.updateById(orderInfo);
//退款后续 //退款后续
//退款返还库存 //退款返还库存
if (!returnProMap.isEmpty()) { if (!returnProMap.isEmpty()) {
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap))); rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));