打印日志
This commit is contained in:
@@ -31,38 +31,43 @@ public class PrintMachineLog implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id
|
* 主键ID
|
||||||
*/
|
*/
|
||||||
@Id(keyType = KeyType.Auto)
|
@Id(keyType = KeyType.Auto)
|
||||||
private Long id;
|
private Integer id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
|
* 店铺Id
|
||||||
*/
|
*/
|
||||||
private String connectionType;
|
private Long shopId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
|
* 设备名称
|
||||||
*/
|
|
||||||
private String contentType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印小票 标签-label 出品-kitchen 小票-cash
|
|
||||||
*/
|
|
||||||
private String subType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印机名称
|
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IP地址/打印机编号
|
* 连接方式 USB、云打印、局域网
|
||||||
|
*/
|
||||||
|
private String connectionType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印类型 label标签 cash小票
|
||||||
|
*/
|
||||||
|
private String printType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印机品牌 飞鹅/云想印
|
||||||
|
*/
|
||||||
|
private String brand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ip地址/MAC地址
|
||||||
*/
|
*/
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 端口/打印机秘钥
|
* 端口
|
||||||
*/
|
*/
|
||||||
private String port;
|
private String port;
|
||||||
|
|
||||||
@@ -72,34 +77,14 @@ public class PrintMachineLog implements Serializable {
|
|||||||
private String receiptSize;
|
private String receiptSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类打印 0-所以 1-部分分类 2-部分商品
|
* 打印数量
|
||||||
*/
|
*/
|
||||||
private String classifyPrint;
|
private Integer printNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桌台打印 0-所有 1-部分
|
* 打印内容类型
|
||||||
*/
|
*/
|
||||||
private String tablePrint;
|
private String printContentType;
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]
|
|
||||||
*/
|
|
||||||
private String printQty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
|
|
||||||
*/
|
|
||||||
private String printMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号,如:[1,2,3]
|
|
||||||
*/
|
|
||||||
private String printType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印票据 0-全部打印 1-仅厨房 2-仅前台
|
|
||||||
*/
|
|
||||||
private String printReceipt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印内容
|
* 打印内容
|
||||||
@@ -107,33 +92,7 @@ public class PrintMachineLog implements Serializable {
|
|||||||
private String printContent;
|
private String printContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺id
|
* 打印任务id,用于复查打印状态
|
||||||
*/
|
|
||||||
private String shopId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务类型
|
|
||||||
*/
|
|
||||||
private String bizType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印人id
|
|
||||||
*/
|
|
||||||
private Long createUserId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印人名称
|
|
||||||
*/
|
|
||||||
private String createUserName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印任务创建时间
|
|
||||||
*/
|
|
||||||
@Column(onInsertValue = "now()")
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印任务id,用于复查打印状态,云想印=orderId
|
|
||||||
*/
|
*/
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
@@ -157,4 +116,15 @@ public class PrintMachineLog implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String respMsg;
|
private String respMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@Column(onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.czg.order.service;
|
package com.czg.order.service;
|
||||||
|
|
||||||
import com.czg.account.entity.PrintMachine;
|
import com.czg.account.entity.PrintMachine;
|
||||||
import com.mybatisflex.core.service.IService;
|
|
||||||
import com.czg.order.entity.PrintMachineLog;
|
import com.czg.order.entity.PrintMachineLog;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺小票打印记录 服务层。
|
* 店铺小票打印记录 服务层。
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.czg.service.order.mapper;
|
package com.czg.service.order.mapper;
|
||||||
|
|
||||||
import com.mybatisflex.core.BaseMapper;
|
|
||||||
import com.czg.order.entity.PrintMachineLog;
|
import com.czg.order.entity.PrintMachineLog;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺小票打印记录 映射层。
|
* 店铺小票打印记录 映射层。
|
||||||
|
|||||||
@@ -2,29 +2,22 @@ package com.czg.service.order.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.account.entity.PrintMachine;
|
import com.czg.account.entity.PrintMachine;
|
||||||
import com.czg.config.RedisCst;
|
|
||||||
import com.czg.market.service.OrderInfoService;
|
|
||||||
import com.czg.order.entity.OrderInfo;
|
|
||||||
import com.czg.order.entity.PrintMachineLog;
|
import com.czg.order.entity.PrintMachineLog;
|
||||||
import com.czg.order.service.PrintMachineLogService;
|
import com.czg.order.service.PrintMachineLogService;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import com.czg.service.order.mapper.PrintMachineLogMapper;
|
import com.czg.service.order.mapper.PrintMachineLogMapper;
|
||||||
import com.czg.service.order.print.FeiPrinter;
|
import com.czg.service.order.print.FeiPrinter;
|
||||||
import com.czg.service.order.print.YxyPrinter;
|
import com.czg.service.order.print.YxyPrinter;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -41,19 +34,14 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService {
|
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderInfoService orderInfoService;
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
private YxyPrinter yxyPrinter;
|
private YxyPrinter yxyPrinter;
|
||||||
@Lazy
|
@Lazy
|
||||||
@Resource
|
@Resource
|
||||||
private FeiPrinter feiPrinter;
|
private FeiPrinter feiPrinter;
|
||||||
@Resource
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
Map<Integer, String> yxxStatusMap = Map.of(
|
Map<Integer, String> yxxStatusMap = Map.of(
|
||||||
0, "离线(设备上线后自动补打)",
|
0, "离线(设备上线后自动补打)",
|
||||||
@@ -125,7 +113,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
|
|||||||
// 其他打印机暂时没有适配,先return不做打印记录
|
// 其他打印机暂时没有适配,先return不做打印记录
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
entity.setBizType(bizType);
|
entity.setPrintContentType(bizType);
|
||||||
entity.setPrintContent(printContent);
|
entity.setPrintContent(printContent);
|
||||||
entity.setCreateTime(DateUtil.date().toLocalDateTime());
|
entity.setCreateTime(DateUtil.date().toLocalDateTime());
|
||||||
if (failFlag == 0) {
|
if (failFlag == 0) {
|
||||||
@@ -135,7 +123,7 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
|
|||||||
entity.setRespCode(respCode);
|
entity.setRespCode(respCode);
|
||||||
entity.setRespMsg(respMsg);
|
entity.setRespMsg(respMsg);
|
||||||
super.save(entity);
|
super.save(entity);
|
||||||
ThreadUtil.execAsync(() -> checkPrintStatus(orderId, config, entity));
|
ThreadUtil.execAsync(() -> checkPrintStatus(config, entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,11 +138,10 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
|
|||||||
/**
|
/**
|
||||||
* 打印机状态查询(解决 retryFuture 爆红问题 + 虚拟线程 + 轮询重试)
|
* 打印机状态查询(解决 retryFuture 爆红问题 + 虚拟线程 + 轮询重试)
|
||||||
*
|
*
|
||||||
* @param orderId 订单Id
|
* @param config 打印机配置
|
||||||
* @param config 打印机配置
|
* @param entity 打印日志实体
|
||||||
* @param entity 打印日志实体
|
|
||||||
*/
|
*/
|
||||||
public void checkPrintStatus(Long orderId, PrintMachine config, PrintMachineLog entity) {
|
public void checkPrintStatus(PrintMachine config, PrintMachineLog entity) {
|
||||||
// 最大重试次数
|
// 最大重试次数
|
||||||
int maxRetryTimes = 5;
|
int maxRetryTimes = 5;
|
||||||
AtomicInteger executedTimes = new AtomicInteger(0);
|
AtomicInteger executedTimes = new AtomicInteger(0);
|
||||||
@@ -249,7 +236,6 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
|
|||||||
//仅当是最后一次任务时,才执行更新操作
|
//仅当是最后一次任务时,才执行更新操作
|
||||||
if (isLastTask) {
|
if (isLastTask) {
|
||||||
super.updateById(entity);
|
super.updateById(entity);
|
||||||
// updateOrderEntity(orderId, config, isPrintSuccess);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -269,26 +255,6 @@ public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMappe
|
|||||||
registerShutdownHookOnce();
|
registerShutdownHookOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新状态
|
|
||||||
*/
|
|
||||||
private void updateOrderEntity(Long orderId, PrintMachine config, boolean isPrintSuccess) {
|
|
||||||
redisService.runFunAndCheckKey(() -> {
|
|
||||||
OrderInfo orderInfo = orderInfoService.getOne(query().select(OrderInfo::getPrintStatus).eq(OrderInfo::getId, orderId));
|
|
||||||
if (orderInfo == null) {
|
|
||||||
orderInfo = new OrderInfo();
|
|
||||||
}
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("id", config.getId());
|
|
||||||
jsonObject.put("name", config.getName());
|
|
||||||
jsonObject.put("time", LocalDateTimeUtil.formatNormal(LocalDateTime.now()));
|
|
||||||
orderInfo.upPrintStatus(jsonObject, isPrintSuccess);
|
|
||||||
orderInfoService.update(orderInfo, query().eq(OrderInfo::getId, orderId));
|
|
||||||
return orderInfo;
|
|
||||||
}, RedisCst.getLockKey("UP_ORDER_PRINT", orderId));
|
|
||||||
redisService.del("order:print:" + orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一更新打印日志实体
|
* 统一更新打印日志实体
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user