修改打印小票

dev-discount
胡锐 3 years ago
parent c8b3bfabd9
commit 6c81bea107
  1. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  2. 18
      hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java
  3. 182
      hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java
  4. 55
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java

File diff suppressed because one or more lines are too long

@ -1,5 +1,9 @@
package com.hai.config; package com.hai.config;
import com.hai.common.utils.DateUtil;
import java.util.Date;
/** /**
* 商鹏打印机模板 * 商鹏打印机模板
* @author hurui * @author hurui
@ -21,17 +25,20 @@ public class SpPrinterTemplate {
public static String oilCashierStubTemp(String gasName, public static String oilCashierStubTemp(String gasName,
String orderNo, String orderNo,
String payTime, String payTime,
String phone,
String source, String source,
String gunNo, String gunNo,
String oilNo, String oilNo,
String oilLiters, String oilLiters,
String orderPrice) { String orderPrice) throws Exception {
String str = "<C><B>" + gasName + "</B></C> <BR> " + String str = "<C><B>" + gasName + "</B></C> <BR> " +
"<C>(收银员存根)</C> <BR>" + "<C>(收银员存根)</C> <BR>" +
"------------------------------<BR>" + "------------------------------<BR>" +
"流水:" + orderNo + "<BR>" + "流水:" + orderNo + "<BR>" +
"------------------------------<BR>" + "------------------------------<BR>" +
"时间:" + payTime + "<BR>" + "打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
"支付时间:" + payTime + "<BR>" +
"电话:" + phone.substring(0, 3) + "****" + phone.substring(7) + "<BR>" +
"来源:" + source + "<BR>" + "来源:" + source + "<BR>" +
"油枪:"+ gunNo + "号<BR>" + "油枪:"+ gunNo + "号<BR>" +
"油品:" + oilNo + "#<BR>" + "油品:" + oilNo + "#<BR>" +
@ -60,17 +67,20 @@ public class SpPrinterTemplate {
public static String oilClientStubTemp(String gasName, public static String oilClientStubTemp(String gasName,
String orderNo, String orderNo,
String payTime, String payTime,
String phone,
String source, String source,
String gunNo, String gunNo,
String oilNo, String oilNo,
String oilLiters, String oilLiters,
String orderPrice) { String orderPrice) throws Exception {
String str = "<C><B>" + gasName + "</B></C> <BR> " + String str = "<C><B>" + gasName + "</B></C> <BR> " +
"<C>(客户存根)</C> <BR>" + "<C>(客户存根)</C> <BR>" +
"------------------------------<BR>" + "------------------------------<BR>" +
"流水:" + orderNo + "<BR>" + "流水:" + orderNo + "<BR>" +
"------------------------------<BR>" + "------------------------------<BR>" +
"时间:" + payTime + "<BR>" + "打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
"支付时间:" + payTime + "<BR>" +
"电话:" + phone.substring(0, 3) + "****" + phone.substring(7) + "<BR>" +
"来源:" + source + "<BR>" + "来源:" + source + "<BR>" +
"油枪:"+ gunNo + "号<BR>" + "油枪:"+ gunNo + "号<BR>" +
"油品:" + oilNo + "#<BR>" + "油品:" + oilNo + "#<BR>" +

@ -11,6 +11,180 @@ import java.util.Date;
*/ */
public class ZkcPrinterTemplate { public class ZkcPrinterTemplate {
/**
* 加油站
* @param gasName 油站名称
* @param orderNo 订单号
* @param payTime 支付时间
* @param source 来源
* @param gunNo 抢号
* @param oilNo 油号
* @param oilLiters 升数
* @param orderPrice 加油金额
* @return
*/
public static byte[] oilTemp(String gasName,
String orderNo,
String payTime,
String phone,
String source,
String gunNo,
String oilNo,
String oilLiters,
String orderPrice) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// 居中
stream.write(0x1B);
stream.write(0x61);
stream.write(0x01);
stream.write(gasName.getBytes("UTF-8"));
stream.write(0x0A);
stream.write("(收银员存根)".getBytes("UTF-8"));
stream.write(0x0A);
// 左对齐
stream.write(0x1B);
stream.write(0x61);
stream.write(0x00);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("流水号:" + orderNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("油枪:" + gunNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("油品:" + oilNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("升数:" + oilLiters + "升").getBytes("UTF-8"));
stream.write(0x0A);
stream.write("实际加油升数以加油机为准!".getBytes("UTF-8"));
stream.write(0x0A);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x0E);
stream.write("加油金额".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("¥" + orderPrice).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x21);
stream.write(0x00);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x61);
stream.write(0x01);
stream.write("开心又省钱;来“ 嗨森逛 ”".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
// 居中
stream.write(0x1B);
stream.write(0x61);
stream.write(0x01);
stream.write(gasName.getBytes("UTF-8"));
stream.write(0x0A);
stream.write("(客户存根)".getBytes("UTF-8"));
stream.write(0x0A);
// 左对齐
stream.write(0x1B);
stream.write(0x61);
stream.write(0x00);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("流水号:" + orderNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("油枪:" + gunNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("油品:" + oilNo).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("升数:" + oilLiters + "升").getBytes("UTF-8"));
stream.write(0x0A);
stream.write("实际加油升数以加油机为准!".getBytes("UTF-8"));
stream.write(0x0A);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x0E);
stream.write("加油金额".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("¥" + orderPrice).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x21);
stream.write(0x00);
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x1B);
stream.write(0x61);
stream.write(0x01);
stream.write("开心又省钱;来“ 嗨森逛 ”".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
return getPrinterBytes(stream.toByteArray(), 1, "UTF-8");
}
/** /**
* 加油站收银员存根模板 * 加油站收银员存根模板
* @param gasName 油站名称 * @param gasName 油站名称
@ -26,6 +200,7 @@ public class ZkcPrinterTemplate {
public static byte[] oilCashierStubTemp(String gasName, public static byte[] oilCashierStubTemp(String gasName,
String orderNo, String orderNo,
String payTime, String payTime,
String phone,
String source, String source,
String gunNo, String gunNo,
String oilNo, String oilNo,
@ -60,6 +235,9 @@ public class ZkcPrinterTemplate {
stream.write(("支付时间:" + payTime).getBytes("UTF-8")); stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A); stream.write(0x0A);
stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8")); stream.write("来源:嗨森逛".getBytes("UTF-8"));
stream.write(0x0A); stream.write(0x0A);
@ -119,6 +297,7 @@ public class ZkcPrinterTemplate {
public static byte[] oilClientStubTemp(String gasName, public static byte[] oilClientStubTemp(String gasName,
String orderNo, String orderNo,
String payTime, String payTime,
String phone,
String source, String source,
String gunNo, String gunNo,
String oilNo, String oilNo,
@ -154,6 +333,9 @@ public class ZkcPrinterTemplate {
stream.write(("支付时间:" + payTime).getBytes("UTF-8")); stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A); stream.write(0x0A);
stream.write(("电话:" + phone.substring(0, 3) + "****" + phone.substring(7)).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8")); stream.write("来源:嗨森逛".getBytes("UTF-8"));
stream.write(0x0A); stream.write(0x0A);

@ -1674,28 +1674,42 @@ public class HighOrderServiceImpl implements HighOrderService {
new Thread(() -> { new Thread(() -> {
try { try {
SpPrinterConfig sp = new SpPrinterConfig(); SpPrinterConfig sp = new SpPrinterConfig();
sp.print(device.getDeviceSn(),
SpPrinterTemplate.oilCashierStubTemp( String printStr = SpPrinterTemplate.oilCashierStubTemp(
childOrder.getGoodsName(), childOrder.getGoodsName(),
order.getOrderNo(), order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
"嗨森逛", order.getMemPhone(),
childOrder.getGasGunNo(), "嗨森逛",
childOrder.getGasOilNo(), childOrder.getGasGunNo(),
childOrder.getGasOilLiters().toString(), childOrder.getGasOilNo(),
order.getTotalPrice().toString() childOrder.getGasOilLiters().toString(),
), 1); order.getTotalPrice().toString()
sp.print(device.getDeviceSn(), ) + "<BR><BR><BR><BR><BR>" +
SpPrinterTemplate.oilClientStubTemp(
childOrder.getGoodsName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
"嗨森逛",
childOrder.getGasGunNo(),
childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString()
) + "<BR>";
sp.print(device.getDeviceSn(), printStr, 1);
/* sp.print(device.getDeviceSn(),
SpPrinterTemplate.oilClientStubTemp( SpPrinterTemplate.oilClientStubTemp(
childOrder.getGoodsName(), childOrder.getGoodsName(),
order.getOrderNo(), order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
"嗨森逛", "嗨森逛",
childOrder.getGasGunNo(), childOrder.getGasGunNo(),
childOrder.getGasOilNo(), childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(), childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString() order.getTotalPrice().toString()
), 1); ), 1);*/
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1706,28 +1720,17 @@ public class HighOrderServiceImpl implements HighOrderService {
new Thread(() -> { new Thread(() -> {
try { try {
mqttProviderConfig.publish(2, false, device.getDeviceImei(), mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilCashierStubTemp( ZkcPrinterTemplate.oilTemp(
childOrder.getGoodsName(), childOrder.getGoodsName(),
order.getOrderNo(), order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
"嗨森逛", "嗨森逛",
childOrder.getGasGunNo(), childOrder.getGasGunNo(),
childOrder.getGasOilNo(), childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(), childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString() order.getTotalPrice().toString()
)); ));
mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilClientStubTemp(
childOrder.getGoodsName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
"嗨森逛",
childOrder.getGasGunNo(),
childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString()
));
} catch (Exception e) { } catch (Exception e) {
e.getMessage(); e.getMessage();
} }

Loading…
Cancel
Save