店铺管理-店铺配置:打印机设置相关接口

This commit is contained in:
谭凯凯 2024-10-12 10:42:45 +08:00 committed by Tankaikai
parent b7205fca9a
commit 3b77cfb33d
6 changed files with 263 additions and 223 deletions

View File

@ -77,6 +77,14 @@ public class TbPrintPCMachine implements Serializable {
*/
private String productId;
private String receiptSize;
private String classifyPrint;
private String tablePrint;
private String printQty;
private String printMethod;
private String printType;
private String printReceipt;
private Integer pageSize;
private Integer page;
@ -242,5 +250,60 @@ public class TbPrintPCMachine implements Serializable {
this.productId = productId;
}
public String getReceiptSize() {
return receiptSize;
}
public void setReceiptSize(String receiptSize) {
this.receiptSize = receiptSize;
}
public String getClassifyPrint() {
return classifyPrint;
}
public void setClassifyPrint(String classifyPrint) {
this.classifyPrint = classifyPrint;
}
public String getTablePrint() {
return tablePrint;
}
public void setTablePrint(String tablePrint) {
this.tablePrint = tablePrint;
}
public String getPrintQty() {
return printQty;
}
public void setPrintQty(String printQty) {
this.printQty = printQty;
}
public String getPrintMethod() {
return printMethod;
}
public void setPrintMethod(String printMethod) {
this.printMethod = printMethod;
}
public String getPrintType() {
return printType;
}
public void setPrintType(String printType) {
this.printType = printType;
}
public String getPrintReceipt() {
return printReceipt;
}
public void setPrintReceipt(String printReceipt) {
this.printReceipt = printReceipt;
}
}

View File

@ -152,8 +152,8 @@ public class PrintConsumer {
}
list = list.stream()
.filter(item -> StrUtil.isNotBlank(item.getConfig())
&& model.equals(JSONObject.parseObject(item.getConfig()).getString("model"))).collect(Collectors.toList());
.filter(item -> StrUtil.isNotBlank(item.getPrintMethod())
&& model.equals(item.getPrintMethod())).collect(Collectors.toList());
log.info("打印机列表: {}", list);
return list;

View File

