Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -49,12 +49,14 @@ public class OrderDetailPO implements Serializable {
|
||||
private String amount;
|
||||
|
||||
private String spec;
|
||||
private String proGroupInfo;
|
||||
|
||||
public Detail(String productName, String number, String amount, String spec) {
|
||||
public Detail(String productName, String number, String amount, String spec, String proGroupInfo) {
|
||||
this.productName = productName;
|
||||
this.number = number;
|
||||
this.amount = amount;
|
||||
this.spec = spec;
|
||||
this.proGroupInfo = proGroupInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public class PrintMechineConsumer {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
|
||||
});
|
||||
@@ -240,7 +240,7 @@ public class PrintMechineConsumer {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
}
|
||||
});
|
||||
@@ -367,14 +367,14 @@ public class PrintMechineConsumer {
|
||||
|
||||
data = PrinterUtils.getPrintData("return",
|
||||
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), Math.abs(printerNum), remark, null);
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), Math.abs(printerNum), remark, null, it.getProGroupInfo());
|
||||
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
|
||||
} else {
|
||||
data = PrinterUtils.getPrintData("", orderInfo.getMasterId(),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(),
|
||||
printerNum, remark, null);
|
||||
printerNum, remark, null, it.getProGroupInfo());
|
||||
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
|
||||
@@ -393,7 +393,7 @@ public class PrintMechineConsumer {
|
||||
String data = PrinterUtils.getPrintData("return",
|
||||
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
|
||||
// todo 修改为bigdecimal
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), orderDetail.getRemark(), null);
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), orderDetail.getRemark(), null, orderDetail.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
|
||||
@@ -462,7 +462,7 @@ public class PrintMechineConsumer {
|
||||
// todo 修改为bigdecimal
|
||||
String data = PrinterUtils.getPrintData("return",
|
||||
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), orderDetail.getRemark(), null);
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), orderDetail.getRemark(), null, orderDetail.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
|
||||
|
||||
@@ -505,7 +505,7 @@ public class PrintMechineConsumer {
|
||||
// todo 修改为bigdecimal
|
||||
String data = PrinterUtils.getPrintData("", orderInfo.getMasterId(),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(),
|
||||
it.getNum().intValue(), remark, null);
|
||||
it.getNum().intValue(), remark, null, it.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
}
|
||||
@@ -548,7 +548,7 @@ public class PrintMechineConsumer {
|
||||
// todo 修改为bigdecimal
|
||||
|
||||
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ?
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum().intValue(), remark, null);
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum().intValue(), remark, null, it.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
}
|
||||
@@ -600,7 +600,7 @@ public class PrintMechineConsumer {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
|
||||
});
|
||||
@@ -664,7 +664,7 @@ public class PrintMechineConsumer {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ public class PrintMechineConsumer {
|
||||
}
|
||||
|
||||
|
||||
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo, DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark);
|
||||
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo, DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark, it.getProGroupInfo());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class FeiPrinter extends PrinterHandler {
|
||||
String remark = sku == null ? "" : sku.getSpecSnap();
|
||||
// todo 修改为bigdecimal
|
||||
String[] resp = FeieyunPrintUtil.getPrintData(machine.getAddress(), orderInfo,
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), remark);
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum().intValue(), remark, orderDetail.getProGroupInfo());
|
||||
shopPrintLogService.save(machine, "新订单", resp[0], resp[1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ public abstract class PrinterHandler {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ public class YxyPrinter extends PrinterHandler {
|
||||
|
||||
String data = PrinterUtils.getPrintData("return", getPickupNum(orderInfo),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(),
|
||||
orderDetail.getNum().abs().intValue(), orderDetail.getRemark(), orderDetail.getNote());
|
||||
orderDetail.getNum().abs().intValue(), orderDetail.getRemark(), orderDetail.getNote(), orderDetail.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
|
||||
String resp = PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
|
||||
@@ -81,7 +81,7 @@ public class YxyPrinter extends PrinterHandler {
|
||||
|
||||
String data = PrinterUtils.getPrintData("", getPickupNum(orderInfo),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(),
|
||||
orderDetail.getNum().intValue(), orderDetail.getRemark(), orderDetail.getNote());
|
||||
orderDetail.getNum().intValue(), orderDetail.getRemark(), orderDetail.getNote(), orderDetail.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
|
||||
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
|
||||
String resp = PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
|
||||
@@ -163,7 +163,7 @@ public class YxyPrinter extends PrinterHandler {
|
||||
public static void main(String[] args) {
|
||||
String data = PrinterUtils.getPrintData("", "#3",
|
||||
DateUtils.getTime(DateUtil.date()), "九度",
|
||||
Integer.valueOf("20"), "少冰", "加菜防守打法火速地方啊地上1三大法宝苏俄倒海翻江");
|
||||
Integer.valueOf("20"), "少冰", "加菜防守打法火速地方啊地上1三大法宝苏俄倒海翻江","");
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, 1, "ZF544PG03W00005", data);
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class CloudPrinterService {
|
||||
// todo 修改为bigdecimal
|
||||
|
||||
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ?
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum().intValue(), remark, null);
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum().intValue(), remark, null, it.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
|
||||
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class CloudPrinterService {
|
||||
// todo 修改为bigdecimal
|
||||
|
||||
String data = PrinterUtils.getPrintData("", orderInfo.getOrderType().equals("miniapp") ?
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark, null);
|
||||
orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark, null, it.getProGroupInfo());
|
||||
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
|
||||
|
||||
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
|
||||
@@ -283,7 +283,7 @@ public class CloudPrinterService {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
|
||||
});
|
||||
@@ -353,7 +353,7 @@ public class CloudPrinterService {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ public class CloudPrinterService {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNum(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
|
||||
});
|
||||
@@ -493,7 +493,7 @@ public class CloudPrinterService {
|
||||
unitPrice = it.getMemberPrice();
|
||||
}
|
||||
BigDecimal subTotal = NumberUtil.mul(it.getNumber(), unitPrice.subtract(NumberUtil.null2Zero(it.getDiscountSaleAmount())));
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark);
|
||||
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), subTotal.toPlainString(), remark, it.getProGroupInfo());
|
||||
detailList.add(detail);
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ public class CloudPrinterService {
|
||||
}
|
||||
// todo 修改为bigdecimal
|
||||
|
||||
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo, DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark);
|
||||
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo, DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber().intValue(), remark, it.getProGroupInfo());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.text.UnicodeUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.bean.OrderUseTypeEnum;
|
||||
@@ -121,24 +123,29 @@ public class FeieyunPrintUtil {
|
||||
|
||||
}
|
||||
|
||||
public static String buildPrintContent(String pickupNumber, String date, String productName, Integer number, String remark) {
|
||||
public static String buildPrintContent(String pickupNumber, String date, String productName, Integer number, String remark, String proGroupInfo) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<CB>" + pickupNumber + "</CB><BR><BR>");
|
||||
builder.append("<L>时间: " + date + " </L><BR><BR><BR>");
|
||||
remark = StrUtil.emptyToDefault(remark, "");
|
||||
if (productName.length() > 4 || remark.length() > 4) {
|
||||
builder.append("<B><BOLD>" + productName + " x " + number + "</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>" + remark + " </BOLD></B><BR>");
|
||||
} else {
|
||||
builder.append("<B><BOLD>" + productName + " x " + number + "</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>" + remark + " </BOLD></B><BR>");
|
||||
builder.append("<B><BOLD>" + productName + " x " + number + "</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>" + remark + " </BOLD></B><BR><BR>");
|
||||
if (!StrUtil.isBlank(proGroupInfo) && cn.hutool.json.JSONUtil.isJsonArray(proGroupInfo)) {
|
||||
JSONArray subItems = cn.hutool.json.JSONUtil.parseArray(proGroupInfo);
|
||||
for (int i = 0; i < subItems.size(); i++) {
|
||||
String proName = subItems.getJSONObject(i).getStr("proName");
|
||||
int qty = subItems.getJSONObject(i).getInt("number");
|
||||
builder.append("<B>("+(i+1)+")"+proName + " x " + qty + "</B><BR>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//builder.append("<CUT>");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String[] getPrintData(String sn, TbOrderInfo orderInfo, String date, String productName, Integer number, String remark) {
|
||||
String content = buildPrintContent(getPickupNum(orderInfo), date, productName, number, remark);
|
||||
public static String[] getPrintData(String sn, TbOrderInfo orderInfo, String date, String productName, Integer number, String remark, String proGroupInfo) {
|
||||
String content = buildPrintContent(getPickupNum(orderInfo), date, productName, number, remark, proGroupInfo);
|
||||
|
||||
System.out.println("content:".concat(content));
|
||||
|
||||
@@ -230,18 +237,31 @@ public class FeieyunPrintUtil {
|
||||
data.append("--------------------------------<BR>");
|
||||
for (OrderDetailPO.Detail detail : detailPO.getDetailList()) {
|
||||
String productName = detail.getProductName();
|
||||
String number = detail.getNumber();
|
||||
String number = Convert.toBigDecimal(detail.getNumber()).setScale(0).toPlainString();
|
||||
String amount = toPlainStr(detail.getAmount());
|
||||
//58mm的机器,一行打印16个汉字,32个字母; 80mm的机器,一行打印24个汉字,48个字母
|
||||
//展示4列 b1代表名称列占用(14个字节) b2单价列(6个字节) b3数量列(3个字节) b4金额列(6个字节)-->这里的字节数可按自己需求自由改写,14+6+3+6再加上代码写的3个空格就是32了,58mm打印机一行总占32字节
|
||||
//String row = FeieYunUtil.getRow(productName, "",number, amount, 14, 6,3, 6)
|
||||
//展示3列 b1代表名称列占用(20个字节) b2单价列(0个字节) b3数量列(3个字节) b4金额列(6个字节)-->这里的字节数可按自己需求自由改写,20+0+3+6再加上代码写的3个空格就是32了,58mm打印机一行总占32字节
|
||||
String row = FeieYunUtil.getRow(productName, "", number, amount, 20, 0, 3, 6);
|
||||
String row = FeieYunUtil.getRow(productName, "", " "+number, amount, 20, 0, 4, 6);
|
||||
data.append(row);
|
||||
if (StrUtil.isBlank(detail.getSpec())) {
|
||||
if (StrUtil.isNotBlank(detail.getSpec())) {
|
||||
data.append("规格:" + detail.getSpec() + "<BR>");
|
||||
}
|
||||
String proGroupInfo = detail.getProGroupInfo();
|
||||
if (StrUtil.isBlank(proGroupInfo)) {
|
||||
continue;
|
||||
}
|
||||
data.append("规格:" + detail.getSpec() + "<BR>");
|
||||
if (!JSONUtil.isJsonArray(proGroupInfo)) {
|
||||
continue;
|
||||
}
|
||||
JSONArray subItems = JSONUtil.parseArray(proGroupInfo);
|
||||
for (int i = 0; i < subItems.size(); i++) {
|
||||
String proName = subItems.getJSONObject(i).getStr("proName");
|
||||
int qty = subItems.getJSONObject(i).getInt("number");
|
||||
String subRow = FeieYunUtil.getRow(" - "+proName, "", qty+"", "0.00", 20, 0, 4, 6);
|
||||
data.append(subRow);
|
||||
}
|
||||
}
|
||||
log.error("打印数据>>>>>>>>>>>>>>>>>>>>>:{}{}", detailPO.getDiscountAmount(), detailPO.getDiscountAdio());
|
||||
if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) {
|
||||
@@ -256,9 +276,9 @@ public class FeieyunPrintUtil {
|
||||
} else {
|
||||
data.append(StrUtil.format("<B>应收:{}</B><BR>", t));
|
||||
}
|
||||
data.append("--------------------------------<BR>");
|
||||
if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) {
|
||||
data.append(StrUtil.format("储值:{}<BR>", toPlainStr(detailPO.getReceiptsAmount())));
|
||||
data.append("--------------------------------<BR>");
|
||||
data.append(StrUtil.format("积分:{}<BR>", detailPO.getIntegral()));
|
||||
}
|
||||
data.append(StrUtil.format("余额:{}<BR>", toPlainStr(detailPO.getBalance())));
|
||||
@@ -506,7 +526,7 @@ public class FeieyunPrintUtil {
|
||||
|
||||
public static void testPrint() {
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽","");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
@@ -529,7 +549,7 @@ public class FeieyunPrintUtil {
|
||||
*/
|
||||
public static void testPrint2() {
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽","");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
@@ -549,7 +569,7 @@ public class FeieyunPrintUtil {
|
||||
*/
|
||||
public static void testPrint3() {
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽","");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.ProductInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.ProductInfoPO;
|
||||
@@ -79,7 +81,7 @@ public class PrinterUtils {
|
||||
* @param remark sku规格名
|
||||
* @param note 备注
|
||||
*/
|
||||
public static String getPrintData(String type, String pickupNumber, String date, String productName, Integer number, String remark, String note) {
|
||||
public static String getPrintData(String type, String pickupNumber, String date, String productName, Integer number, String remark, String note, String proGroupInfo) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if ("return".equals(type)) {
|
||||
builder.append("<C><B>").append(pickupNumber).append("【退】</B></C><BR><BR>");
|
||||
@@ -102,6 +104,14 @@ public class PrinterUtils {
|
||||
if (StrUtil.isNotBlank(note)) {
|
||||
builder.append("<S><L>备注: ").append(note == null ? "" : note).append(" </L></S><BR>");
|
||||
}
|
||||
if (!StrUtil.isBlank(proGroupInfo) && cn.hutool.json.JSONUtil.isJsonArray(proGroupInfo)) {
|
||||
JSONArray subItems = cn.hutool.json.JSONUtil.parseArray(proGroupInfo);
|
||||
for (int i = 0; i < subItems.size(); i++) {
|
||||
String proName = subItems.getJSONObject(i).getStr("proName");
|
||||
int qty = subItems.getJSONObject(i).getInt("number");
|
||||
builder.append("<CS:32>("+(i+1)+")"+proName + " x " + qty + "</CS><BR>");
|
||||
}
|
||||
}
|
||||
builder.append("<OUT:150>");
|
||||
builder.append("<PCUT>");
|
||||
return builder.toString();
|
||||
@@ -109,91 +119,74 @@ public class PrinterUtils {
|
||||
|
||||
|
||||
public static String getCashPrintData(OrderDetailPO detailPO, String type, String orderType) {
|
||||
|
||||
log.info("getCashPrintData detailPO:{},type:{},orderType:{}", JSONUtil.toJSONString(detailPO), type, orderType);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<C><B>").append(detailPO.getMerchantName()).append("</B></C><BR><BR>");
|
||||
sb.append("<C><BOLD>").append(type).append("【").append(detailPO.getMasterId()).append("】</BOLD></C><BR><BR>");
|
||||
if (Objects.nonNull(detailPO.getOutNumber())) {
|
||||
sb.append("<CB><BOLD>").append(detailPO.getOutNumber()).append("</BOLD></CB><BR><BR>");
|
||||
}
|
||||
|
||||
sb.append("<S><L>订单号: ").append(detailPO.getOrderNo()).append(" </L></S><BR>");
|
||||
sb.append("<S><L>交易时间: ").append(detailPO.getTradeDate()).append(" </L></S><BR>");
|
||||
sb.append("<S><L>收银员: ").append(detailPO.getOperator()).append(" </L></S><BR><BR><BR>");
|
||||
char paddingCharacter = ' ';
|
||||
sb.append("<S>").append(String.format("%-15s", "品名").replace(' ', paddingCharacter)).append(String.format("%-4s", "数量").replace(' ', paddingCharacter)).append(String.format("%4s", "小计").replace(' ', paddingCharacter)).append("<S><BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
StringBuffer data = new StringBuffer();
|
||||
data.append(StrUtil.format("<C><F>{}</F></C><BR>", detailPO.getMerchantName()));
|
||||
data.append("<BR>");
|
||||
data.append("<OUT:30>");
|
||||
data.append(StrUtil.format("<C><BOLD>{}【{}】</BOLD></C><BR>", type, detailPO.getMasterId()));
|
||||
//if (Objects.nonNull(detailPO.getOutNumber())) {
|
||||
// data.append(StrUtil.format("<CB><BOLD>{}</BOLD></CB>",detailPO.getOutNumber()));
|
||||
//}
|
||||
data.append("<OUT:30>");
|
||||
data.append("<BR>");
|
||||
data.append(StrUtil.format("<S>订单号:{}</S><BR>", detailPO.getOrderNo()));
|
||||
data.append(StrUtil.format("<S>交易时间:{}</S><BR>", detailPO.getTradeDate()));
|
||||
data.append(StrUtil.format("<S>收银员:{}</S><BR>", detailPO.getOperator()));
|
||||
data.append("<OUT:15>");
|
||||
data.append("<BR>");
|
||||
data.append("<S>品名 数量 小计</S><BR>");
|
||||
data.append("<S>--------------------------------</S><BR>");
|
||||
for (OrderDetailPO.Detail detail : detailPO.getDetailList()) {
|
||||
|
||||
if (detail.getProductName().length() > 4 && detail.getProductName().length() <= 10) {
|
||||
|
||||
int count = getProducrName(detail.getProductName());
|
||||
if (count <= 0) {
|
||||
int length = 15 - (detail.getProductName().length() - 4);
|
||||
sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
|
||||
} else {
|
||||
int length = 15 + count - (detail.getProductName().length() - 4);
|
||||
sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
|
||||
}
|
||||
|
||||
} else if (detail.getProductName().length() > 10) {
|
||||
|
||||
sb.append("<S>").append(detail.getProductName()).append("</S><BR>");
|
||||
sb.append("<S>").append(String.format("%20s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%11s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
|
||||
|
||||
} else {
|
||||
sb.append("<S>").append(String.format("%-15s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
|
||||
String number = Convert.toBigDecimal(detail.getNumber()).setScale(0).toPlainString();
|
||||
String row = YunXiangYinUtil.getRow(detail.getProductName(), "", " " + number, toPlainStr(detail.getAmount()), 20, 0, 4, 6);
|
||||
data.append(row);
|
||||
if (StrUtil.isNotBlank(detail.getSpec())) {
|
||||
data.append("<S>规格:").append(detail.getSpec()).append("</S><BR>");
|
||||
}
|
||||
|
||||
if (detail.getSpec() != null && ObjectUtil.isNotEmpty(detail.getSpec())) {
|
||||
sb.append("<S>规格:").append(detail.getSpec()).append("</S><BR>");
|
||||
String proGroupInfo = detail.getProGroupInfo();
|
||||
if (StrUtil.isBlank(proGroupInfo)) {
|
||||
continue;
|
||||
}
|
||||
if (!cn.hutool.json.JSONUtil.isJsonArray(proGroupInfo)) {
|
||||
continue;
|
||||
}
|
||||
JSONArray subItems = cn.hutool.json.JSONUtil.parseArray(proGroupInfo);
|
||||
for (int i = 0; i < subItems.size(); i++) {
|
||||
String proName = subItems.getJSONObject(i).getStr("proName");
|
||||
int qty = subItems.getJSONObject(i).getInt("number");
|
||||
String subRow = YunXiangYinUtil.getRow(" - "+proName, "", " "+qty, "0.00", 20, 0, 4, 6);
|
||||
data.append(subRow);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) {
|
||||
sb.append("------------------------<BR>");
|
||||
sb.append("<S>原价:".concat(String.format("%15s", toPlainStr(detailPO.getReceiptsAmount())).replace(' ', paddingCharacter)).concat("</S><BR>"));
|
||||
sb.append("<S>折扣: ".concat(String.format("%15s", "-".concat(toPlainStr(detailPO.getDiscountAmount()))).replace(' ', paddingCharacter)).concat("</S><BR>"));
|
||||
data.append("<S>--------------------------------</S><BR>");
|
||||
data.append(StrUtil.format("<S>原价:{}</S><BR>", toPlainStr(detailPO.getReceiptsAmount())));
|
||||
data.append(StrUtil.format("<S>折扣:-{}</S><BR>", toPlainStr(detailPO.getDiscountAmount())));
|
||||
}
|
||||
|
||||
|
||||
sb.append("------------------------<BR>");
|
||||
data.append("<S>--------------------------------</S><BR>");
|
||||
String t = "¥" + (ObjectUtil.isEmpty(detailPO.getDiscountAmount()) || ObjectUtil.isNull(detailPO.getDiscountAmount()) ? toPlainStr(detailPO.getReceiptsAmount()) : NumberUtil.sub(new BigDecimal(detailPO.getReceiptsAmount()), new BigDecimal(detailPO.getDiscountAmount())).setScale(2, RoundingMode.DOWN).toPlainString());
|
||||
t = String.format("%11s", t).replace(' ', paddingCharacter);
|
||||
if (orderType.equals("return")) {
|
||||
sb.append("<F>应退" + t + "</F><BR>");
|
||||
data.append("<F>应退" + t + "</F><BR>");
|
||||
data.append(StrUtil.format("<F>应收:{}</F><BR>", t));
|
||||
} else {
|
||||
sb.append("<F>实付" + t + "</F><BR>");
|
||||
|
||||
data.append(StrUtil.format("<F>应收:{}</F><BR>", t));
|
||||
}
|
||||
data.append("<S>--------------------------------</S><BR>");
|
||||
if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) {
|
||||
sb.append("<S>储值¥" + toPlainStr(detailPO.getReceiptsAmount()) + " </S><BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
sb.append("<S>积分:" + detailPO.getIntegral() + "</S><BR>");
|
||||
data.append(StrUtil.format("<S>储值:{}</S><BR>", toPlainStr(detailPO.getReceiptsAmount())));
|
||||
data.append(StrUtil.format("<S>积分:{}</S><BR>", detailPO.getIntegral()));
|
||||
}
|
||||
|
||||
sb.append("<S>余额:" + toPlainStr(detailPO.getBalance()) + "</S><BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
|
||||
if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) {
|
||||
sb.append("<L>备注:" + detailPO.getRemark() + "</L><BR>");
|
||||
}
|
||||
|
||||
|
||||
data.append(StrUtil.format("<S>余额:{}</S><BR>", toPlainStr(detailPO.getBalance())));
|
||||
data.append("<S>--------------------------------</S><BR>");
|
||||
data.append(StrUtil.format("<L><BOLD>备注:{}</BOLD></L><BR>", detailPO.getRemark()));
|
||||
if (Objects.nonNull(detailPO.getOutNumber())) {
|
||||
sb.append("<QR>".concat(detailPO.getOutNumber()).concat("</QR><BR>"));
|
||||
data.append("<QR>".concat(detailPO.getOutNumber()).concat("</QR><BR>"));
|
||||
}
|
||||
|
||||
|
||||
sb.append("<S>打印时间:" + DateUtils.getTime(new Date()) + "</S><BR>");
|
||||
|
||||
sb.append("<OUT:180>");
|
||||
sb.append("<PCUT>");
|
||||
return sb.toString();
|
||||
|
||||
data.append("<S>打印时间:" + DateUtils.getTime(new Date()) + "</S><BR>");
|
||||
data.append("<OUT:180>");
|
||||
data.append("<PCUT>");
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
private static String toPlainStr(String str) {
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tankaikai
|
||||
* @since 2024-10-15 15:12
|
||||
*/
|
||||
@UtilityClass
|
||||
public class YunXiangYinUtil {
|
||||
|
||||
public String titleAddSpace(String str, int b1) {
|
||||
int k = 0;
|
||||
int b = b1;
|
||||
try {
|
||||
k = str.getBytes("GBK").length;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (int i = 0; i < b - k; i++) {
|
||||
str += " ";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String getStringByEnter(int length, String string) throws Exception {
|
||||
for (int i = 1; i <= string.length(); i++) {
|
||||
if (string.substring(0, i).getBytes("GBK").length > length) {
|
||||
return "<S>" + string.substring(0, i - 1) + "</S><BR>" + getStringByEnter(length, string.substring(i - 1));
|
||||
}
|
||||
}
|
||||
return "<S>" + string + "</S>";
|
||||
}
|
||||
|
||||
public static String addSpace(String str, int size) {
|
||||
int len = str.length();
|
||||
if (len < size) {
|
||||
for (int i = 0; i < size - len; i++) {
|
||||
str += " ";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static Boolean isEn(String str) {
|
||||
Boolean b = false;
|
||||
try {
|
||||
b = str.getBytes("GBK").length == str.length();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public static List<String> getStrList(String inputString, int length) {
|
||||
int size = inputString.length() / length;
|
||||
if (inputString.length() % length != 0) {
|
||||
size += 1;
|
||||
}
|
||||
return getStrList(inputString, length, size);
|
||||
}
|
||||
|
||||
public static List<String> getStrList(String inputString, int length, int size) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (int index = 0; index < size; index++) {
|
||||
String childStr = substring(inputString, index * length, (index + 1) * length);
|
||||
list.add(childStr);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String substring(String str, int f, int t) {
|
||||
if (f > str.length()) {
|
||||
return null;
|
||||
}
|
||||
if (t > str.length()) {
|
||||
return str.substring(f, str.length());
|
||||
} else {
|
||||
return str.substring(f, t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对齐后的小票明细行数据
|
||||
* 58mm的机器,一行打印16个汉字,32个字母;80mm的机器,一行打印24个汉字,48个字母
|
||||
* b1代表名称列占用字节 b2单价列 b3数量列 b4金额列-->这里的字节数可按自己需求自由改写
|
||||
*
|
||||
* @param title 品名
|
||||
* @param price 单价
|
||||
* @param num 数量
|
||||
* @param total 小计
|
||||
* @param b1 品名占用字节
|
||||
* @param b2 单价占用字节
|
||||
* @param b3 数量占用字节
|
||||
* @param b4 小计占用字节
|
||||
* @return 对齐后的行数据
|
||||
*/
|
||||
public static String getRow(String title, String price, String num, String total, int b1, int b2, int b3, int b4) {
|
||||
price = addSpace(price, b2);
|
||||
num = addSpace(num, b3);
|
||||
total = addSpace(total, b4);
|
||||
String otherStr = " " + price + num + " " + total;
|
||||
int tl = 0;
|
||||
try {
|
||||
tl = title.getBytes("GBK").length;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int spaceNum = (tl / b1 + 1) * b1 - tl;
|
||||
if (tl < b1) {
|
||||
for (int k = 0; k < spaceNum; k++) {
|
||||
title += " ";
|
||||
}
|
||||
title += otherStr;
|
||||
title = "<S>" + title + "</S>";
|
||||
} else if (tl == b1) {
|
||||
title += otherStr;
|
||||
title = "<S>" + title + "</S>";
|
||||
} else {
|
||||
List<String> list = null;
|
||||
if (isEn(title)) {
|
||||
list = getStrList(title, b1);
|
||||
} else {
|
||||
list = getStrList(title, b1 / 2);
|
||||
}
|
||||
String s0 = titleAddSpace(list.get(0), b1);
|
||||
title = "<S>"+s0 + otherStr + "</S><BR>";// 添加 单价 数量 总额
|
||||
String s = "";
|
||||
for (int k = 1; k < list.size(); k++) {
|
||||
s += list.get(k);
|
||||
}
|
||||
try {
|
||||
s = getStringByEnter(b1, s);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
title += s;
|
||||
}
|
||||
return title + "<BR>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user