店铺小票打印记录需求

This commit is contained in:
谭凯凯
2024-10-09 18:25:17 +08:00
committed by Tankaikai
parent 4615e0fae1
commit 2b0ca2b5b8
15 changed files with 714 additions and 56 deletions

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachineLog;
import com.github.pagehelper.PageInfo;
import java.util.Map;
public interface ShopPrintLogService {
PageInfo<TbPrintMachineLog> page(Map<String, Object> params);
/**
* 保存打印记录
* @param config 打印机配置
* @param bizType 业务类型
* @param printContent 打印内容
* @param respJson 打印机响应结果
*/
void save(TbPrintMachine config, String bizType, String printContent, String respJson);
}

View File

@@ -0,0 +1,141 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.dao.TbPrintMachineLogMapper;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachineLog;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopPrintLogDTO;
import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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 ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper, TbPrintMachineLog> implements ShopPrintLogService {
private QueryWrapper<TbPrintMachineLog> getWrapper(Map<String, Object> params) {
TbPrintMachineLog entity = BeanUtil.toBean(params, TbPrintMachineLog.class);
QueryWrapper<TbPrintMachineLog> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(entity.getId() != null, TbPrintMachineLog::getId, entity.getId());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getShopId()), TbPrintMachineLog::getShopId, entity.getShopId());
wrapper.lambda().likeRight(StrUtil.isNotEmpty(entity.getName()), TbPrintMachineLog::getName, entity.getName());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getConnectionType()), TbPrintMachineLog::getConnectionType, entity.getConnectionType());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getContentType()), TbPrintMachineLog::getContentType, entity.getContentType());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getSubType()), TbPrintMachineLog::getSubType, entity.getSubType());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getAddress()), TbPrintMachineLog::getAddress, entity.getAddress());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getPort()), TbPrintMachineLog::getPort, entity.getPort());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getReceiptSize()), TbPrintMachineLog::getReceiptSize, entity.getReceiptSize());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getClassifyPrint()), TbPrintMachineLog::getClassifyPrint, entity.getClassifyPrint());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getTablePrint()), TbPrintMachineLog::getTablePrint, entity.getTablePrint());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getPrintQty()), TbPrintMachineLog::getPrintQty, entity.getPrintQty());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getPrintMethod()), TbPrintMachineLog::getPrintMethod, entity.getPrintMethod());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getPrintType()), TbPrintMachineLog::getPrintType, entity.getPrintType());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getPrintReceipt()), TbPrintMachineLog::getPrintReceipt, entity.getPrintReceipt());
wrapper.lambda().eq(entity.getFailFlag() != null, TbPrintMachineLog::getFailFlag, entity.getFailFlag());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getRespCode()), TbPrintMachineLog::getRespCode, entity.getRespCode());
wrapper.lambda().like(StrUtil.isNotEmpty(entity.getRespMsg()), TbPrintMachineLog::getRespMsg, entity.getRespMsg());
wrapper.lambda().eq(entity.getCreateUserId() != null, TbPrintMachineLog::getCreateUserId, entity.getCreateUserId());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getCreateUserName()), TbPrintMachineLog::getCreateUserName, entity.getCreateUserName());
wrapper.lambda().eq(StrUtil.isNotEmpty(entity.getTaskId()), TbPrintMachineLog::getTaskId, entity.getTaskId());
wrapper.lambda().orderByDesc(TbPrintMachineLog::getId);
return wrapper;
}
@Override
public PageInfo<TbPrintMachineLog> page(Map<String, Object> params) {
MapProxy mapProxy = MapProxy.create(params);
Integer pageNum = mapProxy.getInt("pageNum",1);
Integer pageSize = mapProxy.getInt("pageSize",10);
PageInfo<TbPrintMachineLog> pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> baseMapper.selectList(getWrapper(params)));
return pageInfo;
}
/**
* 保存打印记录
*
* @param config 打印机配置
* @param bizType 业务类型
* @param printContent 打印内容
* @param respJson 打印机响应结果
*/
@Override
@Async
public void save(TbPrintMachine config, String bizType, String printContent, String respJson) {
if (config == null) {
return;
}
TbPrintMachineLog entity = new TbPrintMachineLog();
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);
}
String taskId = resp.getJSONObject("data").getStr("orderId");
entity.setTaskId(taskId);
} 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(new Date());
if(failFlag == 0){
entity.setPrintTime(entity.getCreateTime());
}
entity.setFailFlag(failFlag);
entity.setRespCode(respCode);
entity.setRespMsg(respMsg);
super.save(entity);
}
private ShopPrintLogDTO convertToDTO(TbPrintMachineLog entity) {
ShopPrintLogDTO dto = new ShopPrintLogDTO();
BeanUtil.copyProperties(entity, ShopPrintLogDTO.class);
return dto;
}
}