Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-22 15:25:04 +08:00
commit f5cef10c40
8 changed files with 192 additions and 56 deletions

View File

@ -255,7 +255,7 @@ public class PrintMechineConsumer {
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType()); String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data); PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
} }
} }
} }
@ -630,7 +630,7 @@ public class PrintMechineConsumer {
} }
log.error("打印数据2>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO)); log.error("打印数据2>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType); FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType, printerNum);
} }
} }

View File

@ -1,12 +1,17 @@
package com.chaozhanggui.system.cashierservice.rabbit.print; package com.chaozhanggui.system.cashierservice.rabbit.print;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO; import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper; import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper; import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
@ -15,6 +20,7 @@ import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil; import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -25,6 +31,14 @@ import java.util.List;
@Slf4j @Slf4j
public class FeiPrinter extends PrinterHandler { public class FeiPrinter extends PrinterHandler {
@Resource
private TbCallQueueMapper tbCallQueueMapper;
@Resource
private TbCallTableMapper tbCallTableMapper;
@Value("${wx.mini.page.call}")
private String callPageUrl;
private final MPOrderInfoMapper mPOrderInfoMapper; private final MPOrderInfoMapper mPOrderInfoMapper;
private final MpShopInfoMapper mpShopInfoMapper; private final MpShopInfoMapper mpShopInfoMapper;
private final MPOrderDetailMapper mPOrderDetailMapper; private final MPOrderDetailMapper mPOrderDetailMapper;
@ -71,7 +85,12 @@ public class FeiPrinter extends PrinterHandler {
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString()); "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "退款单"; String printType = "退款单";
log.error("打印数据3>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO)); log.error("打印数据3>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType); String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
StrUtil.blankToDefault(machine.getPrintQty(), "");
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType, printerNum);
shopPrintLogService.save(machine, "退款单", resp[0], resp[1]); shopPrintLogService.save(machine, "退款单", resp[0], resp[1]);
} }
@ -86,13 +105,41 @@ public class FeiPrinter extends PrinterHandler {
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString()); "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "结算单"; String printType = "结算单";
log.error("打印数据1>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO)); log.error("打印数据1>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType); String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType, printerNum);
shopPrintLogService.save(machine, "结算单", resp[0], resp[1]); shopPrintLogService.save(machine, "结算单", resp[0], resp[1]);
} }
@Override @Override
protected void callNumPrint(TbPrintMachine machine, CallNumPrintDTO printDTO) { protected void callNumPrint(TbPrintMachine machine, CallNumPrintDTO printDTO) {
log.error("未实现打印方法"); log.error("未实现打印方法");
TbCallQueue queue = tbCallQueueMapper.selectById(printDTO.getCallQueueId());
if (queue == null) {
log.warn("叫号记录不存在");
return;
}
TbCallTable tbCallTable = tbCallTableMapper.selectById(queue.getCallTableId());
TbShopInfo shopInfo = mpShopInfoMapper.selectById(queue.getShopId());
CallNumPrintPO po = new CallNumPrintPO();
po.setCallNum(queue.getCallNum());
po.setShopName(shopInfo.getShopName());
po.setTableName(tbCallTable.getName());
po.setTableNote(tbCallTable.getNote());
po.setPreNum(tbCallQueueMapper.selectCount(new LambdaQueryWrapper<TbCallQueue>()
.eq(TbCallQueue::getShopId, queue.getShopId())
.eq(TbCallQueue::getCallTableId, queue.getCallTableId())
.lt(TbCallQueue::getId, queue.getId())
.in(TbCallQueue::getState, 0, 1)).toString());
po.setCallNum(queue.getCallNum());
po.setCodeUrl(StrUtil.format(callPageUrl, queue.getShopId(), queue.getId()));
po.setTakeTime(queue.getCreateTime());
po.setShopNote(StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum()));
String data = FeieyunPrintUtil.getCallNumPrintData(po);
String resp = FeieyunPrintUtil.print(data, machine.getAddress(), "1");
shopPrintLogService.save(machine, "叫号单", data, resp);
} }
} }

