增加排号小票打印处理

This commit is contained in:
2024-09-19 15:30:50 +08:00
parent 89ac3c9e25
commit 905063987a
18 changed files with 1412 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
@@ -88,9 +89,9 @@ public class PrintConsumer {
if (orderDetails.isEmpty()) {
return;
}
getPrintMachine(Integer.valueOf(orderInfo.getShopId()), "cash").forEach(machine -> {
getPrintMachine(Integer.valueOf(orderInfo.getShopId()), "cash", "one").forEach(machine -> {
log.info("打印机信息: {}", machine);
printerHandler.handleRequest(machine, isReturn, orderInfo, orderDetails);
printerHandler.handleRequest(machine, isReturn, orderInfo, orderDetails, null);
});
} catch (Exception e) {
@@ -111,10 +112,9 @@ public class PrintConsumer {
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
Utils.checkValueUnReturn(shopInfo, "店铺信息不存在");
getPrintMachine(shopInfo.getId(), "cash").forEach(machine -> {
getPrintMachine(shopInfo.getId(), "cash", "normal").forEach(machine -> {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId());
printerHandler.handleRequest(machine, isReturn, orderInfo, tbOrderDetails);
printerHandler.handleRequest(machine, isReturn, orderInfo, tbOrderDetails, null);
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
});
@@ -123,6 +123,21 @@ public class PrintConsumer {
}
}
@RabbitListener(queues = {RabbitConstants.QUEUE_PRINT_CALL_TABLE})
public void printCallTableListener(String msg) {
try {
log.info("打印消息mq 接收到打印取号小票消息,消息内容: {}", msg);
CallNumPrintDTO printDTO = JSONObject.parseObject(msg, CallNumPrintDTO.class);
getPrintMachine(printDTO.getShopId(), "cash", "callTicket").forEach(machine -> {
printerHandler.handleRequest(machine, false, null, null, printDTO);
});
} catch (Exception e) {
log.warn("打印菜品失败", e);
}
}
private boolean checkMachineModel(String type, TbPrintMachine machine) {
Utils.checkValueUnReturn(machine, "打印机为null");
JSONObject config = JSONObject.parseObject(machine.getConfig());
@@ -131,7 +146,7 @@ public class PrintConsumer {
}
private List<TbPrintMachine> getPrintMachine(Integer shopId, String subType) {
private List<TbPrintMachine> getPrintMachine(Integer shopId, String subType, String model) {
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(shopId);
if (ObjectUtil.isEmpty(shopInfo)) {
log.error("店铺信息不存在");
@@ -147,6 +162,10 @@ public class PrintConsumer {
log.error("店铺未配置打印机店铺id: {}", shopId);
return list;
}
list = list.stream()
.filter(item -> StrUtil.isNotBlank(item.getConfig())
&& model.equals(JSONObject.parseObject(item.getConfig()).getString("model"))).collect(Collectors.toList());
log.info("打印机列表: {}", list);
return list;

View File

@@ -166,4 +166,13 @@ public class RabbitConfig {
return BindingBuilder.bind(printPlaceQueue).to(printExchange).with(RabbitConstants.ROUTING_KEY_PRINT_PLACE);
}
@Bean
Queue printCallTableQueue() {
return new Queue(RabbitConstants.QUEUE_PRINT_CALL_TABLE);
}
@Bean
Binding bindingCallTablePrint(Queue printCallTableQueue, DirectExchange printExchange) {
return BindingBuilder.bind(printCallTableQueue).to(printExchange).with(RabbitConstants.ROUTING_KEY_CALL_TABLE);
}
}

View File

@@ -63,8 +63,11 @@ public interface RabbitConstants {
String EXCHANGE_PRINT = "exchange.print";
// 菜品打印
String QUEUE_PRINT_DISHES = "queue.dishes.print";
String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print";
String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print1";
// 下单打印
String QUEUE_PRINT_PLACE = "queue.place.order.print";
String ROUTING_KEY_PRINT_PLACE = "routing.place.order.print";
// 排号打印
String QUEUE_PRINT_CALL_TABLE = "queue.print.call.table";
String ROUTING_KEY_CALL_TABLE = "routing.call.table";
}

View File

@@ -6,6 +6,7 @@ import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import org.springframework.stereotype.Component;
@@ -37,4 +38,9 @@ public class FeiPrinter extends PrinterHandler{
protected void normalOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List<OrderDetailPO.Detail> detailList) {
}
@Override
protected void callNumPrint(CallNumPrintDTO printDTO) {
}
}

View File

@@ -8,6 +8,7 @@ import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
@@ -41,7 +42,7 @@ public abstract class PrinterHandler {
this.tbShopUserMapper = tbShopUserMapper;
}
protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList) {
protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) {
String configStr = machine.getConfig();
Utils.checkValueUnReturn(configStr, "打印机配置为空");
JSONObject config = JSONObject.parseObject(configStr);
@@ -119,18 +120,22 @@ public abstract class PrinterHandler {
}
}
break;
case "callTicket":
callNumPrint(printDTO);
break;
default:
log.warn("未知打印类型: {}", model);
}
}
public void handleRequest(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList) {
public void handleRequest(TbPrintMachine machine, Boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) {
if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) {
log.info("打印机: {}, 是否退款单: {}, 订单信息: {}, 订单详情信息: {}", machine, isReturn, orderInfo, tbOrderDetailList);
print(machine, isReturn, orderInfo, tbOrderDetailList);
print(machine, isReturn, orderInfo, tbOrderDetailList, printDTO);
} else if (nextPrinter != null) {
log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this, nextPrinter);
nextPrinter.handleRequest(machine, isReturn, orderInfo, tbOrderDetailList);
nextPrinter.handleRequest(machine, isReturn, orderInfo, tbOrderDetailList, printDTO);
} else {
log.warn("未找到匹配打印机");
}
@@ -144,6 +149,8 @@ public abstract class PrinterHandler {
protected abstract void normalOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List<OrderDetailPO.Detail> detailList);
protected abstract void callNumPrint(CallNumPrintDTO printDTO);
// 抽象方法,子类实现判断能否处理请求
boolean canHandleRequest(String currentBrand, String connectType) {
log.info("handle判断是否可处理: {}, 连接类型: {}, handler类型: {}", currentBrand, connectType, printerBrand);

View File

@@ -2,18 +2,21 @@ package com.chaozhanggui.system.cashierservice.rabbit.print;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
@@ -22,11 +25,18 @@ import java.util.List;
@Slf4j
@Component
public class YxyPrinter extends PrinterHandler{
private final TbCallQueueMapper tbCallQueueMapper;
private final TbCallTableMapper tbCallTableMapper;
@Value("${wx.mini.page.call}")
private String callPageUrl;
private final TbShopInfoMapper shopInfoMapper;
public YxyPrinter(TbShopInfoMapper shopInfoMapper, TbProductMapper productMapper, TbProductSkuMapper productSkuMapper, TbShopUserMapper shopUserMapper) {
public YxyPrinter(TbShopInfoMapper shopInfoMapper, TbProductMapper productMapper, TbProductSkuMapper productSkuMapper, TbShopUserMapper shopUserMapper, TbCallQueueMapper tbCallQueueMapper, TbCallTableMapper tbCallTableMapper) {
super("yxyPrinter", productMapper, productSkuMapper, shopUserMapper);
this.shopInfoMapper = shopInfoMapper;
this.tbCallQueueMapper = tbCallQueueMapper;
this.tbCallTableMapper = tbCallTableMapper;
}
@@ -83,4 +93,36 @@ public class YxyPrinter extends PrinterHandler{
PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
}
@Override
protected void callNumPrint(CallNumPrintDTO printDTO) {
TbCallQueue queue = tbCallQueueMapper.selectById(printDTO.getCallQueueId());
if (queue == null) {
log.warn("叫号记录不存在");
return;
}
TbCallTable tbCallTable = tbCallTableMapper.selectById(queue.getCallTableId());
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(queue.getShopId());
CallNumPrintPO po = new CallNumPrintPO();
po.setCallNum(queue.getCallNum());
po.setShopName(shopInfo.getShopName());
po.setTableName(tbCallTable.getName());
po.setTableNote(tbCallTable.getNote());
po.setPreNum(tbCallQueueMapper.selectCount(new LambdaQueryWrapper<TbCallQueue>()
.eq(TbCallQueue::getShopId, queue.getShopId())
.eq(TbCallQueue::getCallTableId, queue.getCallTableId())
.lt(TbCallQueue::getId, queue.getId())
.in(TbCallQueue::getState, 0, 1)).toString());
po.setCallNum(queue.getCallNum());
po.setCodeUrl(StrUtil.format(callPageUrl, queue.getShopId(), queue.getId()));
po.setTakeTime(queue.getCreateTime());
po.setShopNote("过号顺延三桌 三桌后需重新排号 谢谢理解!");
String data = PrinterUtils.getCallNumPrintData(po);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一条新的排号记录\"}";
PrinterUtils.printTickets(voiceJson, 3, 1, "ZF544PG03W00005", data);
}
public static void main(String[] args) {
}
}