打印完善

This commit is contained in:
张松
2025-02-26 15:57:00 +08:00
parent ee48e3f509
commit b018b321ed

View File

@@ -1,5 +1,6 @@
package com.czg.service.account.print; package com.czg.service.account.print;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
@@ -78,7 +79,7 @@ public abstract class PrinterHandler {
@Accessors(chain = true) @Accessors(chain = true)
public static class PrintDetailInfo { public static class PrintDetailInfo {
private boolean isPrint; private boolean isPrint;
// private boolean isReturn; // private boolean isReturn;
private long orderId; private long orderId;
private long detailId; private long detailId;
private BigDecimal printNum; private BigDecimal printNum;
@@ -145,31 +146,37 @@ public abstract class PrinterHandler {
} }
protected List<OrderDetail> getCanPrintOrderDetails(boolean partPrint, Long orderId, List<OrderDetail> tbOrderDetailList, List<?> categoryIds) { protected List<OrderDetail> getCanPrintOrderDetails(boolean partPrint, Long orderId, List<OrderDetail> tbOrderDetailList, List<?> categoryIds) {
List<Object> detailList = redisService.lGet(RedisCst.getPrintOrderDetailKey(orderId), 0, -1);
Map<Long, PrintDetailInfo> detailMap = detailList.stream().collect(Collectors.toMap(i -> {
if (i instanceof PrintDetailInfo i2) {
return i2.getDetailId();
}
throw new RuntimeException("转换orderDetail失败");
}, i -> (PrintDetailInfo) i));
List<Long> productIds = tbOrderDetailList.stream().map(OrderDetail::getProductId).collect(Collectors.toList()); List<Long> productIds = tbOrderDetailList.stream().map(OrderDetail::getProductId).collect(Collectors.toList());
Map<Long, Boolean> canPrintProMap = partPrint || categoryIds.isEmpty() ? new HashMap<>() : Map<Long, Boolean> canPrintProMap = partPrint || categoryIds.isEmpty() ? new HashMap<>() :
productService.list(new QueryWrapper().in(Product::getCategoryId, categoryIds).in(Product::getId, productIds)) productService.list(new QueryWrapper().in(Product::getCategoryId, categoryIds).in(Product::getId, productIds))
.stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true)); .stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true));
ArrayList<OrderDetail> orderDetails = new ArrayList<>(); ArrayList<OrderDetail> orderDetails = new ArrayList<>();
tbOrderDetailList.forEach(item -> { tbOrderDetailList.forEach(item -> {
PrintDetailInfo printDetailInfo = detailMap.get(item.getId()); Object o = redisService.get(RedisCst.getPrintOrderDetailKey(orderId, item.getId()));
if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint) &&
(printDetailInfo == null || item.getNum().subtract(printDetailInfo.getPrintNum()).compareTo(BigDecimal.ZERO) > 0)) { if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint)) {
item.setReturnNum(item.getReturnNum() == null ? BigDecimal.ZERO : item.getReturnNum()); item.setReturnNum(item.getReturnNum() == null ? BigDecimal.ZERO : item.getReturnNum());
PrintDetailInfo printDetailInfo = o != null ? JSONObject.parseObject((String) o, PrintDetailInfo.class) : null;
if (printDetailInfo != null) { if (printDetailInfo != null) {
if (item.getNum().compareTo(printDetailInfo.getPrintNum()) <= 0) {
log.info("此菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo);
}
if (item.getReturnNum().compareTo(printDetailInfo.getPrintReturnNum()) <= 0) {
log.info("此退菜菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo);
}
item.setNum(item.getNum().subtract(printDetailInfo.getPrintNum())); item.setNum(item.getNum().subtract(printDetailInfo.getPrintNum()));
item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintNum())); item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintReturnNum()));
orderDetails.add(item);
}else {
orderDetails.add(item);
} }
orderDetails.add(item);
} else {
log.info("此菜品不在打印分类或属于免打, {} {} {}", item.getProductName(), item.getSkuName(), item.getId());
} }
}); });
@@ -200,7 +207,7 @@ public abstract class PrinterHandler {
} }
default -> log.warn("未知打印类型: {}", printMethod); default -> log.warn("未知打印类型: {}", printMethod);
} }
}else { } else {
log.info("准备开始打印叫号单"); log.info("准备开始打印叫号单");
if (StrUtil.isBlank(machine.getPrintType())) { if (StrUtil.isBlank(machine.getPrintType())) {
return; return;
@@ -241,10 +248,8 @@ public abstract class PrinterHandler {
} }
// 已打印详情信息 // 已打印详情信息
ArrayList<PrintDetailInfo> printDetailInfos = new ArrayList<>(); Map<Long, OrderDetail> detailMap = tbOrderDetailList.stream().map(item -> BeanUtil.copyProperties(item, OrderDetail.class)).collect(Collectors.toMap(OrderDetail::getId, i -> i));
Map<Long, OrderDetail> detailMap = tbOrderDetailList.stream().collect(Collectors.toMap(OrderDetail::getId, i -> i));
tbOrderDetailList = getCanPrintOrderDetails("1".equals(machine.getClassifyPrint()), orderInfo.getId(), tbOrderDetailList, categoryIds); tbOrderDetailList = getCanPrintOrderDetails("1".equals(machine.getClassifyPrint()), orderInfo.getId(), tbOrderDetailList, categoryIds);
String printKey = RedisCst.getPrintOrderDetailKey(orderInfo.getId());
tbOrderDetailList.parallelStream().filter(o -> ObjectUtil.defaultIfNull(o.getIsPrint(), 0) == 1).forEach(item -> { tbOrderDetailList.parallelStream().filter(o -> ObjectUtil.defaultIfNull(o.getIsPrint(), 0) == 1).forEach(item -> {
log.info("开始打印菜品,商品名:{}", item.getProductName()); log.info("开始打印菜品,商品名:{}", item.getProductName());
Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0); Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0);
@@ -291,8 +296,8 @@ public abstract class PrinterHandler {
// 保存已打印信息 // 保存已打印信息
OrderDetail orderDetail = detailMap.get(item.getId()); OrderDetail orderDetail = detailMap.get(item.getId());
redisService.leftPush(printKey, new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId()) redisService.set(RedisCst.getPrintOrderDetailKey(orderInfo.getId(), item.getId()), JSONObject.toJSONString(new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId())
.setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum())); .setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum())), 3600 * 24);
}); });
@@ -383,10 +388,10 @@ public abstract class PrinterHandler {
CallTable tbCallTable = callTableService.getById(queue.getCallTableId()); CallTable tbCallTable = callTableService.getById(queue.getCallTableId());
ShopInfo shopInfo = shopInfoService.getById(queue.getShopId()); ShopInfo shopInfo = shopInfoService.getById(queue.getShopId());
callNumPrint(machine, queue.getCallNum(), shopInfo.getShopName(), tbCallTable.getName(), tbCallTable.getNote(), String.valueOf(callQueueService.count(new QueryWrapper() callNumPrint(machine, queue.getCallNum(), shopInfo.getShopName(), tbCallTable.getName(), tbCallTable.getNote(), String.valueOf(callQueueService.count(new QueryWrapper()
.eq(CallQueue::getShopId, queue.getShopId()) .eq(CallQueue::getShopId, queue.getShopId())
.eq(CallQueue::getCallTableId, queue.getCallTableId()) .eq(CallQueue::getCallTableId, queue.getCallTableId())
.lt(CallQueue::getId, queue.getId()) .lt(CallQueue::getId, queue.getId())
.in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(), .in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(),
StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum())); StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum()));
} }
@@ -399,6 +404,7 @@ public abstract class PrinterHandler {
/** /**
* 根据订单信息判断是否是退单 * 根据订单信息判断是否是退单
*
* @param orderInfo 顶动感信息 * @param orderInfo 顶动感信息
* @return 是否退款 * @return 是否退款
*/ */