调整打印机配置,修改打印机参数

This commit is contained in:
谭凯凯
2024-10-14 10:30:24 +08:00
committed by Tankaikai
parent ebdf2f873a
commit 98942f6ea7
5 changed files with 780 additions and 722 deletions

View File

@@ -65,11 +65,11 @@ public class TbPrintMachineLog implements Serializable {
*/ */
private String printQty; private String printQty;
/** /**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号 * 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
*/ */
private String printMethod; private String printMethod;
/** /**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号,如:[1,2,3] * 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号,如:['refund','handover','queue']
*/ */
private String printType; private String printType;
/** /**

View File

@@ -59,11 +59,11 @@ public class ShopPrintLogDTO implements Serializable {
*/ */
private String printQty; private String printQty;
/** /**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号 * 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
*/ */
private String printMethod; private String printMethod;
/** /**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号,如:[1,2,3] * 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号,如:['refund','handover','queue']
*/ */
private String printType; private String printType;
/** /**

View File

@@ -104,7 +104,7 @@ public class PrintMechineConsumer {
return; return;
} }
String model = StrUtil.isEmpty(it.getPrintMethod()) ? "normal" : it.getPrintMethod(); String model = StrUtil.isEmpty(it.getPrintMethod()) ? "normal" : it.getPrintMethod();
String printerNum = StrUtil.isEmpty(it.getPrintQty()) ? "1" : it.getPrintQty().split("^")[1]; String printerNum = StrUtil.isEmpty(it.getPrintQty()) ? "1" : it.getPrintQty().split("\\^")[1];
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(it.getCategoryList(), "[]"), CategoryInfo.class); List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(it.getCategoryList(), "[]"), CategoryInfo.class);
@@ -137,16 +137,28 @@ public class PrintMechineConsumer {
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model,
TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) { TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
String orderId = orderInfo.getId().toString(); String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) { switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机 case "label": //标签打印机
break; break;
case "cash": //小票打印机 case "cash": //小票打印机
switch (model) { if ("one".equals(model)) {
case "normal": //普通出单 onlyKitchenForYxy(orderId, orderInfo, printerNum, tbPrintMachineWithBLOBs, categoryInfos);
} else if ("normal".equals(model)) {
onlyFrontDeskForYxy(orderId, orderInfo, printerNum, shopInfo, tbPrintMachineWithBLOBs, categoryInfos);
} else if ("all".equals(model)) {
onlyKitchenForYxy(orderId, orderInfo, printerNum, tbPrintMachineWithBLOBs, categoryInfos);
onlyFrontDeskForYxy(orderId, orderInfo, printerNum, shopInfo, tbPrintMachineWithBLOBs, categoryInfos);
}
break;
case "kitchen": //出品打印机
break;
}
}
/**
* 仅打印结算单「前台」
*/
private void onlyFrontDeskForYxy(String orderId, TbOrderInfo orderInfo, String printerNum, TbShopInfo shopInfo, TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, List<CategoryInfo> categoryInfos) {
if ("return".equals(orderInfo.getOrderType())) { if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId)); List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) { if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
@@ -245,29 +257,21 @@ public class PrintMechineConsumer {
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data); PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
} }
} }
}
/**
break; * 仅打印制作单「厨房」
case "one": //一菜一品 */
// if (StrUtil.isNotBlank(orderInfo.getUseType()) && orderInfo.getUseType().equals("postPay") private void onlyKitchenForYxy(String orderId, TbOrderInfo orderInfo, String printerNum, TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, List<CategoryInfo> categoryInfos) {
// && (!orderInfo.getStatus().equals("unpaid"))) { //if (StrUtil.isNotBlank(orderInfo.getUseType()) && orderInfo.getUseType().equals("postPay")
// return; // && (!orderInfo.getStatus().equals("unpaid"))) {
// } // return;
//}
if ("return".equals(orderInfo.getOrderType())) { if ("return".equals(orderInfo.getOrderType())) {
printReturnTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId); printReturnTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId);
return;
} else { } else {
printTicket(Integer.valueOf(orderId), categoryInfos, tbPrintMachineWithBLOBs, orderInfo); printTicket(Integer.valueOf(orderId), categoryInfos, tbPrintMachineWithBLOBs, orderInfo);
// printNormalTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId); // printNormalTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId);
}
break;
case "category": //分类出单
break;
}
break;
case "kitchen": //出品打印机
break;
} }
} }
@@ -522,48 +526,10 @@ public class PrintMechineConsumer {
return true; return true;
} }
/**
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) { * 仅打印结算单「前台」
String orderId = orderInfo.getId().toString(); */
switch (tbPrintMachineWithBLOBs.getSubType()) { private void onlyFrontDeskForFe(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String orderId) {
case "label": //标签打印机
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}", count);
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
});
}
break;
case "cash": //小票打印机
switch (model) {
case "normal": //普通出单
if ("return".equals(orderInfo.getOrderType())) { if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId)); List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) { if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
@@ -617,7 +583,7 @@ public class PrintMechineConsumer {
} else { } else {
cashierCarts = cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final"); List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) { if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>(); List<OrderDetailPO.Detail> detailList = new ArrayList<>();
@@ -668,17 +634,19 @@ public class PrintMechineConsumer {
} }
} }
}
break; /**
case "one": //一菜一品 * 仅打印制作单「厨房」
*/
private void onlyKitchenForFe(String orderId, TbOrderInfo orderInfo, String printerNum, TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, List<CategoryInfo> categoryInfos) {
if (orderInfo.getPayType() != null if (orderInfo.getPayType() != null
&& "postPay".equals(orderInfo.getPayType()) && "postPay".equals(orderInfo.getPayType())
&& !orderInfo.getStatus().equals("unpaid")) { && !orderInfo.getStatus().equals("unpaid")) {
return; return;
} }
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final"); List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) { if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> { cashierCarts.parallelStream().forEach(it -> {
@@ -707,11 +675,55 @@ public class PrintMechineConsumer {
} }
}); });
} }
break;
case "category": //分类出单
break;
} }
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}", count);
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
});
}
break;
case "cash": //小票打印机
if ("one".equals(model)) {
onlyKitchenForFe(orderId, orderInfo, printerNum, tbPrintMachineWithBLOBs, categoryInfos);
} else if ("normal".equals(model)) {
onlyFrontDeskForFe(tbPrintMachineWithBLOBs, orderInfo, shopInfo, printerNum, categoryInfos, orderId);
} else if ("all".equals(model)) {
onlyKitchenForFe(orderId, orderInfo, printerNum, tbPrintMachineWithBLOBs, categoryInfos);
onlyFrontDeskForFe(tbPrintMachineWithBLOBs, orderInfo, shopInfo, printerNum, categoryInfos, orderId);
}
break; break;
case "kitchen": //出品打印机 case "kitchen": //出品打印机
break; break;

