打印完善
This commit is contained in:
parent
c7f8f467f0
commit
5b9998d506
|
|
@ -52,7 +52,7 @@ public class PrintMqListener {
|
|||
throw new RuntimeException("订单信息不存在");
|
||||
}
|
||||
|
||||
getPrintMachine(1L, "cash", "one", "one").forEach(machine -> {
|
||||
getPrintMachine(1L, "cash", "one", "order").forEach(machine -> {
|
||||
printerHandler.handleRequest(machine, orderInfo, null);
|
||||
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public class OrderDetail implements Serializable {
|
|||
* 数量
|
||||
*/
|
||||
private BigDecimal num;
|
||||
|
||||
/**
|
||||
* 打包数量
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.czg.service.account.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 订单状态枚举类
|
||||
*/
|
||||
@Getter
|
||||
public enum OrderStatusEnums {
|
||||
|
||||
|
||||
UNPAID("unpaid", "待支付"),
|
||||
IN_PRODUCTION("in_production", "制作中"),
|
||||
WAIT_OUT("wait_out", "待取餐"),
|
||||
DONE("done", "订单完成"),
|
||||
REFUNDING("refunding", "申请退单"),
|
||||
REFUND("refund", "退单"),
|
||||
PART_REFUND("part_refund", "部分退单"),
|
||||
CANCELLED("cancelled", "取消订单");
|
||||
|
||||
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
OrderStatusEnums(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl{
|
|||
protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
|
||||
String remark = orderDetail.getRemark();
|
||||
String content = buildDishPrintData(true, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), remark, orderDetail.getProGroupInfo());
|
||||
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getReturnNum(), remark, orderDetail.getProGroupInfo());
|
||||
sendPrintRequest(machine.getAddress(), content, null,"1");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.czg.product.service.ProdSkuService;
|
|||
import com.czg.product.service.ProductService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.enums.OrderStatusEnums;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
|
|
@ -74,12 +75,14 @@ public abstract class PrinterHandler {
|
|||
protected ProdSkuService prodSkuService;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class PrintDetailInfo {
|
||||
private boolean isPrint;
|
||||
private boolean isReturn;
|
||||
// private boolean isReturn;
|
||||
private long orderId;
|
||||
private long detailId;
|
||||
private BigDecimal printNum;
|
||||
private BigDecimal printReturnNum;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
|
@ -143,9 +146,9 @@ public abstract class PrinterHandler {
|
|||
|
||||
protected List<OrderDetail> getCanPrintOrderDetails(boolean partPrint, Long orderId, List<OrderDetail> tbOrderDetailList, List<?> categoryIds) {
|
||||
List<Object> detailList = redisService.lGet(RedisCst.getPrintOrderDetailKey(orderId), 0, -1);
|
||||
Map<String, PrintDetailInfo> detailMap = detailList.stream().collect(Collectors.toMap(i -> {
|
||||
Map<Long, PrintDetailInfo> detailMap = detailList.stream().collect(Collectors.toMap(i -> {
|
||||
if (i instanceof PrintDetailInfo i2) {
|
||||
return i2.getDetailId() + "_" + i2.isReturn;
|
||||
return i2.getDetailId();
|
||||
}
|
||||
throw new RuntimeException("转换orderDetail失败");
|
||||
}, i -> (PrintDetailInfo) i));
|
||||
|
|
@ -157,14 +160,14 @@ public abstract class PrinterHandler {
|
|||
.stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true));
|
||||
|
||||
ArrayList<OrderDetail> orderDetails = new ArrayList<>();
|
||||
ArrayList<String> status = CollectionUtil.newArrayList("refunding", "part-refund", "refund");
|
||||
tbOrderDetailList.forEach(item -> {
|
||||
boolean isReturn = status.contains(item.getStatus());
|
||||
PrintDetailInfo printDetailInfo = detailMap.get(item.getId() + "_" + isReturn);
|
||||
PrintDetailInfo printDetailInfo = detailMap.get(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)) {
|
||||
item.setReturnNum(item.getReturnNum() == null ? BigDecimal.ZERO : item.getReturnNum());
|
||||
if (printDetailInfo != null) {
|
||||
item.setNum(item.getNum().subtract(printDetailInfo.getPrintNum()));
|
||||
item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintNum()));
|
||||
}
|
||||
orderDetails.add(item);
|
||||
}
|
||||
|
|
@ -225,13 +228,23 @@ public abstract class PrinterHandler {
|
|||
* 仅打印制作单「厨房」
|
||||
*/
|
||||
private void onlyKitchen(PrintMachine machine, OrderInfo orderInfo, List<OrderDetail> tbOrderDetailList) {
|
||||
// 判断订单是否是先付费或者已结算
|
||||
if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) {
|
||||
log.warn("此订单未支付, 订单信息: {}", orderInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
List<?> categoryIds = JSONObject.parseObject(StrUtil.emptyToDefault(machine.getCategoryIds(), "[]"), List.class);
|
||||
if (StrUtil.isEmpty(machine.getClassifyPrint())) {
|
||||
log.error("分类打印是空, classifyPrint: {}", machine.getClassifyPrint());
|
||||
return;
|
||||
}
|
||||
|
||||
// 已打印详情信息
|
||||
ArrayList<PrintDetailInfo> printDetailInfos = new ArrayList<>();
|
||||
Map<Long, OrderDetail> detailMap = tbOrderDetailList.stream().collect(Collectors.toMap(OrderDetail::getId, i -> i));
|
||||
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 -> {
|
||||
log.info("开始打印菜品,商品名:{}", item.getProductName());
|
||||
Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0);
|
||||
|
|
@ -268,18 +281,33 @@ public abstract class PrinterHandler {
|
|||
|
||||
// String remark = StrUtil.isNotBlank(sku.getSpecInfo()) ? sku.getSpecInfo() : "";
|
||||
// item.setRemark(remark);
|
||||
if (ArrayUtil.contains(new String[]{"refunding", "part-refund", "refund"}, item.getStatus())) {
|
||||
if (item.getReturnNum().compareTo(BigDecimal.ZERO) > 0) {
|
||||
returnDishesPrint(orderInfo, item, machine);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (item.getNum().compareTo(BigDecimal.ZERO) > 0) {
|
||||
normalDishesPrint(orderInfo, item, machine);
|
||||
}
|
||||
|
||||
// 保存已打印信息
|
||||
OrderDetail orderDetail = detailMap.get(item.getId());
|
||||
redisService.leftPush(printKey, new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId())
|
||||
.setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum()));
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅打印结算单「前台」
|
||||
*/
|
||||
private void onlyFrontDesk(PrintMachine machine, OrderInfo orderInfo, List<OrderDetail> tbOrderDetailList) {
|
||||
// 判断订单是否是先付费或者已结算
|
||||
if (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) {
|
||||
log.warn("此订单未支付或已取消, 订单信息: {}", orderInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tbOrderDetailList.isEmpty()) {
|
||||
log.info("待打印列表为空");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
|
|||
@Override
|
||||
protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) {
|
||||
String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(),
|
||||
orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo());
|
||||
orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo());
|
||||
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
|
||||
sendPrintRequest(machine.getAddress(), buildDishPrintData, voiceJson, "1");
|
||||
|
|
|
|||
Loading…
Reference in New Issue