过滤空值

This commit is contained in:
2026-04-20 15:59:34 +08:00
parent 0d394d5628
commit 660226d133
9 changed files with 250 additions and 61 deletions

View File

@@ -8,6 +8,7 @@ import com.czg.account.entity.PrintMachine;
import com.czg.account.entity.ShopInfo;
import com.czg.account.service.PrintMachineService;
import com.czg.account.service.ShopInfoService;
import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.exception.CzgException;
import com.czg.market.service.OrderInfoService;
@@ -24,6 +25,7 @@ import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
@@ -58,6 +60,8 @@ public class PrintConfig implements ApplicationRunner {
protected ProductService productService;
@Resource
protected RedisService redisService;
@Resource
private RabbitPublisher rabbitPublisher;
public static final Map<String, PrinterHandler> PRINTER_MAP = new ConcurrentHashMap<>();
@@ -114,6 +118,7 @@ public class PrintConfig implements ApplicationRunner {
orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()));
default -> orderDetailList;
};
sendOrderPrintMsg(orderInfo.getShopId(), orderInfo.getId(), placeNum, printTypeEnum + "", orderDetailList, "");
for (PrintMachine machine : getPrintMachine(orderInfo.getShopId(), printTypeEnum)) {
PrinterHandler printer = getPrinter(machine.getBrand());
switch (printTypeEnum) {
@@ -156,10 +161,6 @@ public class PrintConfig implements ApplicationRunner {
});
break;
case PrinterHandler.PrintTypeEnum.ALL_KITCHEN:
Boolean exit = redisService.hasKey(RedisCst.kitchenAll(orderInfo.getId(), machine.getId()));
if (exit) {
break;
}
// 判断订单是否是先付费或者已结算
if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) {
log.warn("此订单未支付, 订单信息: {}", orderInfo.getId());
@@ -171,7 +172,6 @@ public class PrintConfig implements ApplicationRunner {
}
log.info("准备开始打印后厨整单");
printer.allKitchenPrint(orderInfo, allOrderDetailList, machine);
redisService.set(RedisCst.kitchenAll(orderInfo.getId(), machine.getId()), "", 20);
break;
}
}
@@ -240,13 +240,10 @@ public class PrintConfig implements ApplicationRunner {
* 处理退菜退款订单打印
*/
public void kitchenRefundAllHandler(String operator, OrderInfo orderInfo, List<OrderDetail> detailList) {
sendOrderPrintMsg(orderInfo.getShopId(), orderInfo.getId(), null, PrinterHandler.PrintTypeEnum.REFUND_KITCHEN + "", detailList, operator);
//后厨退菜单
getPrintMachine(orderInfo.getShopId(), PrinterHandler.PrintTypeEnum.REFUND_KITCHEN).forEach(machine -> {
// Boolean isPrint = redisService.hasKey(RedisCst.kitchenRefundAll(orderInfo.getId(), machine.getId()));
// if (!isPrint) {
getPrinter(machine.getBrand()).returnKitchenPrint(operator, orderInfo, detailList, machine);
// redisService.set(RedisCst.kitchenRefundAll(orderInfo.getId(), machine.getId()), "", 180);
// }
getPrinter(machine.getBrand()).returnKitchenPrint(operator, orderInfo, detailList, machine);
});
}
@@ -265,9 +262,11 @@ public class PrintConfig implements ApplicationRunner {
OrderInfo orderInfo, List<OrderDetail> detailList) {
//前台退菜单
if ("退菜单".equals(printTitle)) {
sendOrderPrintMsg(orderInfo.getShopId(), orderInfo.getId(), null, PrinterHandler.PrintTypeEnum.RETURN_ORDER + "", detailList, operator);
getPrintMachine(orderInfo.getShopId(), PrinterHandler.PrintTypeEnum.RETURN_ORDER).forEach(machine ->
getPrinter(machine.getBrand()).returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList));
} else if ("退款单".equals(printTitle)) {
sendOrderPrintMsg(orderInfo.getShopId(), orderInfo.getId(), null, PrinterHandler.PrintTypeEnum.REFUND_ORDER + "", detailList, operator);
getPrintMachine(orderInfo.getShopId(), PrinterHandler.PrintTypeEnum.REFUND_ORDER).forEach(machine ->
getPrinter(machine.getBrand()).returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList));
} else {
@@ -281,7 +280,16 @@ public class PrintConfig implements ApplicationRunner {
boolean partPrint = false;
if ("1".equals(machine.getClassifyPrint())) {
partPrint = true;
List categoryIds = JSONObject.parseObject(StrUtil.emptyToDefault(machine.getCategoryIds(), "[]"), List.class);
//617,616,615,614
List<String> categoryIds = List.of();
if (StrUtil.isNotBlank(machine.getCategoryIds())) {
// 按逗号分割,自动去空字符串
categoryIds = Arrays.stream(machine.getCategoryIds().split(","))
.map(String::trim)
.filter(StrUtil::isNotBlank)
.collect(Collectors.toList());
}
if (CollUtil.isEmpty(categoryIds)) {
return Collections.emptyList();
}
@@ -348,5 +356,19 @@ public class PrintConfig implements ApplicationRunner {
return list;
}
private void sendOrderPrintMsg(Long shopId, Long orderId, Integer placeNum, String printType, List<OrderDetail> detailList, String operator) {
FunUtils.safeRunVoid(() -> {
List<OrderDetailPrintDTO> list2 = detailList.stream()
.map(detail -> {
OrderDetailPrintDTO printDTO = new OrderDetailPrintDTO();
// 自动拷贝相同名称的字段
BeanUtils.copyProperties(detail, printDTO);
return printDTO;
}).toList();
rabbitPublisher.sendOrderPrintLocalMsg(shopId, orderId, placeNum, printType, JSONObject.toJSONString(list2), operator);
}, "订单{}消息发送失败,订单信息: {}", printType, orderId);
}
}

View File

@@ -1,19 +1,24 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.czg.config.RabbitPublisher;
import com.czg.excel.ExcelExportUtil;
import com.czg.exception.CzgException;
import com.czg.order.dto.FinanceStsDTO;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.param.FinanceStsQueryParam;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.FinanceStsService;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.print.DayReportPrintDTO;
import com.czg.print.DaySettlePrintDTO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
/**
* @author yjjie
@@ -24,6 +29,8 @@ public class FinanceStsServiceImpl implements FinanceStsService {
@Resource
private ShopOrderStatisticService orderStatisticService;
@Resource
private RabbitPublisher rabbitPublisher;
@Override
public FinanceStsDTO getFinanceSts(FinanceStsQueryParam param) {
@@ -95,6 +102,28 @@ public class FinanceStsServiceImpl implements FinanceStsService {
throw new CzgException("平台不支持");
}
@Override
public void printDayReport(SaleSummaryCountParam param) {
DayReportPrintDTO dayReportPrintDTO = new DayReportPrintDTO();
// 打印经营日报
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), dayReportPrintDTO, "DAY_REPORT");
}
@Override
public void printDaySettle(SaleSummaryCountParam param) {
// 打印日结单
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), buildDaySettlePrint(param), "DAY_ORDER");
}
private Map<String, DayReportPrintDTO> buildDayReportPrint(SaleSummaryCountParam param) {
return null;
}
private Map<String, DaySettlePrintDTO> buildDaySettlePrint(SaleSummaryCountParam param) {
return null;
}
private ShopOrderStatistic getStatisticData(FinanceStsQueryParam param) {
LocalDate today = LocalDate.now();
if (param.getQueryDate().equals(today)) {

View File

@@ -329,12 +329,11 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
.eq(CashierCart::getTableCode, param.getTableCode())
);
if ("after-pay".equals(orderInfo.getPayMode())) {
//
log.info("后付费生成订单{},第{}", orderInfo.getId(), orderInfo.getPlaceNum());
//客看单
printConfig.orderHandler(orderInfo.getId(), PrinterHandler.PrintTypeEnum.GUEST_ORDER, orderInfo.getPlaceNum());
// 消息通知 本地打印机执行
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), 0, 0, orderInfo.getPlaceNum(), true, "后付费打印");
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), 0, 0, orderInfo.getPlaceNum(), "后付费打印");
} else {
redisService.set(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId(), "", 60 * 15);
}
@@ -1296,14 +1295,14 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
}
if (payType != PayEnums.BACK_SCAN) {
// 事务成功提交后执行消息发送
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, isPrint, "事务环境打印");
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, "事务环境打印");
}
}
});
} else {
if (payType != PayEnums.BACK_SCAN) {
// 非事务环境下直接发送(兼容无事务场景)
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, isPrint, "非事务环境打印");
rabbitPublisher.sendOrderPrintMsg(orderId, !"after-pay".equals(payMode) ? 1 : 0, 1, 1, "非事务环境打印");
}
// log.info("非事务环境下,直接发送订单{}打印消息", orderId);

View File

@@ -114,7 +114,7 @@ public class OrderPayServiceImpl implements OrderPayService {
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay);
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, orderInfo.getIsPrint() == 1, "0元付款");
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, "0元付款");
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
throw new PaySuccessException("支付成功");
}
@@ -355,7 +355,7 @@ public class OrderPayServiceImpl implements OrderPayService {
if (mapCzgResult.getCode() == 200) {
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN);
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, orderInfo.getIsPrint() == 1, "扫码收款");
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId(), !"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0, 1, 1, "扫码收款");
} else {
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
@@ -515,14 +515,12 @@ public class OrderPayServiceImpl implements OrderPayService {
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
orderInfoService.updateById(orderInfo);
//退款后续 退款单/退菜单
if (param.isPrint()) {
String finalPrintTitle = printTitle;
boolean finalIsPay = isPay;
FunUtils.safeRunVoid(() -> printConfig.refundOrderHandler(finalPrintTitle, StrUtil.isNotBlank(param.getOperator()) ? param.getOperator() : ""
, finalIsPay ? param.getRefundAmount().toPlainString() : "0"
, param.getRefundReason(), orderInfo.getRefundType(), orderInfo, param.getRefundDetails()),
"订单id:{} 退款,前台打印消息失败", orderInfo.getId());
}
String finalPrintTitle = printTitle;
boolean finalIsPay = isPay;
FunUtils.safeRunVoid(() -> printConfig.refundOrderHandler(finalPrintTitle, StrUtil.isNotBlank(param.getOperator()) ? param.getOperator() : ""
, finalIsPay ? param.getRefundAmount().toPlainString() : "0"
, param.getRefundReason(), orderInfo.getRefundType(), orderInfo, param.getRefundDetails()),
"订单id:{} 退款,前台打印消息失败", orderInfo.getId());
//后厨退菜单
FunUtils.safeRunVoid(() -> printConfig.kitchenRefundAllHandler(StrUtil.isNotBlank(param.getOperator()) ? param.getOperator() : "", orderInfo, param.getRefundDetails()),
"订单id:{} 退款,后厨退菜单打印消息失败", orderInfo.getId());