|
@@ -1,22 +1,19 @@
|
|
|
package com.gzlh.device.print.test;
|
|
|
|
|
|
import cn.hutool.core.codec.Base64Decoder;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.github.anastaciocintra.escpos.EscPos;
|
|
|
-import com.github.anastaciocintra.escpos.EscPosConst;
|
|
|
-import com.github.anastaciocintra.escpos.Style;
|
|
|
import com.github.anastaciocintra.escpos.image.*;
|
|
|
import com.github.anastaciocintra.output.TcpIpOutputStream;
|
|
|
import com.gzlh.bus.SysConfig;
|
|
|
-import com.gzlh.config.SystemObject;
|
|
|
import com.gzlh.device.led.factory.LedFactory;
|
|
|
import com.gzlh.device.led.utils.LedOptions;
|
|
|
import com.gzlh.device.print.bo.BeiHaiWeightReport;
|
|
|
+import com.gzlh.device.print.handler.impl.PrintYingMeiHandler;
|
|
|
import com.gzlh.utils.EpsonCommands;
|
|
|
import com.gzlh.utils.WordHandlerUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -25,8 +22,6 @@ import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.net.Socket;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
@@ -44,31 +39,45 @@ public class JMPrintThread implements Runnable {
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ LedFactory ledFactory = SpringUtil.getBean(LedFactory.class);
|
|
|
+ String line = SysConfig.serialSetting.getLed().getLine();
|
|
|
+ if (StrUtil.isEmpty(line)) {
|
|
|
+ line = "03";
|
|
|
+ }
|
|
|
+ LedOptions options = new LedOptions().setLine(line);
|
|
|
+ int count = 10;
|
|
|
+ while (PrintYingMeiHandler.connect) {
|
|
|
+ count--;
|
|
|
+ if (count <= 0) {
|
|
|
+ ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg("打印机连接异常", options);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ThreadUtil.sleep(100);
|
|
|
+ }
|
|
|
try {
|
|
|
log.info("start print:{}", JSONUtil.toJsonStr(printBO));
|
|
|
- SystemObject.printFactory.handler(SysConfig.serialSetting.getPrint().getBrand()).close();
|
|
|
Charset charset = Charset.forName("GB2312");
|
|
|
- String title = " "+SysConfig.serialSetting.getPrint().getPrintTitle() + "\n";
|
|
|
+ String title = " " + SysConfig.serialSetting.getPrint().getPrintTitle() + "\n";
|
|
|
TcpIpOutputStream tcpIpOutputStream = new TcpIpOutputStream(SysConfig.serialSetting.getPrint().getIp(), SysConfig.serialSetting.getPrint().getPort());
|
|
|
EscPos escpos = new EscPos(tcpIpOutputStream);
|
|
|
- ThreadUtil.sleep(2000);
|
|
|
Bitonal algorithm = new BitonalThreshold(160);
|
|
|
escpos.initializePrinter();
|
|
|
escpos.setCharsetName("GB2312");
|
|
|
- byte[] zhFontSize = hexToBytes("1C2108");
|
|
|
+ byte[] zhFontSize = WordHandlerUtils.hexToBytes("1C2108");
|
|
|
byte[] titleData = EpsonCommands.mergerByteArray(
|
|
|
- hexToBytes("1B6101"),
|
|
|
- hexToBytes("1C210B"),
|
|
|
+ WordHandlerUtils.hexToBytes("1B6101"),
|
|
|
+ WordHandlerUtils.hexToBytes("1C210B"),
|
|
|
title.getBytes(charset),
|
|
|
- hexToBytes("0D0A")
|
|
|
+ WordHandlerUtils.hexToBytes("0D0A")
|
|
|
);
|
|
|
escpos.write(titleData, 0, titleData.length);
|
|
|
- byte[] numberFontSize = hexToBytes("1B2110");
|
|
|
+ byte[] numberFontSize = WordHandlerUtils.hexToBytes("1B2110");
|
|
|
String text =
|
|
|
" 货主/货代: " + printBO.getWWB_CST_OWNER() + " \n" +
|
|
|
" 船名: " + printBO.getWWB_VLS_VCNNM() + "\n" +
|
|
|
" 船次: " + printBO.getWWB_VIW_VOYAGE() + " \n" +
|
|
|
" 唛头: " + printBO.getWB_MARKERNO() + " \n" +
|
|
|
+ " 电子单号: " + printBO.getWWB_ID() + " \n" +
|
|
|
" 货名: " + printBO.getWWB_GOODSNAME() + "\n" +
|
|
|
" 车号: " + printBO.getWWB_TRUCKNO() + "\n" +
|
|
|
" 毛重: " + printBO.getWWB_CAR_GW() + "吨\n" +
|
|
@@ -84,13 +93,13 @@ public class JMPrintThread implements Runnable {
|
|
|
String at = text.charAt(i) + "";
|
|
|
byte[] atByte = at.getBytes(charset);
|
|
|
if (NumberUtil.isNumber(at)) {
|
|
|
- atByte=at.getBytes(StandardCharsets.UTF_8);
|
|
|
- printData = EpsonCommands.mergerByteArray(printData,numberFontSize, atByte);
|
|
|
+ atByte = at.getBytes(StandardCharsets.UTF_8);
|
|
|
+ printData = EpsonCommands.mergerByteArray(printData, numberFontSize, atByte);
|
|
|
} else {
|
|
|
- printData = EpsonCommands.mergerByteArray(printData,zhFontSize, atByte);
|
|
|
+ printData = EpsonCommands.mergerByteArray(printData, zhFontSize, atByte);
|
|
|
}
|
|
|
}
|
|
|
- // byte[] str = text.getBytes(charset);
|
|
|
+ // byte[] str = text.getBytes(charset);
|
|
|
byte[] data = EpsonCommands.mergerByteArray(
|
|
|
EpsonCommands.printLineHeight((byte) 30), EpsonCommands.alignLeft(),
|
|
|
printData, EpsonCommands.printLineFeed((byte) 1));
|
|
@@ -109,12 +118,6 @@ public class JMPrintThread implements Runnable {
|
|
|
escpos.write(footer, 0, footer.length);
|
|
|
escpos.close();
|
|
|
log.info("print done======:{}", JSONUtil.toJsonStr(printBO));
|
|
|
- LedFactory ledFactory = SpringUtil.getBean(LedFactory.class);
|
|
|
- String line = SysConfig.serialSetting.getLed().getLine();
|
|
|
- if (StrUtil.isEmpty(line)) {
|
|
|
- line = "03";
|
|
|
- }
|
|
|
- LedOptions options = new LedOptions().setLine(line);
|
|
|
ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg("已成功打印小票,请取走小票", options);
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -130,13 +133,5 @@ public class JMPrintThread implements Runnable {
|
|
|
return sb.toString().toUpperCase();
|
|
|
}
|
|
|
|
|
|
- public static byte[] hexToBytes(String hex) {
|
|
|
- int len = hex.length();
|
|
|
- byte[] data = new byte[len / 2];
|
|
|
- for (int i = 0; i < len; i += 2) {
|
|
|
- data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
|
|
|
- + Character.digit(hex.charAt(i + 1), 16));
|
|
|
- }
|
|
|
- return data;
|
|
|
- }
|
|
|
+
|
|
|
}
|