打印修改

This commit is contained in:
张松 2025-03-11 15:05:39 +08:00
parent 278b3930ce
commit efb1ff7f75
8 changed files with 523 additions and 2 deletions

View File

@ -0,0 +1,153 @@
package com.czg.order.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺小票打印记录 实体类
*
* @author zs
* @since 2025-03-11
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PrintMachineLogDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 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;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺id
*/
private String shopId;
/**
* 业务类型
*/
private String bizType;
/**
* 打印人id
*/
private Long createUserId;
/**
* 打印人名称
*/
private String createUserName;
/**
* 打印任务创建时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/**
* 打印任务id用于复查打印状态云想印=orderId
*/
private String taskId;
/**
* 实际打印时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

View File

@ -0,0 +1,160 @@
package com.czg.order.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺小票打印记录 实体类
*
* @author zs
* @since 2025-03-11
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine_log")
public class PrintMachineLog implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 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;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺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 LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

View File

@ -0,0 +1,14 @@
package com.czg.order.service;
import com.mybatisflex.core.service.IService;
import com.czg.order.entity.PrintMachineLog;
/**
* 店铺小票打印记录 服务层
*
* @author zs
* @since 2025-03-11
*/
public interface PrintMachineLogService extends IService<PrintMachineLog> {
}

View File

@ -0,0 +1,14 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.PrintMachineLog;
/**
* 店铺小票打印记录 映射层
*
* @author zs
* @since 2025-03-11
*/
public interface PrintMachineLogMapper extends BaseMapper<PrintMachineLog> {
}

View File

@ -67,8 +67,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
String content = buildDishPrintData(false, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), remark, orderDetail.getProGroupInfo());
sendPrintRequest(machine.getAddress(), content, null,"1");
// shopPrintLogService.save(machine, "新订单", resp[0], resp[1]); // 可以解开注释用于日志存储
// printMachineLogService.save(machine, "新订单", , );
}
@Override

View File

