小票打印完善
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印mq消息处理器
|
* 打印mq消息处理器
|
||||||
@@ -30,30 +31,19 @@ import java.util.List;
|
|||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PrintMqListener {
|
public class PrintMqListener {
|
||||||
@DubboReference
|
|
||||||
private PrintMachineService printMachineService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderInfoService orderInfoService;
|
|
||||||
@Resource
|
@Resource
|
||||||
private MqLogService mqLogService;
|
private MqLogService mqLogService;
|
||||||
@Lazy
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
private PrinterHandler printerHandler;
|
private PrinterHandler printerHandler;
|
||||||
|
|
||||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE})
|
private <T> void invokeFun(String type, String plat, T data, Consumer<T> consumer) {
|
||||||
public void orderPrint(String orderId) {
|
|
||||||
long startTime = DateUtil.date().getTime();
|
long startTime = DateUtil.date().getTime();
|
||||||
log.info("接收到订单打印消息:{}", orderId);
|
log.info("接收到{}打印消息:{}", type, data);
|
||||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(orderId).setType("orderPrint").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(data.toString())
|
||||||
|
.setType(type).setPlat(plat).setCreateTime(DateUtil.date().toLocalDateTime());
|
||||||
try {
|
try {
|
||||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
consumer.accept(data);
|
||||||
if (orderInfo == null) {
|
|
||||||
log.error("订单信息不存在, {}", orderId);
|
|
||||||
throw new RuntimeException("订单信息不存在");
|
|
||||||
}
|
|
||||||
printerHandler.handler(orderId, PrinterHandler.PrintTypeEnum.ORDER);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("订单打印失败", e);
|
log.error("订单打印失败", e);
|
||||||
mqLog.setErrInfo(JSONObject.toJSONString(e));
|
mqLog.setErrInfo(JSONObject.toJSONString(e));
|
||||||
@@ -63,61 +53,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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 交班打印
|
* 交班打印
|
||||||
*/
|
*/
|
||||||
@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) {
|
||||||
long startTime = DateUtil.date().getTime();
|
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.ONE_AND_ORDER));
|
||||||
log.info("接收到交班打印消息:{}", id);
|
|
||||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(id).setType("handoverPrint").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
|
||||||
try {
|
|
||||||
printerHandler.handler(id, PrinterHandler.PrintTypeEnum.HANDOVER);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("交班打印失败", e);
|
|
||||||
mqLog.setErrInfo(JSONObject.toJSONString(e));
|
|
||||||
mqLog.setDuration(DateUtil.date().getTime() - startTime);
|
|
||||||
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
|
|
||||||
mqLogService.save(mqLog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取可用打印机
|
|
||||||
*
|
|
||||||
* @param shopId 店铺id
|
|
||||||
* @param subType 打印类型(分类)label标签 cash小票 kitchen出品
|
|
||||||
* @param printMethod 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
|
|
||||||
* @param printType 打印类型,JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
|
|
||||||
* @return 打印机列表
|
|
||||||
*/
|
|
||||||
private List<PrintMachine> getPrintMachine(Long shopId, String subType, String printMethod, String printType) {
|
|
||||||
QueryWrapper wrapper = new QueryWrapper()
|
|
||||||
.eq(PrintMachine::getStatus, 1)
|
|
||||||
.eq(PrintMachine::getShopId, shopId)
|
|
||||||
.eq(PrintMachine::getSubType, subType)
|
|
||||||
.eq(PrintMachine::getConnectionType, "网络");
|
|
||||||
if (StrUtil.isNotEmpty(printMethod)) {
|
|
||||||
wrapper.in(PrintMachine::getPrintMethod, Arrays.asList(printMethod, "all"));
|
|
||||||
}
|
|
||||||
if ("callTicket".equals(printType)) {
|
|
||||||
printType = "queue";
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotEmpty(printType)) {
|
|
||||||
wrapper.like(PrintMachine::getPrintType, printType);
|
|
||||||
}
|
|
||||||
List<PrintMachine> list = printMachineService.list(wrapper);
|
|
||||||
for (PrintMachine item : list) {
|
|
||||||
//实际打印以传递的参数为准
|
|
||||||
item.setPrintMethod(printMethod);
|
|
||||||
}
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
log.error("店铺未配置打印机,店铺id: {}", shopId);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("打印机列表: {}", list);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public abstract class PrinterHandler {
|
|||||||
@Getter
|
@Getter
|
||||||
public enum PrintTypeEnum {
|
public enum PrintTypeEnum {
|
||||||
HANDOVER("交班", "handover"),
|
HANDOVER("交班", "handover"),
|
||||||
ORDER("订单", "order"), ONE("菜品", "one"), CALL("叫号", "call");
|
ORDER("订单", "order"), ONE("菜品", "one"), CALL("叫号", "call"), ONE_AND_ORDER("菜品和结算单同时打印", "oneAndOrder");
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|
||||||
@@ -178,7 +178,8 @@ public abstract class PrinterHandler {
|
|||||||
Long shopId = null;
|
Long shopId = null;
|
||||||
String printMethod = "";
|
String printMethod = "";
|
||||||
String printType = "";
|
String printType = "";
|
||||||
Object obj = null;
|
Object obj;
|
||||||
|
OrderInfo orderInfo;
|
||||||
switch (printTypeEnum) {
|
switch (printTypeEnum) {
|
||||||
case PrintTypeEnum.HANDOVER:
|
case PrintTypeEnum.HANDOVER:
|
||||||
HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data));
|
HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data));
|
||||||
@@ -190,7 +191,7 @@ public abstract class PrinterHandler {
|
|||||||
printType = "handover";
|
printType = "handover";
|
||||||
break;
|
break;
|
||||||
case PrintTypeEnum.ORDER:
|
case PrintTypeEnum.ORDER:
|
||||||
OrderInfo orderInfo = orderInfoService.getById(data);
|
orderInfo = orderInfoService.getById(data);
|
||||||
if (orderInfo == null) {
|
if (orderInfo == null) {
|
||||||
throw new RuntimeException("订单打印失败,订单不存在");
|
throw new RuntimeException("订单打印失败,订单不存在");
|
||||||
}
|
}
|
||||||
@@ -199,6 +200,25 @@ public abstract class PrinterHandler {
|
|||||||
printMethod = "order";
|
printMethod = "order";
|
||||||
printType = "order";
|
printType = "order";
|
||||||
break;
|
break;
|
||||||
|
case PrintTypeEnum.ONE:
|
||||||
|
orderInfo = orderInfoService.getById(data);
|
||||||
|
if (orderInfo == null) {
|
||||||
|
throw new RuntimeException("订单打印失败,订单不存在");
|
||||||
|
}
|
||||||
|
obj = orderInfo;
|
||||||
|
printMethod = "one";
|
||||||
|
break;
|
||||||
|
case PrintTypeEnum.ONE_AND_ORDER:
|
||||||
|
orderInfo = orderInfoService.getById(data);
|
||||||
|
if (orderInfo == null) {
|
||||||
|
throw new RuntimeException("订单打印失败,订单不存在");
|
||||||
|
}
|
||||||
|
obj = orderInfo;
|
||||||
|
printMethod = "all";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("未知打印类型");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (shopId == null) {
|
if (shopId == null) {
|
||||||
@@ -278,6 +298,8 @@ public abstract class PrinterHandler {
|
|||||||
log.info("准备开始打印交班");
|
log.info("准备开始打印交班");
|
||||||
if (data instanceof HandoverRecordDTO record) {
|
if (data instanceof HandoverRecordDTO record) {
|
||||||
handoverPrint(machine, record);
|
handoverPrint(machine, record);
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("传递数据类型有误");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PrintTypeEnum.ORDER:
|
case PrintTypeEnum.ORDER:
|
||||||
@@ -285,6 +307,8 @@ public abstract class PrinterHandler {
|
|||||||
if (data instanceof OrderInfo orderInfo) {
|
if (data instanceof OrderInfo orderInfo) {
|
||||||
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, orderInfo, orderDetailList);
|
onlyFrontDesk(machine, orderInfo, orderDetailList);
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("传递数据类型有误");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PrintTypeEnum.ONE:
|
case PrintTypeEnum.ONE:
|
||||||
@@ -292,11 +316,27 @@ public abstract class PrinterHandler {
|
|||||||
if (data instanceof OrderInfo orderInfo) {
|
if (data instanceof OrderInfo orderInfo) {
|
||||||
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 {
|
||||||
|
throw new RuntimeException("传递数据类型有误");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PrintTypeEnum.CALL:
|
case PrintTypeEnum.CALL:
|
||||||
log.info("准备开始打印叫号单");
|
log.info("准备开始打印叫号单");
|
||||||
onlyCallNumPrint(machine, null);
|
if (data instanceof Long id) {
|
||||||
|
onlyCallNumPrint(machine, id);
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("传递数据类型有误");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PrintTypeEnum.ONE_AND_ORDER:
|
||||||
|
log.info("准备开始打印菜品以及结算单");
|
||||||
|
if (data instanceof OrderInfo orderInfo) {
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
|
||||||
|
onlyFrontDesk(machine, orderInfo, orderDetailList);
|
||||||
|
onlyKitchen(machine, orderInfo, orderDetailList);
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("传递数据类型有误");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user