View File

@@ -1,7 +1,9 @@
package com.chaozhanggui.system.cashierservice.rabbit.print; package com.chaozhanggui.system.cashierservice.rabbit.print;
import cn.hutool.core.collection.CollUtil;
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 cn.hutool.json.JSONArray;
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
@@ -43,9 +45,41 @@ public abstract class PrinterHandler {
throw new MsgException("打印机配置为空"); throw new MsgException("打印机配置为空");
} }
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class); List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class);
//仅打印后厨-一菜一品
if ("one".equals(printMethod)) {
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else if ("normal".equals(printMethod)) {
//仅打印前台
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
} else if ("all".equals(printMethod)) {
//全部打印 前台+后厨
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else {
log.warn("未知打印类型: {}", printMethod);
}
if (StrUtil.isBlank(machine.getPrintType())) {
return;
}
if (!cn.hutool.json.JSONUtil.isJsonArray(machine.getPrintType())) {
return;
}
JSONArray options = cn.hutool.json.JSONUtil.parseArray(machine.getPrintType());
List<String> optionList = cn.hutool.json.JSONUtil.toList(options, String.class);
//是否包含排队取号
if (!CollUtil.contains(optionList, "queue")) {
return;
}
callNumPrint(machine, printDTO);
if (StrUtil.isBlank(printMethod)) {
throw new MsgException("打印机配置为空");
}
}
switch (printMethod) { /**
case "one": * 仅打印制作单「厨房」
*/
private void onlyKitchen(TbPrintMachine machine, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, List<CategoryInfo> categoryInfos, boolean isReturn) {
tbOrderDetailList.forEach(item -> { tbOrderDetailList.forEach(item -> {
log.info("开始打印退单菜品,商品名:{}", item.getProductName()); log.info("开始打印退单菜品,商品名:{}", item.getProductName());
// 台位费不打印 // 台位费不打印
@@ -71,16 +105,18 @@ public abstract class PrinterHandler {
String remark = StrUtil.isNotBlank(sku.getSpecSnap()) ? sku.getSpecSnap() : ""; String remark = StrUtil.isNotBlank(sku.getSpecSnap()) ? sku.getSpecSnap() : "";
item.setRemark(remark); item.setRemark(remark);
String data;
String voiceJson;
if (isReturn) { if (isReturn) {
returnDishesPrint(orderInfo, item, machine); returnDishesPrint(orderInfo, item, machine);
} else { } else {
normalDishesPrint(orderInfo, item, machine); normalDishesPrint(orderInfo, item, machine);
} }
}); });
break; }
case "normal":
/**
* 仅打印结算单「前台」
*/
private void onlyFrontDesk(TbPrintMachine machine, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, boolean isReturn) {
if (tbOrderDetailList.isEmpty()) { if (tbOrderDetailList.isEmpty()) {
log.info("待打印列表为空"); log.info("待打印列表为空");
return; return;
@@ -114,13 +150,6 @@ public abstract class PrinterHandler {
} }
} }
break;
case "callTicket":
callNumPrint(machine, printDTO);
break;
default:
log.warn("未知打印类型: {}", printMethod);
}
} }
public void handleRequest(TbPrintMachine machine, Boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) { public void handleRequest(TbPrintMachine machine, Boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) {

View File

@@ -103,7 +103,7 @@ public class CloudPrinterService {
String printerNum = StrUtil.isEmpty(tbPrintMachineWithBLOBs.getPrintQty()) ? "1" : tbPrintMachineWithBLOBs.getPrintQty().split("\\^")[1]; String printerNum = StrUtil.isEmpty(tbPrintMachineWithBLOBs.getPrintQty()) ? "1" : tbPrintMachineWithBLOBs.getPrintQty().split("\\^")[1];
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(tbPrintMachineWithBLOBs.getCategoryList(),"[]"), CategoryInfo.class); List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(tbPrintMachineWithBLOBs.getCategoryList(), "[]"), CategoryInfo.class);
switch (tbPrintMachineWithBLOBs.getContentType()) { switch (tbPrintMachineWithBLOBs.getContentType()) {
case "yxyPrinter": case "yxyPrinter":
@@ -136,14 +136,108 @@ public class CloudPrinterService {
*/ */
private Result yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) { private Result yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) {
String orderId = orderInfo.getId().toString(); String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) { switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机 case "label": //标签打印机
break; break;
case "cash": //小票打印机 case "cash": //小票打印机
switch (model) { if ("normal".equals(model)) {
case "normal": //普通出单 onlyFrontDeskForYxy(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else if ("one".equals(model)) {
onlyKitchenForYxy(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else if ("all".equals(model)) {
onlyFrontDeskForYxy(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
onlyKitchenForYxy(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else {
log.error("未知的打印方式");
}
break;
case "kitchen": //出品打印机
break;
}
return Result.success(CodeEnum.SUCCESS);
}
/**
* 仅打印制作单「厨房」
*/
private Result onlyKitchenForYxy(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre, String orderId) {
if (!"one".equals(type)) {
return Result.fail("非出品打印");
}
if (ispre) {
return Result.fail("预结算单不打印菜单");
}
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> details = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(details) && details.size() > 0) {
details.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
return Result.success(CodeEnum.SUCCESS);
} else {
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("", orderInfo.getOrderType().equals("miniapp") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
}
return Result.success(CodeEnum.SUCCESS);
}
/**
* 仅打印结算单「前台」
*/
private Result onlyFrontDeskForYxy(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre, String orderId) {
if (!"normal".equals(type)) { if (!"normal".equals(type)) {
return Result.fail("非小票打印"); return Result.fail("非小票打印");
} }
@@ -272,134 +366,13 @@ public class CloudPrinterService {
} }
} }
break;
case "one": //一菜一品
if (!"one".equals(type)) {
return Result.fail("非出品打印");
}
if (ispre) {
return Result.fail("预结算单不打印菜单");
}
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> details = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(details) && details.size() > 0) {
details.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
return Result.success(CodeEnum.SUCCESS);
} else {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("", orderInfo.getOrderType().equals("miniapp") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
}
break;
case "category": //分类出单
if (!"category".equals(type)) {
return Result.fail("非分类打印");
}
break;
}
break;
case "kitchen": //出品打印机
break;
}
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
/**
private Result fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) { * 仅打印结算单「前台」
String orderId = orderInfo.getId().toString(); */
switch (tbPrintMachineWithBLOBs.getSubType()) { private Result onlyFrontDeskForFe(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre,String orderId) {
case "label": //标签打印机
if (!"label".equals(type)) {
return Result.fail("非标签打印机");
}
if (ispre) {
return Result.fail("预结算单不打印标签");
}
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(it.getCategoryId().toString())
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
});
}
break;
case "cash": //小票打印机
switch (model) {
case "normal": //普通出单
if (!"normal".equals(type)) { if (!"normal".equals(type)) {
return Result.fail("非小票打印"); return Result.fail("非小票打印");
} }
@@ -451,7 +424,7 @@ public class CloudPrinterService {
} }
cashierCarts = new ArrayList<>(); List<TbCashierCart> cashierCarts = new ArrayList<>();
if (ispre) { if (ispre) {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "create"); cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "create");
} else { } else {
@@ -514,9 +487,13 @@ public class CloudPrinterService {
} }
} }
return Result.success(CodeEnum.SUCCESS);
}
break; /**
case "one": //一菜一品 * 仅打印制作单「厨房」
*/
private Result onlyKitchenForFe(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre, String orderId) {
if (!"one".equals(type)) { if (!"one".equals(type)) {
return Result.fail("非出品打印"); return Result.fail("非出品打印");
} }
@@ -524,7 +501,7 @@ public class CloudPrinterService {
if (ispre) { if (ispre) {
return Result.fail("预结算单不打印菜单"); return Result.fail("预结算单不打印菜单");
} }
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final"); List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) { if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> { cashierCarts.parallelStream().forEach(it -> {
@@ -552,14 +529,54 @@ public class CloudPrinterService {
} }
}); });
} }
break; return Result.success(CodeEnum.SUCCESS);
case "category": //分类出单
if (!"category".equals(type)) {
return Result.fail("非分类打印");
}
break;
} }
private Result fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
if (!"label".equals(type)) {
return Result.fail("非标签打印机");
}
if (ispre) {
return Result.fail("预结算单不打印标签");
}
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(it.getCategoryId().toString())
).count();
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
});
}
break;
case "cash": //小票打印机
if ("normal".equals(model)) {
onlyFrontDeskForFe(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else if ("one".equals(model)) {
onlyKitchenForFe(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else if ("all".equals(model)) {
onlyFrontDeskForFe(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
onlyKitchenForFe(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre, orderId);
} else {
log.error("未知的打印方式");
}
break; break;
case "kitchen": //出品打印机 case "kitchen": //出品打印机
break; break;