@ -17,6 +17,7 @@ import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.PrintMachineLogService;
import com.czg.product.entity.ProdSku;
import com.czg.product.entity.Product;
import com.czg.product.service.ProdSkuService;
@ -59,6 +60,8 @@ public abstract class PrinterHandler {
protected OrderInfoService orderInfoService;
@Resource
protected RedisService redisService;
@Resource
protected PrintMachineLogService printMachineLogService;
@DubboReference
protected SysParamsService sysParamsService;

View File

@ -0,0 +1,171 @@
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.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
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.order.entity.PrintMachineLog;
import com.czg.order.service.PrintMachineLogService;
import com.czg.service.order.mapper.PrintMachineLogMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
/**
* 店铺小票打印记录ServiceImpl
*
* @author tankaikai
* @since 2024-10-8 17:10
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService{
/**
* 保存打印记录
*
* @param config 打印机配置
* @param bizType 业务类型
* @param printContent 打印内容
* @param respJson 打印机响应结果
*/
@Async
public void save(PrintMachine config, String bizType, String printContent, String respJson) {
// if (config == null) {
// return;
// }
// PrintMachineLog entity = new PrintMachineLog();
// BeanUtil.copyProperties(config, entity);
// int failFlag = 0;
// String respCode = "0";
// String respMsg = "打印中";
//
// Map<Integer, String> yxxStatusMap = MapUtil.builder(0, "离线(设备上线后自动补打)").put(1, "在线").put(2, "获取失败").put(3, "未激活").put(4, "设备已禁用").build();
// // 云想印
// if ("yxyPrinter".equals(config.getContentType())) {
// cn.hutool.json.JSONObject resp = JSONUtil.parseObj(respJson);
// int code = resp.getInt("code");
// cn.hutool.json.JSONObject data = resp.getJSONObject("data").getJSONObject("data");
// //设备状态0: 离线, 1: 在线, 2: 获取失败, 3:未激活, 4:设备已禁用
// int status = data.getInt("status");
// if (code != 0) {
// failFlag = 1;
// respCode = code + "";
// respMsg = resp.getStr("msg");
// } else if (status != 1) {
// failFlag = 1;
// respCode = code + "";
//
// respMsg = status + "_" + yxxStatusMap.get(status);
// }
// if (code == 0) {
// String taskId = resp.getJSONObject("data").getStr("orderId");
// entity.setTaskId(taskId);
// }
// // 飞鹅云打印机暂时没有适配先return不做打印记录
// } else if ("fePrinter".equals(config.getContentType())) {
// cn.hutool.json.JSONObject resp = JSONUtil.parseObj(respJson);
// int ret = resp.getInt("ret");
// if (ret != 0) {
// failFlag = 1;
// respCode = ret + "";
// respMsg = resp.getStr("msg");
// } else {
// String printOrderId = resp.getStr("data");
// entity.setTaskId(printOrderId);
// }
// } else {
// // 其他打印机暂时没有适配先return不做打印记录
// return;
// }
// entity.setBizType(bizType);
//// entity.setCreateUserId(config.getCurrentUserId());
//// entity.setCreateUserName(config.getCurrentUserName());
//// if (StrUtil.isNotBlank(config.getCurrentUserNickName())) {
//// entity.setCreateUserName(StrUtil.concat(true, config.getCurrentUserNickName(), " | ", config.getCurrentUserName()));
//// }
// entity.setPrintContent(printContent);
// entity.setCreateTime(DateUtil.date().toLocalDateTime());
// if (failFlag == 0) {
// entity.setPrintTime(entity.getCreateTime());
// }
// entity.setFailFlag(failFlag);
// entity.setRespCode(respCode);
// entity.setRespMsg(respMsg);
// super.save(entity);
//
// // 云想印
// if ("yxyPrinter".equals(config.getContentType())) {
// // 延迟3ms复查打印状态 (用户可以根据设备信息查询到当前设备的在线情况该接口只能提供参考设备的离线状态是在设备离线3分钟后才会生效)
// ThreadUtil.safeSleep(1000 * 5);
// String jsonStr = PrinterUtils.checkPrintStatus(config.getAddress(), entity.getTaskId());
// cn.hutool.json.JSONObject resp = JSONUtil.parseObj(jsonStr);
// int code = resp.getInt("code");
// if (code == 0) {
// cn.hutool.json.JSONObject data = resp.getJSONObject("data");
// boolean status = data.containsKey("status");
// if (!status) {
// return;
// }
// boolean success = data.getBool("status", false);
// if (entity.getFailFlag() == 0 && success) {
// entity.setFailFlag(0);
// entity.setRespMsg("打印成功");
// entity.setPrintTime(entity.getCreateTime());
// } else if (entity.getFailFlag() == 1 && success) {
// entity.setFailFlag(0);
// entity.setPrintTime(new Date());
// entity.setRespMsg("打印成功");
// // 如果设备在线 and 休眠5秒后查询结果是未打印即视为设备已离线云端3分钟后才会同步到离线信息
// } else if (entity.getFailFlag() == 0 && !success) {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg("0_离线(设备上线后自动补打)");
// } else {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", entity.getRespMsg()));
// }
// super.updateById(entity);
// }
// // 飞鹅云打印机
// } else if ("fePrinter".equals(config.getContentType())) {
// ThreadUtil.safeSleep(1000 * 5);
// Boolean success = FeieyunPrintUtil.checkPrintStatus(entity.getTaskId());
// if (success == null) {
// entity.setFailFlag(1);
// entity.setRespMsg("打印失败,未知错误");
// } else if (success) {
// entity.setFailFlag(0);
// entity.setPrintTime(new Date());
// entity.setRespMsg("打印成功");
// } else {
// String msg = FeieyunPrintUtil.checkOnline(entity.getAddress());
// if (msg.indexOf("在线,工作状态正常") > 0) {
// entity.setFailFlag(0);
// entity.setPrintTime(new Date());
// entity.setRespMsg("打印成功");
// } else {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", msg));
// }
// }
// super.updateById(entity);
// }
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.order.mapper.PrintMachineLogMapper">
</mapper>