打印移动到order模块

This commit is contained in:
张松
2025-02-26 17:32:55 +08:00
parent 48e3ab425b
commit d7c4f05960
25 changed files with 264 additions and 120 deletions

View File

@@ -7,7 +7,6 @@ import com.czg.account.vo.LoginVO;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher;
import com.czg.mq.PrintMqListener;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
@@ -53,13 +52,11 @@ public class AuthorizationController {
return CzgResult.success();
}
@Resource
PrintMqListener printMqListener;
@Resource
RabbitPublisher rabbitPublisher;
@GetMapping("test")
public CzgResult<?> login() {
rabbitPublisher.sendOrderPrintMsg("1");
rabbitPublisher.sendOrderPrintMsg("552");
// printMqListener.orderPrint("1");
// return CzgResult.success(Map.of("token", StpKit.USER.getShopId()));
return CzgResult.success();

View File

@@ -0,0 +1,14 @@
package com.czg.controller.admin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 存酒管理
* @author Administrator
*/
@RestController
@RequestMapping
public class ShopStorageGoodController {
}

View File

@@ -1,108 +0,0 @@
package com.czg.mq;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.MqLog;
import com.czg.account.entity.PrintMachine;
import com.czg.account.service.MqLogService;
import com.czg.account.service.PrintMachineService;
import com.czg.config.RabbitConstants;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.service.account.print.PrinterHandler;
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.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
/**
* 打印mq消息处理器
* @author Administrator
*/
@Component
@Slf4j
public class PrintMqListener {
@DubboReference
private OrderInfoService orderInfoService;
@Resource
private MqLogService mqLogService;
@Resource
private PrintMachineService printMachineService;
@Lazy
@Resource
private PrinterHandler printerHandler;
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE})
public void orderPrint(String orderId) {
long startTime = DateUtil.date().getTime();
log.info("接收到订单打印消息:{}", orderId);
MqLog mqLog = new MqLog().setQueue(RabbitConstants.Queue.ORDER_PRINT_QUEUE).setMsg(orderId).setType("orderPrint").setPlat("java.account").setCreateTime(DateUtil.date().toLocalDateTime());
try {
OrderInfo orderInfo = orderInfoService.getById(orderId);
if (orderInfo == null) {
log.error("订单信息不存在, {}", orderId);
throw new RuntimeException("订单信息不存在");
}
getPrintMachine(orderInfo.getShopId(), "cash", "all", "order").forEach(machine -> {
printerHandler.handleRequest(machine, orderInfo, null);
// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
});
}catch (Exception e) {
log.error("订单打印失败", e);
mqLog.setErrInfo(JSONObject.toJSONString(e));
mqLog.setDuration(DateUtil.date().getTime() - startTime);
mqLog.setFailTime(DateUtil.date().toLocalDateTime());
mqLogService.save(mqLog);
}
}
/**
* 获取可用打印机
* @param shopId 店铺id
* @param subType 打印类型分类label标签 cash小票 kitchen出品
* @param printMethod 打印方式 all-全部打印 normal-仅打印结账单「前台」one-仅打印制作单「厨房」
* @param printType 打印类型JSON数组 refund-确认退款单 handover-交班单 queue-排队取号
* @return 打印机列表
*/
private List<PrintMachine> getPrintMachine(Long shopId, String subType, String printMethod, String printType) {
QueryWrapper wrapper = new QueryWrapper()
.eq(PrintMachine::getStatus, 1)
.eq(PrintMachine::getShopId, shopId)
.eq(PrintMachine::getSubType, subType)
.eq(PrintMachine::getConnectionType, "network");
if (StrUtil.isNotEmpty(printMethod)) {
wrapper.in(PrintMachine::getPrintMethod, Arrays.asList(printMethod, "all"));
}
if ("callTicket".equals(printType)) {
printType = "queue";
}
if (StrUtil.isNotEmpty(printType)) {
wrapper.like(PrintMachine::getPrintType, printType);
}
List<PrintMachine> list = printMachineService.list(wrapper);
for (PrintMachine item : list) {
//实际打印以传递的参数为准
item.setPrintMethod(printMethod);
}
if (list.isEmpty()) {
log.error("店铺未配置打印机店铺id: {}", shopId);
return list;
}
log.info("打印机列表: {}", list);
return list;
}
}