@ -2,7 +2,6 @@ package com.chaozhanggui.system.cashierservice.rabbit;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
@ -18,9 +17,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
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;
@ -103,16 +103,10 @@ public class PrintMechineConsumer {
log.error("打印机状态异常:{},{}", it.getAddress(), it.getStatus());
return;
}
String model = StrUtil.isEmpty(it.getPrintMethod()) ? "normal" : it.getPrintMethod();
String printerNum = StrUtil.isEmpty(it.getPrintQty()) ? "1" : it.getPrintQty().split("^")[1];
JSONObject config = JSONObject.parseObject(it.getConfig());
String model = config.getString("model");
String printerNum = config.getString("printerNum");
String feet = config.getString("feet");
String autoCut = config.getString("autoCut");
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(), CategoryInfo.class);
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(it.getCategoryList(), "[]"), CategoryInfo.class);
switch (it.getContentType()) {
case "yxyPrinter":
@ -313,7 +307,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();
}
@ -379,7 +373,8 @@ public class PrintMechineConsumer {
/**
* 打印退款订单
* @param orderId 订单id
*
* @param orderId 订单id
* @param tbOrderDetails 现有订单
*/
public void printReturnTicket(Integer orderId, List<TbOrderDetail> tbOrderDetails) {
@ -416,19 +411,16 @@ public class PrintMechineConsumer {
for (Object o : printProductSetCopy) {
redisTemplate.opsForSet().add(printKey, o);
}
}else if (tbOrderDetails != null) {
} else if (tbOrderDetails != null) {
redisTemplate.delete(printKey);
}
log.info("-------------------打印机数量{}", list.size());
for (TbPrintMachine machine : list) {
String config = machine.getConfig();
if (config != null) {
JSONObject jsonObject = JSONObject.parseObject(config);
if (!"one".equals(jsonObject.getString("model"))) {
continue;
}
String printMethod = machine.getPrintMethod();
if (!"one".equals(printMethod)) {
continue;
}
log.info("-------------------商品数量{}", printProductSet.size());
printProductSet.forEach(item -> {
@ -619,7 +611,7 @@ public class PrintMechineConsumer {
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}

View File

@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.service;
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.*;
@ -64,9 +65,7 @@ public class CloudPrinterService {
ShopUserDutyPayMapper shopUserDutyPayMapper;
public Result printReceipt(String type,String orderId,Boolean ispre){
public Result printReceipt(String type, String orderId, Boolean ispre) {
try {
@ -89,7 +88,7 @@ public class CloudPrinterService {
return Result.fail(CodeEnum.printmachinenoexsit);
}
list.parallelStream().forEach(tbPrintMachineWithBLOBs->{
list.parallelStream().forEach(tbPrintMachineWithBLOBs -> {
if (!"network".equals(tbPrintMachineWithBLOBs.getConnectionType())) {
log.error("非网络打印机");
return;
@ -100,29 +99,24 @@ public class CloudPrinterService {
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,type,ispre);
yxyPrinter(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre);
break;
case "fePrinter":
fePrinter(tbPrintMachineWithBLOBs,model,orderInfo,shopInfo,printerNum,categoryInfos,type,ispre);
fePrinter(tbPrintMachineWithBLOBs, model, orderInfo, shopInfo, printerNum, categoryInfos, type, ispre);
break;
}
});
return Result.success(CodeEnum.SUCCESS);
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
@ -131,18 +125,17 @@ public class CloudPrinterService {
}
/**
* 博时结云打印机
* 博时结云打印机
*
* @param tbPrintMachineWithBLOBs
* @param model
* @param orderInfo
* @param shopInfo
* @param printerNum
*/
private Result yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos,String type,Boolean ispre){
String orderId=orderInfo.getId().toString();
private Result yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
@ -151,21 +144,21 @@ public class CloudPrinterService {
case "cash": //小票打印机
switch (model) {
case "normal": //普通出单
if(!"normal".equals(type)){
if (!"normal".equals(type)) {
return Result.fail("非小票打印");
}
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0){
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.parallelStream().forEach(it->{
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
tbOrderDetails.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
log.info("获取当前类别是否未打印类别:{}", count);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
@ -187,21 +180,21 @@ public class CloudPrinterService {
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
ObjectUtil.isEmpty(orderInfo.getMasterId())||ObjectUtil.isNull(orderInfo.getMasterId())?orderInfo.getTableName():orderInfo.getMasterId(),
ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0",
detailList,orderInfo.getRemark(),null,null);
detailList, orderInfo.getRemark(), null, null);
detailPO.setOutNumber(orderInfo.getOutNumber());
String printType="退款单";
String printType = "退款单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,"return");
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
@ -209,29 +202,29 @@ public class CloudPrinterService {
}
List<TbCashierCart> cashierCarts =new ArrayList<>();
if(ispre){
cashierCarts=tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"create");
}else {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
List<TbCashierCart> cashierCarts = new ArrayList<>();
if (ispre) {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "create");
} else {
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())) {
@ -246,7 +239,7 @@ public class CloudPrinterService {
String balance = "0";
if ("deposit".equals(orderInfo.getPayType())) {
if(ObjectUtil.isNotEmpty(orderInfo.getMemberId())&&ObjectUtil.isNotNull(orderInfo.getMemberId())){
if (ObjectUtil.isNotEmpty(orderInfo.getMemberId()) && ObjectUtil.isNotNull(orderInfo.getMemberId())) {
TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
balance = user.getAmount().toPlainString();
@ -254,89 +247,88 @@ public class CloudPrinterService {
}
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
orderInfo.getOrderType().equals("miniapp")?orderInfo.getTableName():orderInfo.getMasterId(),
orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(),
balance, (ObjectUtil.isEmpty(orderInfo.getPayType())||ObjectUtil.isNull(orderInfo.getPayType())?"":orderInfo.getPayType() ), "0",
detailList,orderInfo.getRemark(),orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null,orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
String printType="结算单";
balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), "0",
detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null, orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
String printType = "结算单";
detailPO.setOutNumber(orderInfo.getOutNumber());
if(ispre){
printType="预结算单";
if (ispre) {
printType = "预结算单";
}
if("return".equals(orderInfo.getOrderType())){
printType="退款单";
if ("return".equals(orderInfo.getOrderType())) {
printType = "退款单";
}
String data= PrinterUtils.getCashPrintData(detailPO,printType,orderInfo.getOrderType());
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
break;
case "one": //一菜一品
if(!"one".equals(type)){
if (!"one".equals(type)) {
return Result.fail("非出品打印");
}
if(ispre){
if (ispre) {
return Result.fail("预结算单不打印菜单");
}
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> details= tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(details)&&details.size()>0){
details.parallelStream().forEach(it->{
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> details = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(details) && details.size() > 0) {
details.parallelStream().forEach(it -> {
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
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.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("return",orderInfo.getPayType().equals("wx_lite") ?
orderInfo.getTableName():orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark, null);
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
return Result.success(CodeEnum.SUCCESS);
}else {
} else {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final");
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
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())) {
@ -344,13 +336,11 @@ public class CloudPrinterService {
}
String data = PrinterUtils.getPrintData("",orderInfo.getOrderType().equals("miniapp") ?
orderInfo.getTableName():orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark, null);
String data = PrinterUtils.getPrintData("", orderInfo.getOrderType().equals("miniapp") ?
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark, null);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
@ -358,7 +348,7 @@ public class CloudPrinterService {
break;
case "category": //分类出单
if(!"category".equals(type)){
if (!"category".equals(type)) {
return Result.fail("非分类打印");
}
break;
@ -373,35 +363,33 @@ public class CloudPrinterService {
}
private Result fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos,String type,Boolean ispre){
String orderId=orderInfo.getId().toString();
private Result fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
if(!"label".equals(type)){
if (!"label".equals(type)) {
return Result.fail("非标签打印机");
}
if(ispre){
if (ispre) {
return Result.fail("预结算单不打印标签");
}
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->{
Long count= categoryInfos.stream().filter(c->
cashierCarts.parallelStream().forEach(it -> {
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(it.getCategoryId().toString())
).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++){
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getOrderType().equals("miniapp")?orderInfo.getTableName():orderInfo.getMasterId(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
@ -412,21 +400,21 @@ public class CloudPrinterService {
case "cash": //小票打印机
switch (model) {
case "normal": //普通出单
if(!"normal".equals(type)){
if (!"normal".equals(type)) {
return Result.fail("非小票打印");
}
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0){
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.parallelStream().forEach(it->{
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
tbOrderDetails.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
log.info("获取当前类别是否未打印类别:{}", count);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
@ -448,13 +436,13 @@ public class CloudPrinterService {
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId())||ObjectUtil.isNull(orderInfo.getMasterId())?orderInfo.getTableName():orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList,orderInfo.getRemark(),null,null);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark(), null, null);
String printType="退款单";
String printType = "退款单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,"return");
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
// PrinterUtils.printTickets(1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
@ -463,29 +451,29 @@ public class CloudPrinterService {
}
cashierCarts =new ArrayList<>();
if(ispre){
cashierCarts=tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"create");
}else {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
cashierCarts = new ArrayList<>();
if (ispre) {
cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "create");
} else {
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())) {
@ -505,68 +493,68 @@ public class CloudPrinterService {
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.getOrderType().equals("miniapp")?orderInfo.getTableName():orderInfo.getMasterId(),
orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(),
balance,(ObjectUtil.isEmpty(orderInfo.getPayType())||ObjectUtil.isNull(orderInfo.getPayType())?"":orderInfo.getPayType() ),
"0", detailList,orderInfo.getRemark(),null,null);
String printType="结算单";
if(ispre){
printType="预结算单";
balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), null, null);
String printType = "结算单";
if (ispre) {
printType = "预结算单";
}
if("return".equals(orderInfo.getOrderType())){
printType="退款单";
if ("return".equals(orderInfo.getOrderType())) {
printType = "退款单";
}
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(),printType, printType);
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType);
}
}
break;
case "one": //一菜一品
if(!"one".equals(type)){
if (!"one".equals(type)) {
return Result.fail("非出品打印");
}
if(ispre){
if (ispre) {
return Result.fail("预结算单不打印菜单");
}
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final");
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
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();
}
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(),orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
}
});
}
break;
case "category": //分类出单
if(!"category".equals(type)){
if (!"category".equals(type)) {
return Result.fail("非分类打印");
}
break;
@ -580,17 +568,17 @@ public class CloudPrinterService {
}
public Result handoverprintData(String token,Integer id,String loginName,boolean isprintProduct){
public Result handoverprintData(String token, Integer id, String loginName, boolean isprintProduct) {
JSONObject info= TokenUtil.parseParamFromToken(token);
MsgException.checkNull(info,"获取信息失败");
JSONObject info = TokenUtil.parseParamFromToken(token);
MsgException.checkNull(info, "获取信息失败");
TbmerchantAccount tbmerchantAccount= tbmerchantAccountMapper.selectByPrimaryKey(Integer.valueOf(info.get("accountId").toString()));
MsgException.checkNull(tbmerchantAccount,"商户信息不存在");
TbmerchantAccount tbmerchantAccount = tbmerchantAccountMapper.selectByPrimaryKey(Integer.valueOf(info.get("accountId").toString()));
MsgException.checkNull(tbmerchantAccount, "商户信息不存在");
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbmerchantAccount.getShopId()));
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbmerchantAccount.getShopId()));
MsgException.checkNull(tbShopInfo, "店铺信息不存在");
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(tbShopInfo.getId());
@ -607,7 +595,7 @@ public class CloudPrinterService {
return Result.fail(CodeEnum.printmachinenoexsit);
}
bloBsList.parallelStream().forEach(it->{
bloBsList.parallelStream().forEach(it -> {
if (!"network".equals(it.getConnectionType())) {
log.error("非网络打印机");
@ -619,75 +607,70 @@ public class CloudPrinterService {
return;
}
if(!it.getSubType().equals("cash")){
log.error("非小票打印机");
return;
}
ShopUserDuty shopUserDuty=shopUserDutyMapper.selectByPrimaryKey(id);
// ShopUserDuty shopUserDuty=shopUserDutyMapper.selectByShopIdAndDay(tbShopInfo.getId(),tradeDay);
MsgException.checkNull(shopUserDuty,"交班信息不存在");
TbPlussShopStaff shopStaff= tbPlussShopStaffMapper.selectByPrimaryKey(Integer.valueOf(info.get("staffId").toString()));
MsgException.checkNull(shopStaff,"员工信息不存在");
List<HandoverInfo.PayInfo> list=null;
List<HandoverInfo.MemberData> memberData=null;
List<HandoverInfo.ProductCategory> productCategories=null;
List<Map<String,Object>> mapList= shopUserDutyPayMapper.selectByDutyId(shopUserDuty.getId());
if(ObjectUtil.isNotEmpty(mapList)&&mapList.size()>0){
list= JSONUtil.parseJSONStr2TList(JSONUtil.toJSONString(mapList), HandoverInfo.PayInfo.class);
if (!it.getSubType().equals("cash")) {
log.error("非小票打印机");
return;
}
memberData=new ArrayList<>();
ShopUserDutyPay shopUserDutyPay=shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),"deposit");
if(ObjectUtil.isNotEmpty(shopUserDutyPay)){
memberData.add(new HandoverInfo.MemberData(shopUserDutyPay.getAmount().toPlainString(),"会员卡消费"));
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByPrimaryKey(id);
// ShopUserDuty shopUserDuty=shopUserDutyMapper.selectByShopIdAndDay(tbShopInfo.getId(),tradeDay);
MsgException.checkNull(shopUserDuty, "交班信息不存在");
TbPlussShopStaff shopStaff = tbPlussShopStaffMapper.selectByPrimaryKey(Integer.valueOf(info.get("staffId").toString()));
MsgException.checkNull(shopStaff, "员工信息不存在");
List<HandoverInfo.PayInfo> list = null;
List<HandoverInfo.MemberData> memberData = null;
List<HandoverInfo.ProductCategory> productCategories = null;
List<Map<String, Object>> mapList = shopUserDutyPayMapper.selectByDutyId(shopUserDuty.getId());
if (ObjectUtil.isNotEmpty(mapList) && mapList.size() > 0) {
list = JSONUtil.parseJSONStr2TList(JSONUtil.toJSONString(mapList), HandoverInfo.PayInfo.class);
}
memberData = new ArrayList<>();
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(), "deposit");
if (ObjectUtil.isNotEmpty(shopUserDutyPay)) {
memberData.add(new HandoverInfo.MemberData(shopUserDutyPay.getAmount().toPlainString(), "会员卡消费"));
// memberData.add(new HandoverInfo.MemberData(ObjectUtil.isNull(shopUserDuty.getMemberOutAmount())? BigDecimal.ZERO.toPlainString() : shopUserDuty.getMemberOutAmount().toPlainString(),"会员卡支付"));
// memberData.add(new HandoverInfo.MemberData(ObjectUtil.isNull(shopUserDuty.getMemberOutAmount())? BigDecimal.ONE.toPlainString() : shopUserDuty.getMemberOutAmount().toPlainString(),"储值卡支付"));
}
memberData.add(new HandoverInfo.MemberData(ObjectUtil.isNull(shopUserDuty.getMemberInAmount())? BigDecimal.ZERO.toPlainString() : shopUserDuty.getMemberInAmount().toPlainString(),"会员卡充值"));
memberData.add(new HandoverInfo.MemberData(ObjectUtil.isNull(shopUserDuty.getMemberInAmount()) ? BigDecimal.ZERO.toPlainString() : shopUserDuty.getMemberInAmount().toPlainString(), "会员卡充值"));
List<Map<String,Object>> categries= shopUserDutyPayMapper.selectCetoryBydutyId(shopUserDuty.getId());
if(ObjectUtil.isNotEmpty(categries)&&categries.size()>0){
productCategories=JSONUtil.parseJSONStr2TList(JSONUtil.toJSONString(categries),HandoverInfo.ProductCategory.class);
List<Map<String, Object>> categries = shopUserDutyPayMapper.selectCetoryBydutyId(shopUserDuty.getId());
if (ObjectUtil.isNotEmpty(categries) && categries.size() > 0) {
productCategories = JSONUtil.parseJSONStr2TList(JSONUtil.toJSONString(categries), HandoverInfo.ProductCategory.class);
}
List<ProductInfoPO> productInfoPOS=null;
List<ProductInfo> productInfos=null;
if(isprintProduct){
List<ProductInfoPO> productInfoPOS = null;
List<ProductInfo> productInfos = null;
if (isprintProduct) {
// productInfoPOS=shopUserDutyPayMapper.selectProductByDutyId(shopUserDuty.getId());
productInfos=shopUserDutyMapper.selectByDutyId(shopUserDuty.getId());
productInfos = shopUserDutyMapper.selectByDutyId(shopUserDuty.getId());
}
HandoverInfo handoverInfo=new HandoverInfo(tbShopInfo.getShopName(),
ObjectUtil.isNotEmpty(shopUserDuty.getLoginTime())?DateUtils.getTime(shopUserDuty.getLoginTime()):null,
ObjectUtil.isNotEmpty(shopUserDuty.getLoginOutTime())?DateUtils.getTime(shopUserDuty.getLoginOutTime()):DateUtils.getTime(new Date()),
ObjectUtil.isNull(shopStaff.getName())?"":shopStaff.getName(),
list,memberData,shopUserDuty.getAmount().add(ObjectUtil.isNull(shopUserDuty.getQuickAmount())?BigDecimal.ZERO:shopUserDuty.getQuickAmount()).toPlainString(),
HandoverInfo handoverInfo = new HandoverInfo(tbShopInfo.getShopName(),
ObjectUtil.isNotEmpty(shopUserDuty.getLoginTime()) ? DateUtils.getTime(shopUserDuty.getLoginTime()) : null,
ObjectUtil.isNotEmpty(shopUserDuty.getLoginOutTime()) ? DateUtils.getTime(shopUserDuty.getLoginOutTime()) : DateUtils.getTime(new Date()),
ObjectUtil.isNull(shopStaff.getName()) ? "" : shopStaff.getName(),
list, memberData, shopUserDuty.getAmount().add(ObjectUtil.isNull(shopUserDuty.getQuickAmount()) ? BigDecimal.ZERO : shopUserDuty.getQuickAmount()).toPlainString(),
"0",
shopUserDuty.getAmount().subtract(shopUserDuty.getReturnAmount()).toPlainString(),
shopUserDuty.getAmount().add(ObjectUtil.isNull(shopUserDuty.getQuickAmount())?BigDecimal.ZERO:shopUserDuty.getQuickAmount()).toPlainString(),
shopUserDuty.getAmount().add(ObjectUtil.isNull(shopUserDuty.getQuickAmount()) ? BigDecimal.ZERO : shopUserDuty.getQuickAmount()).toPlainString(),
shopUserDuty.getReturnAmount().toPlainString(),
shopUserDuty.getOrderNum().toString(),
productCategories,ObjectUtil.isNull(shopUserDuty.getQuickAmount())?"0":shopUserDuty.getQuickAmount().toPlainString(),
productCategories, ObjectUtil.isNull(shopUserDuty.getQuickAmount()) ? "0" : shopUserDuty.getQuickAmount().toPlainString(),
productInfoPOS,
productInfos
);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,1,1,it.getAddress(),PrinterUtils.handoverprintData(handoverInfo));
PrinterUtils.printTickets(voiceJson, 1, 1, it.getAddress(), PrinterUtils.handoverprintData(handoverInfo));
});
@ -696,11 +679,7 @@ public class CloudPrinterService {
}
public Result printInvoice(String shopId,String content,String remark,String amount){
public Result printInvoice(String shopId, String content, String remark, String amount) {
List<TbPrintMachineWithBLOBs> bloBsList = tbPrintMachineMapper.selectByShopId(shopId);
@ -709,7 +688,7 @@ public class CloudPrinterService {
return Result.fail(CodeEnum.printmachinenoexsit);
}
bloBsList.parallelStream().forEach(it->{
bloBsList.parallelStream().forEach(it -> {
if (!"network".equals(it.getConnectionType())) {
log.error("非网络打印机");
return;
@ -720,17 +699,16 @@ public class CloudPrinterService {
return;
}
if(!it.getSubType().equals("cash")){
if (!it.getSubType().equals("cash")) {
log.error("非小票打印机");
return;
}
String voiceJson = "{\"bizType\":\"1\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,1,1,it.getAddress(),PrinterUtils.printInvoice(content, remark, amount));
PrinterUtils.printTickets(voiceJson, 1, 1, it.getAddress(), PrinterUtils.printInvoice(content, remark, amount));
});
return Result.success(CodeEnum.SUCCESS);
}
}

View File

@ -273,8 +273,7 @@ public class DataService {
JSONObject config = JSONObject.parseObject(it.getConfig());
String model = config.getString("model");
String model = it.getPrintMethod();
if(!"normal".equals(model)){
log.error("打印机类型错误");
return;

View File

@ -21,11 +21,19 @@
<result property="sort" column="sort" jdbcType="INTEGER"/>
<result property="vendorId" column="vendor_id" jdbcType="VARCHAR"/>
<result property="productId" column="product_id" jdbcType="VARCHAR"/>
<result column="receipt_size" jdbcType="VARCHAR" property="receiptSize" />
<result column="classify_print" jdbcType="VARCHAR" property="classifyPrint" />
<result column="table_print" jdbcType="VARCHAR" property="tablePrint" />
<result column="print_qty" jdbcType="VARCHAR" property="printQty" />
<result column="print_method" jdbcType="VARCHAR" property="printMethod" />
<result column="print_type" jdbcType="VARCHAR" property="printType" />
<result column="print_receipt" jdbcType="VARCHAR" property="printReceipt" />
</resultMap>
<sql id="Base_Column_List">
id
, name, type, connection_type, address, port, sub_type, status, shop_id, category_ids, content_type, config, created_at, updated_at, category_list, sort, vendor_id, product_id </sql>
, name, type, connection_type, address, port, sub_type, status, shop_id, category_ids, content_type, config, created_at, updated_at, category_list, sort, vendor_id, product_id, receipt_size, classify_print, table_print, print_qty, print_method, print_type, print_receipt </sql>
<!--查询单个-->
<select id="queryById" resultMap="TbPrintMachineMap">