打印状态标识 允许重新操作

This commit is contained in:
2025-12-29 14:26:51 +08:00
parent 5d9c01f427
commit ff09e8e92b
2 changed files with 19 additions and 46 deletions

View File

@@ -30,9 +30,6 @@ public class PrintMqListener {
@Resource
private FunUtil funUtil;
// 注入自定义线程池(建议单独配置,避免使用默认线程池)
@Resource
private ThreadPoolTaskExecutor asyncExecutor;
@Lazy
@Resource
private PrinterHandler printerHandler;
@@ -64,37 +61,10 @@ public class PrintMqListener {
}
Boolean printOrder = jsonObject.getBoolean("printOrder");
funUtil.runFunAndCheckKey(() -> {
printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER, null);
return null;
}, RedisCst.getLockKey("orderPrint", orderId));
});
// // 使用异步线程池执行延迟任务,不阻塞当前消费者线程
// CompletableFuture.runAsync(() -> {
// try {
// // 延迟3秒处理
// TimeUnit.SECONDS.sleep(3);
// // 执行核心打印逻辑
// invokeFun("orderPrint", "java.order", req, (data) -> {
// JSONObject jsonObject = JSONObject.parseObject(data);
// String orderId = jsonObject.getString("orderId");
// if (orderId == null) {
// throw new RuntimeException("订单打印失败未传递orderId");
// }
// Boolean printOrder = jsonObject.getBoolean("printOrder");
// funUtil.runFunAndCheckKey(() -> {
// printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
// return null;
// }, RedisCst.getLockKey("orderPrint", orderId));
// });
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// // 记录中断日志
// log.warn("打印任务被中断req:{}", req, e);
// } catch (Exception e) {
// // 记录业务异常日志
// log.error("打印任务处理失败req:{}", req, e);
// }
// }, asyncExecutor);
}
/**
@@ -102,14 +72,14 @@ public class PrintMqListener {
*/
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE})
public void handoverPrint(String id) {
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.HANDOVER));
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.HANDOVER, null));
}
/**
* 交班打印
* 叫号打印
*/
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.CALL_TABLE_PRINT_QUEUE})
public void callTablePrint(String id) {
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.CALL));
invokeFun("handoverPrint", "java.order", id, (data) -> printerHandler.handler(data, PrinterHandler.PrintTypeEnum.CALL, null));
}
}

View File

@@ -2,7 +2,6 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.core.thread.ThreadUtil;
@@ -12,18 +11,15 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.czg.account.entity.PrintMachine;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.service.OrderInfoService;
import com.czg.order.entity.PrintMachineLog;
import com.czg.order.service.PrintMachineLogService;
import com.czg.service.order.mapper.PrintMachineLogMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -38,7 +34,7 @@ import java.util.*;
@Slf4j
@Service
@RequiredArgsConstructor
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService{
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService {
//请求地址
private static final String URL_STR = "https://ioe.car900.com/v1/openApi/dev/customPrint.json";
//APPID
@@ -53,6 +49,10 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
public static final String USER = "chaozhanggui2022@163.com";//*必填*:账号名
public static final String UKEY = "UfWkhXxSkeSSscsU";//*必填*: 飞鹅云后台注册账号后生成的UKEY 【备注这不是填打印机的KEY】
public static final String SN = "960238952";//*必填*打印机编号必须要在管理后台里添加打印机或调用API接口添加之后才能调用API
@Resource
private OrderInfoService orderInfoService;
/**
* 获取TOKEN值
*
@@ -77,10 +77,10 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
System.out.println("token" + token);
Map<String, String> finalMap = new HashMap<>();
finalMap.put("ENCODE", encode.toString());
System.out.println("+++++++++++++++" + token + APP_SECRET);
finalMap.put("TOKEN", SecureUtil.md5(token + APP_SECRET).toUpperCase());
return finalMap;
}
/**
* 检查打印状态
*
@@ -106,9 +106,11 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
return HttpUtil.get("https://ioe.car900.com/v1/openApi/dev/findOrder.json", paramMap, 1000 * 5);
}
private static String signature(String USER, String UKEY, String STIME) {
return DigestUtils.sha1Hex(USER + UKEY + STIME);
}
/**
* 检查飞鹅打印机打印任务是否已打印
*
@@ -135,6 +137,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
}
return ret;
}
/**
* 检查飞鹅打印机是否在线
*
@@ -161,6 +164,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
}
return msg;
}
/**
* 保存打印记录
*
@@ -170,6 +174,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
* @param respJson 打印机响应结果
*/
@Async
@Override
public void save(PrintMachine config, String bizType, String printContent, Object respJson) {
if (config == null) {
return;
@@ -266,7 +271,6 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
entity.setPrintTime(null);
entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", entity.getRespMsg()));
}
super.updateById(entity);
}
// 飞鹅云打印机
} else if ("飞鹅".equals(config.getContentType())) {
@@ -291,8 +295,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", msg));
}
}
super.updateById(entity);
}
super.updateById(entity);
}
}