View File

@ -41,9 +41,10 @@ public abstract class PrinterHandler {
protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) { protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) {
String printMethod = machine.getPrintMethod(); String printMethod = machine.getPrintMethod();
if (StrUtil.isBlank(printMethod)) { if (StrUtil.isBlank(printMethod) && StrUtil.isBlank(machine.getPrintType())) {
throw new MsgException("打印机配置为空"); throw new MsgException("打印机配置为空");
} }
if (StrUtil.isNotBlank(printMethod)) {
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class); List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class);
//仅打印后厨-一菜一品 //仅打印后厨-一菜一品
if ("one".equals(printMethod)) { if ("one".equals(printMethod)) {
@ -58,6 +59,7 @@ public abstract class PrinterHandler {
} else { } else {
log.warn("未知打印类型: {}", printMethod); log.warn("未知打印类型: {}", printMethod);
} }
}
if (StrUtil.isBlank(machine.getPrintType())) { if (StrUtil.isBlank(machine.getPrintType())) {
return; return;
} }
@ -70,10 +72,10 @@ public abstract class PrinterHandler {
if (!CollUtil.contains(optionList, "queue")) { if (!CollUtil.contains(optionList, "queue")) {
return; return;
} }
callNumPrint(machine, printDTO); if (printDTO == null) {
if (StrUtil.isBlank(printMethod)) { return;
throw new MsgException("打印机配置为空");
} }
callNumPrint(machine, printDTO);
} }
/** /**
@ -93,7 +95,10 @@ public abstract class PrinterHandler {
log.error("商品不存在, id: {}", item.getProductSkuId()); log.error("商品不存在, id: {}", item.getProductSkuId());
return; return;
} }
if (StrUtil.isEmpty(machine.getClassifyPrint())) {
log.error("分类打印是空, classifyPrint: {}", machine.getClassifyPrint());
return;
}
long count = categoryInfos.stream().filter(c -> long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId) c.getId().toString().equals(categoryId)
).count(); ).count();

View File

@ -116,7 +116,11 @@ public class YxyPrinter extends PrinterHandler {
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType()); String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; // String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
String resp = PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data); String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), machine.getAddress(), data);
shopPrintLogService.save(machine, printType, data, resp); shopPrintLogService.save(machine, printType, data, resp);
} }

View File

@ -484,7 +484,7 @@ public class CloudPrinterService {
} }
log.error("打印数据4>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO)); log.error("打印数据4>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType); FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType, printerNum);
} }
} }

View File

@ -274,7 +274,7 @@ public class DataService {
String model = it.getPrintMethod(); String model = it.getPrintMethod();
if(!"normal".equals(model)){ if(!"normal".equals(model) && !"all".equals(model)){
log.error("打印机类型错误"); log.error("打印机类型错误");
return; return;
} }

View File

@ -7,18 +7,13 @@ import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo; import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.util.RedisUtils;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.Jedis;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
@ -55,6 +50,8 @@ public class DutyService {
public void exect(String message) { public void exect(String message) {
try { try {
System.out.println("数据落地开始:" + message); System.out.println("数据落地开始:" + message);
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>数据落地开始: {}", message);
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>数据落地开始: {}", message);
JSONObject jsonObject = JSON.parseObject(message); JSONObject jsonObject = JSON.parseObject(message);
String token = jsonObject.getString("token"); String token = jsonObject.getString("token");
@ -378,6 +375,9 @@ public class DutyService {
private void subInventory(Integer shopId, Integer skuId, Integer num) { private void subInventory(Integer shopId, Integer skuId, Integer num) {
TbProductSku tbProductSku = productSkuMapper.selectByPrimaryKey(skuId); TbProductSku tbProductSku = productSkuMapper.selectByPrimaryKey(skuId);
if (tbProductSku == null) {
return;
}
TbProductWithBLOBs product = productMapper.selectByPrimaryKey(Integer.valueOf(tbProductSku.getProductId())); TbProductWithBLOBs product = productMapper.selectByPrimaryKey(Integer.valueOf(tbProductSku.getProductId()));

View File

@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -254,7 +255,7 @@ public class FeieyunPrintUtil {
return data.toString(); return data.toString();
} }
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType) { public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType, String printerNum) {
String content = buildPrintContent(detailPO, type, orderType); String content = buildPrintContent(detailPO, type, orderType);
//通过POST请求发送打印信息到服务器 //通过POST请求发送打印信息到服务器
@ -276,7 +277,7 @@ public class FeieyunPrintUtil {
nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改 nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
nvps.add(new BasicNameValuePair("sn", sn)); nvps.add(new BasicNameValuePair("sn", sn));
nvps.add(new BasicNameValuePair("content", content)); nvps.add(new BasicNameValuePair("content", content));
nvps.add(new BasicNameValuePair("times", "1"));//打印联数 nvps.add(new BasicNameValuePair("times", printerNum));//打印联数
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
String result = null; String result = null;
@ -316,6 +317,46 @@ public class FeieyunPrintUtil {
} }
public static String print(String content, String sn, String printerNum) {
// 通过POST请求发送打印信息到服务器
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(30000)// 读取超时
.setConnectTimeout(30000)// 连接超时
.build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost(URL);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("user", USER));
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
nvps.add(new BasicNameValuePair("stime", STIME));
nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));// 固定值,不需要修改
nvps.add(new BasicNameValuePair("sn", sn));
nvps.add(new BasicNameValuePair("content", content));
nvps.add(new BasicNameValuePair("times", printerNum));// 打印联数
CloseableHttpResponse response = null;
String result = null;
try {
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
response = httpClient.execute(post);
int statecode = response.getStatusLine().getStatusCode();
if (statecode == 200) {
HttpEntity httpentity = response.getEntity();
if (httpentity != null) {
// 服务器返回的JSON字符串建议要当做日志记录起来
result = EntityUtils.toString(httpentity);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close(response, post, httpClient);
}
return result;
}
public static int getProducrName(String str) { public static int getProducrName(String str) {
int count = 0; int count = 0;
@ -337,6 +378,43 @@ public class FeieyunPrintUtil {
return s; return s;
} }
public static void close(CloseableHttpResponse response, HttpPost post, CloseableHttpClient httpClient) {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
post.abort();
} catch (Exception e) {
e.printStackTrace();
}
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getCallNumPrintData(CallNumPrintPO po) {
StringBuilder sb = new StringBuilder();
sb.append(StrUtil.format("<CB>{}</CB><BR>", po.getShopName()));
sb.append("--------------------------------<BR>");
sb.append(StrUtil.format("<CB>{} {}</CB><BR>", po.getTableName(), po.getCallNum()));
sb.append(StrUtil.format("<C>前面有{}桌</C><BR>", po.getPreNum()));
sb.append(StrUtil.format("<C><QR>{}</QR></C><BR>", po.getCodeUrl()));
sb.append("<CB>怕过号扫一扫</CB><BR>");
sb.append("--------------------------------<BR>");
sb.append(po.getShopNote() + "<BR>");
sb.append("--------------------------------<BR>");
sb.append(StrUtil.format("取号时间:{}<BR>", DateUtils.getTime(po.getTakeTime())));
sb.append(StrUtil.format("打印时间:{}<BR>", DateUtils.getTime(new Date())));
sb.append("<CUT>");
return sb.toString();
}
/** /**
* 检查飞鹅打印机是否在线 * 检查飞鹅打印机是否在线
* *
@ -457,4 +535,6 @@ public class FeieyunPrintUtil {
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4} //失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
System.out.println(UnicodeUtil.toString(resp)); System.out.println(UnicodeUtil.toString(resp));
} }
} }