小票打印完善
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 打印mq消息处理器
|
||||
@@ -30,30 +31,19 @@ import java.util.List;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PrintMqListener {
|
||||
@DubboReference
|
||||
private PrintMachineService printMachineService;
|
||||
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private MqLogService mqLogService;
|
||||
@Lazy
|
||||
@Resource
|
||||
private PrinterHandler printerHandler;
|
||||
|
||||
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE})
|
||||
public void orderPrint(String orderId) {
|
||||
private <T> void invokeFun(String type, String plat, T data, Consumer<T> consumer) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
log.info("接收到订单打印消息:{}", orderId);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(orderId).setType("orderPrint").setPlat("java.order").setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
log.info("接收到{}打印消息:{}", type, data);
|
||||
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE).setMsg(data.toString())
|
||||
.setType(type).setPlat(plat).setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
try {
|
||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
||||
if (orderInfo == null) {
|
||||
log.error("订单信息不存在, {}", orderId);
|
||||
throw new RuntimeException("订单信息不存在");
|
||||
}
|
||||
printerHandler.handler(orderId, PrinterHandler.PrintTypeEnum.ORDER);
|
||||
|
||||
consumer.accept(data);
|
||||
} catch (Exception e) {
|
||||
log.error("订单打印失败", 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})
|
||||
public void handoverPrint(String id) {
|
||||
long startTime = DateUtil.date().getTime();
|
||||
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;
|
||||
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.ONE_AND_ORDER));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user