适配打印机新参数
This commit is contained in:
@@ -3,7 +3,6 @@ package com.chaozhanggui.system.cashierservice.rabbit;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
|
||||
@@ -22,7 +21,10 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -87,57 +89,53 @@ public class PrintMechineConsumer {
|
||||
log.info("打印机列表,{}", ArrayUtil.toString(list));
|
||||
log.info("待打印订单信息, {}", orderInfo);
|
||||
|
||||
list.forEach(tbPrintMachineWithBLOBs->{
|
||||
list.forEach(tbPrintMachineWithBLOBs -> {
|
||||
if (!"network".equals(tbPrintMachineWithBLOBs.getConnectionType())) {
|
||||
log.error("非网络打印机:{},{}",tbPrintMachineWithBLOBs.getAddress(),tbPrintMachineWithBLOBs.getConnectionType());
|
||||
log.error("非网络打印机:{},{}", tbPrintMachineWithBLOBs.getAddress(), tbPrintMachineWithBLOBs.getConnectionType());
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!"1".equals(tbPrintMachineWithBLOBs.getStatus().toString())) {
|
||||
log.error("打印机状态异常:{},{}",tbPrintMachineWithBLOBs.getAddress(),tbPrintMachineWithBLOBs.getStatus());
|
||||
log.error("打印机状态异常:{},{}", tbPrintMachineWithBLOBs.getAddress(), tbPrintMachineWithBLOBs.getStatus());
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject config = JSONObject.parseObject(tbPrintMachineWithBLOBs.getConfig());
|
||||
String model = config.getString("model");
|
||||
String model = tbPrintMachineWithBLOBs.getPrintMethod();
|
||||
|
||||
String printerNum = config.getString("printerNum");
|
||||
String printerNum = StrUtil.isEmpty(tbPrintMachineWithBLOBs.getPrintQty()) ? "1" : tbPrintMachineWithBLOBs.getPrintQty().split("^")[1];
|
||||
|
||||
String feet = config.getString("feet");
|
||||
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(tbPrintMachineWithBLOBs.getCategoryList(), "[]"), CategoryInfo.class);
|
||||
|
||||
String autoCut = config.getString("autoCut");
|
||||
|
||||
List<CategoryInfo> categoryInfos=JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(),CategoryInfo.class);
|
||||
|
||||
switch (tbPrintMachineWithBLOBs.getContentType()){
|
||||
switch (tbPrintMachineWithBLOBs.getContentType()) {
|
||||
case "yxyPrinter":
|
||||
yxyPrinter(tbPrintMachineWithBLOBs,model,orderInfo,shopInfo,printerNum,categoryInfos);
|
||||
yxyPrinter(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos);
|
||||
break;
|
||||
case "fePrinter":
|
||||
fePrinter(tbPrintMachineWithBLOBs,model,orderInfo,shopInfo,printerNum,categoryInfos);
|
||||
fePrinter(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos);
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 博时结云打印机
|
||||
* 博时结云打印机
|
||||
*
|
||||
* @param tbPrintMachineWithBLOBs
|
||||
* @param model
|
||||
* @param orderInfo
|
||||
* @param shopInfo
|
||||
* @param printerNum
|
||||
*/
|
||||
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
|
||||
String orderId=orderInfo.getId().toString();
|
||||
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
|
||||
String orderId = orderInfo.getId().toString();
|
||||
|
||||
|
||||
switch (tbPrintMachineWithBLOBs.getSubType()) {
|
||||
@@ -146,23 +144,23 @@ public class PrintMechineConsumer {
|
||||
case "cash": //小票打印机
|
||||
switch (model) {
|
||||
case "normal": //普通出单
|
||||
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
|
||||
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
|
||||
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
|
||||
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
|
||||
cashierCarts.parallelStream().forEach(it -> {
|
||||
String categoryId;
|
||||
if(ObjectUtil.isEmpty(it.getCategoryId())){
|
||||
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
if (ObjectUtil.isEmpty(it.getCategoryId())) {
|
||||
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
} else {
|
||||
categoryId = it.getCategoryId();
|
||||
}
|
||||
|
||||
|
||||
Long count= categoryInfos.stream().filter(c->
|
||||
Long count = categoryInfos.stream().filter(c ->
|
||||
c.getId().toString().equals(categoryId)
|
||||
).count();
|
||||
|
||||
if(count>0){
|
||||
if (count > 0) {
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
|
||||
String remark = "";
|
||||
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
|
||||
@@ -182,11 +180,11 @@ public class PrintMechineConsumer {
|
||||
balance = user.getAmount().toPlainString();
|
||||
}
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
|
||||
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
|
||||
|
||||
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getTableName(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList,orderInfo.getRemark());
|
||||
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getTableName(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark());
|
||||
detailPO.setOutNumber(orderInfo.getOutNumber());
|
||||
String data= PrinterUtils.getCashPrintData(detailPO,"结算单");
|
||||
String data = PrinterUtils.getCashPrintData(detailPO, "结算单");
|
||||
PrinterUtils.printTickets(1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
}
|
||||
|
||||
@@ -194,7 +192,7 @@ public class PrintMechineConsumer {
|
||||
|
||||
break;
|
||||
case "one": //一菜一品
|
||||
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final");
|
||||
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
|
||||
log.info("一菜一品打印,待打印信息:{}", cashierCarts);
|
||||
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
|
||||
|
||||
@@ -210,18 +208,18 @@ public class PrintMechineConsumer {
|
||||
log.info("--------------------非代客下单 打印一菜一品");
|
||||
|
||||
String categoryId;
|
||||
if(ObjectUtil.isEmpty(it.getCategoryId())){
|
||||
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
if (ObjectUtil.isEmpty(it.getCategoryId())) {
|
||||
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
} else {
|
||||
categoryId = it.getCategoryId();
|
||||
}
|
||||
|
||||
|
||||
Long count= categoryInfos.stream().filter(c->
|
||||
Long count = categoryInfos.stream().filter(c ->
|
||||
c.getId().toString().equals(categoryId)
|
||||
).count();
|
||||
|
||||
if(count>0){
|
||||
if (count > 0) {
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
|
||||
String remark = "";
|
||||
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
|
||||
@@ -285,7 +283,7 @@ public class PrintMechineConsumer {
|
||||
if (info != null) {
|
||||
isReturn = it.getNum() - Integer.parseInt(info) < 0;
|
||||
printerNum = it.getNum() - Integer.parseInt(info);
|
||||
}else {
|
||||
} else {
|
||||
printerNum = it.getNum();
|
||||
}
|
||||
|
||||
@@ -353,37 +351,35 @@ public class PrintMechineConsumer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
|
||||
String orderId=orderInfo.getId().toString();
|
||||
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
|
||||
String orderId = orderInfo.getId().toString();
|
||||
switch (tbPrintMachineWithBLOBs.getSubType()) {
|
||||
case "label": //标签打印机
|
||||
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
|
||||
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
|
||||
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
|
||||
cashierCarts.parallelStream().forEach(it->{
|
||||
cashierCarts.parallelStream().forEach(it -> {
|
||||
|
||||
String categoryId;
|
||||
if(ObjectUtil.isEmpty(it.getCategoryId())){
|
||||
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
if (ObjectUtil.isEmpty(it.getCategoryId())) {
|
||||
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
|
||||
} else {
|
||||
categoryId = it.getCategoryId();
|
||||
}
|
||||
|
||||
|
||||
Long count= categoryInfos.stream().filter(c->
|
||||
Long count = categoryInfos.stream().filter(c ->
|
||||
c.getId().toString().equals(categoryId)
|
||||
).count();
|
||||
|
||||
|
||||
if(count>0) {
|
||||
if (count > 0) {
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
|
||||
String remark = "";
|
||||
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
|
||||
remark = tbProductSkuWithBLOBs.getSpecSnap();
|
||||
}
|
||||
|
||||
for(int i=0;i<it.getNumber();i++){
|
||||
for (int i = 0; i < it.getNumber(); i++) {
|
||||
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
|
||||
}
|
||||
|
||||
@@ -524,7 +520,7 @@ public class PrintMechineConsumer {
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case "kitchen": //出品打印机
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user