删除无关模块
This commit is contained in:
parent
b2b9f15f79
commit
f029719a42
|
@ -1,88 +0,0 @@
|
|||
package com.dpkj.modules.express.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.dpkj.common.config.FileConfig;
|
||||
import com.dpkj.common.vo.Result;
|
||||
import com.dpkj.modules.express.service.PrinterService;
|
||||
import com.dpkj.modules.express.utils.FileUtils;
|
||||
import com.dpkj.modules.express.utils.PrinterUtil;
|
||||
import com.dpkj.modules.express.vo.Print;
|
||||
import com.dpkj.modules.express.vo.PrinterStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Auther: 萧道子
|
||||
* @Date: 2024/4/28 13:58
|
||||
* @Description: 打印机
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("printer")
|
||||
public class PrinterController {
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
@Autowired
|
||||
private FileConfig fileConfig;
|
||||
|
||||
/**
|
||||
* 获取打印机状态
|
||||
*
|
||||
* @return com.dpkj.common.vo.Result
|
||||
* @author 萧道子 2024/4/28
|
||||
*/
|
||||
@GetMapping("status")
|
||||
public Result getStatus() {
|
||||
try {
|
||||
PrinterStatus val = printerService.getPrinterStatus();
|
||||
return Result.ok("获取成功", val);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("[printer][PrinterController.getStatus]获取打印机状态失败 {}", e.getMessage());
|
||||
return Result.error("打印机状态获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印文件
|
||||
*
|
||||
* @return com.dpkj.common.vo.Result
|
||||
* @author 萧道子 2024/4/29
|
||||
*/
|
||||
@PostMapping("print")
|
||||
public Result print(@RequestBody Print val) {
|
||||
try {
|
||||
String base64 = val.getBase64();
|
||||
if (StrUtil.isEmpty(base64)) throw new Exception("参数缺失!");
|
||||
|
||||
List<File> files = FileUtils.saveBase64ToBmp(base64);
|
||||
if (files.isEmpty()) throw new Exception("打印失败,面单未生成!");
|
||||
|
||||
File file = files.get(0);
|
||||
String filePath = file.getAbsolutePath();
|
||||
Integer num = printerService.printBmpByPath(filePath);// 打印
|
||||
FileUtil.del(file); // 删除文件
|
||||
|
||||
if (num != 0) throw new Exception("打印失败,请检查打印机是否连接正常!");
|
||||
|
||||
return Result.ok("打印成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.info("[printer][PrinterController.print] 打印面单 {}", e.getMessage());
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.dpkj.modules.express.service;
|
||||
|
||||
import com.dpkj.modules.express.utils.PrinterUtil;
|
||||
import com.dpkj.modules.express.vo.PrinterStatus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PrinterService {
|
||||
|
||||
/**
|
||||
* 获取打印机状态
|
||||
*
|
||||
* @return com.dpkj.modules.express.vo.PrinterStatus
|
||||
* @author 萧道子 2024/4/28
|
||||
*/
|
||||
PrinterStatus getPrinterStatus();
|
||||
|
||||
/**
|
||||
* 通过路径打印BMP文件
|
||||
*
|
||||
* @param path :
|
||||
* @return java.lang.Integer
|
||||
* @author 萧道子 2024/4/29
|
||||
*/
|
||||
Integer printBmpByPath(String path) throws Exception;
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
package com.dpkj.modules.express.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.dpkj.common.config.PrinterConfig;
|
||||
import com.dpkj.modules.express.service.PrinterService;
|
||||
import com.dpkj.modules.express.utils.PrinterUtil;
|
||||
import com.dpkj.modules.express.vo.PrinterStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Auther: 萧道子
|
||||
* @Date: 2024/4/28 14:34
|
||||
* @Description:
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PrinterServiceImpl implements PrinterService {
|
||||
@Resource
|
||||
private PrinterConfig printerConfig;
|
||||
|
||||
private PrinterUtil.MsPrintSdk printSDK = PrinterUtil.getPrintSDK();
|
||||
|
||||
public PrinterServiceImpl() throws PrinterUtil.PrinterRegistrationException {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
log.info("[printer] 打印机初始化");
|
||||
initPrinter();
|
||||
}
|
||||
|
||||
private void initPrinter() {
|
||||
if (StrUtil.equals(printerConfig.getConnectionType(), "USB")) {
|
||||
// USB连接
|
||||
Integer n = printSDK.SetUsbportauto();
|
||||
log.info("[printer][SetUsbportauto] USB自动识别 {}", n);
|
||||
} else {
|
||||
// 串口连接
|
||||
String portName = printerConfig.getPortName();
|
||||
Integer baudRate = printerConfig.getBaudRate();
|
||||
Integer n = printSDK.SetPrintPort(portName, baudRate);
|
||||
log.info("[printer][SetPrintPort] 串口配置 {}", n);
|
||||
}
|
||||
Integer n = printSDK.SetInit();
|
||||
log.info("[printer][SetInit] 初始化打印机设置 {}", n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrinterStatus getPrinterStatus() {
|
||||
Integer num = printSDK.GetStatusspecial();
|
||||
PrinterStatus statusVo = getStatusVo(num);
|
||||
return statusVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer printBmpByPath(String path) {
|
||||
initPrinter();
|
||||
|
||||
String formattedFilePath = path.replace("\\", "\\\\");
|
||||
int n = printSDK.PrintDiskimgfile(formattedFilePath);
|
||||
log.info("[printer][PrintDiskimgfile] 打印BMP文件 {}", n);
|
||||
|
||||
printMarkpositioncut();
|
||||
// printMarkcutpaper();
|
||||
printCutpaper();
|
||||
return n;
|
||||
}
|
||||
|
||||
private PrinterStatus getStatusVo(Integer num) {
|
||||
PrinterStatus val = new PrinterStatus().setValue(num);
|
||||
switch (num) {
|
||||
case 0:
|
||||
val.setText("打印机正常");
|
||||
break;
|
||||
case 1:
|
||||
val.setText("打印机未连接或未上电");
|
||||
break;
|
||||
case 2:
|
||||
val.setText("打印机和调用库不匹配");
|
||||
break;
|
||||
case 3:
|
||||
val.setText("当前使用打印机无特殊功能");
|
||||
break;
|
||||
case 4:
|
||||
val.setText("容纸器没有可靠上纸");
|
||||
break;
|
||||
case 5:
|
||||
val.setText("纸张堵在出票口,持续堆叠");
|
||||
break;
|
||||
case 6:
|
||||
val.setText("卡纸");
|
||||
break;
|
||||
case 7:
|
||||
val.setText("拽纸");
|
||||
break;
|
||||
case 8:
|
||||
val.setText("出纸传感器有纸");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检测黑标进纸到切纸位置
|
||||
*/
|
||||
private Integer printMarkpositioncut() {
|
||||
int n = printSDK.PrintMarkpositioncut();
|
||||
log.info("[printer][PrintMarkpositioncut] 检测黑标进纸到切纸位置 {}", n);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印切纸
|
||||
*/
|
||||
private Integer printCutpaper() {
|
||||
int n = printSDK.PrintCutpaper(0);
|
||||
log.info("[printer][PrintCutpaper] 打印切纸 {}", n);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 黑标切纸
|
||||
*/
|
||||
private Integer printMarkcutpaper() {
|
||||
int n = printSDK.PrintMarkcutpaper(0);
|
||||
log.info("[printer][printMarkcutpaper] 打印黑标切纸 {}", n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检测黑标进纸到打印位置
|
||||
*/
|
||||
private Integer printMarkpositionPrint() {
|
||||
int n = printSDK.PrintMarkpositionPrint();
|
||||
log.info("[printer][printMarkpositionPrint] 检测黑标进纸到打印位置 {}", n);
|
||||
return n;
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
package com.dpkj.modules.express.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.dpkj.common.config.FileConfig;
|
||||
import org.apache.pdfbox.Loader;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Auther: 萧道子
|
||||
* @Date: 2024/4/29 14:47
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
public class FileUtils {
|
||||
|
||||
private static FileConfig fileConfig;
|
||||
|
||||
@Autowired
|
||||
public void setFileConfig(FileConfig fileConfig) {
|
||||
this.fileConfig = fileConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* base64Pdf 转字节流
|
||||
*
|
||||
* @param base64Pdf :
|
||||
* @return java.util.List<java.awt.image.BufferedImage>
|
||||
* @author 萧道子 2024/4/29
|
||||
*/
|
||||
public static List<BufferedImage> convertBase64PdfToBufferedImage(String base64Pdf) throws IOException {
|
||||
List<BufferedImage> images = new ArrayList<>();
|
||||
base64Pdf = base64Pdf.replaceAll("[^A-Za-z0-9+/=]", "");
|
||||
byte[] base64Bytes = Base64.getDecoder().decode(base64Pdf);
|
||||
PDDocument document = Loader.loadPDF(base64Bytes);
|
||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||
for (int i = 0; i < document.getNumberOfPages(); i++) {
|
||||
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(i, 188);
|
||||
int h = bufferedImage.getHeight();
|
||||
int w = bufferedImage.getWidth();
|
||||
int x = 15;
|
||||
int y = 28;
|
||||
// int y = new BigDecimal(0.03).multiply(new BigDecimal(h)).setScale(0, BigDecimal.ROUND_UP).intValue();
|
||||
BufferedImage croppedImageTopOne = bufferedImage.getSubimage(x, y, w - x, h - y);
|
||||
images.add(croppedImageTopOne);
|
||||
}
|
||||
document.close();
|
||||
return images;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将BufferedImage 保存为 BMP文件
|
||||
*
|
||||
* @param images :
|
||||
* @return java.util.List<java.io.File>
|
||||
* @author 萧道子 2024/4/29
|
||||
*/
|
||||
public static List<File> saveBufferedImageToBmp(List<BufferedImage> images) throws IOException {
|
||||
List<File> fileList = new ArrayList<>();
|
||||
String path = fileConfig.getPath();
|
||||
// 创建文件夹
|
||||
FileUtil.mkdir(fileConfig.getPath());
|
||||
for (BufferedImage bufferedImage : images) {
|
||||
String filePath = path + "/" + IdUtil.simpleUUID() + ".bmp";
|
||||
filePath = FileUtil.normalize(filePath);
|
||||
File bmpFile = new File(filePath);
|
||||
// 使用ImageIO将BufferedImage保存为BMP文件
|
||||
ImageIO.write(bufferedImage, "BMP", bmpFile);
|
||||
fileList.add(bmpFile);
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将base64保存为Bmp文件
|
||||
*
|
||||
* @param base64 :
|
||||
* @return java.util.List<java.io.File>
|
||||
* @author 萧道子 2024/4/29
|
||||
*/
|
||||
public static List<File> saveBase64ToBmp(String base64) throws IOException {
|
||||
List<BufferedImage> bufferedImages = FileUtils.convertBase64PdfToBufferedImage(base64);
|
||||
List<File> files = FileUtils.saveBufferedImageToBmp(bufferedImages);
|
||||
return files;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
package com.dpkj.modules.express.utils;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
public class PrinterUtil {
|
||||
|
||||
/**
|
||||
* 获取 MsPrintSdk 实例,同时注册 MsPrintSdk 控件。
|
||||
*
|
||||
* @return MsPrintSdk 实例
|
||||
* @throws PrinterRegistrationException 如果注册控件失败,抛出此异常
|
||||
*/
|
||||
public static MsPrintSdk getPrintSDK() throws PrinterRegistrationException {
|
||||
/* String ocxPath = "src/lib/Msprintsdk.ocx";
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("regsvr32", "/s", ocxPath);
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
int exitCode = process.waitFor();
|
||||
// if (exitCode != 0) {
|
||||
// throw new PrinterRegistrationException("Failed to register MsPrintSdk OCX. Exit code: " + exitCode);
|
||||
// }
|
||||
} catch (InterruptedException | IOException e) {
|
||||
throw new PrinterRegistrationException("Error occurred while registering MsPrintSdk OCX.", e);
|
||||
}*/
|
||||
|
||||
try {
|
||||
return Native.load("Msprintsdk.x64", MsPrintSdk.class);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
log.info("[printer][PrinterUtil.getPrintSDK] SDK注册失败 {}", e.getMessage());
|
||||
throw new PrinterRegistrationException("Failed to load MsPrintSdk library: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void convertAndPassStringAsJCharArray(String filePath) {
|
||||
// 将字符串转换为char[]
|
||||
char[] chars = filePath.toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义接口映射本地库中的函数。
|
||||
*/
|
||||
public interface MsPrintSdk extends Library {
|
||||
|
||||
/**
|
||||
* 设置打印端口和波特率。
|
||||
*
|
||||
* @param strPort 打印端口名
|
||||
* @param baudRate 波特率
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer SetPrintPort(String strPort, int baudRate);
|
||||
|
||||
/**
|
||||
* 设置打印连接方式、名称和值。
|
||||
*
|
||||
* @param iConnWay 连接方式
|
||||
* @param strName 名称
|
||||
* @param strValue 值
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer SetPrintConn(int iConnWay, String strName, String strValue);
|
||||
|
||||
/**
|
||||
* 设置 USB 端口自动识别。
|
||||
*
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer SetUsbportauto();
|
||||
|
||||
/**
|
||||
* 获取打印机状态。
|
||||
* 0 打印机正常
|
||||
* 1 打印机未连接或未上电
|
||||
* 2 打印机和调用库不匹配
|
||||
* 3 打印头打开
|
||||
* 4 切刀未复位
|
||||
* 5 打印头温度异常
|
||||
* 6 黑标错误,可能的情况为 黑标传感器坏 | 使用错误白纸 | 黑标不标准,浓度偏低
|
||||
* 7 纸尽
|
||||
* 8 纸将尽
|
||||
*
|
||||
* @return 返回打印机状态代码 0:成功 1:失败
|
||||
*/
|
||||
Integer GetStatus();
|
||||
|
||||
/**
|
||||
* 获取打印机特殊功能状态
|
||||
* 0 打印机正常
|
||||
* 1 打印机未连接或未上电
|
||||
* 2 打印机和调用库不匹配
|
||||
* 3 当前使用打印机无特殊功能
|
||||
* 4 容纸器没有可靠上纸
|
||||
* 5 纸张堵在出票口,持续堆叠
|
||||
* 6 卡纸,出纸口未堵的情况下,胶辊无法驱动纸持续前进了。 比如纸卷在胶辊上了、切刀堵住了纸的前进、纸张被拉住无法前进等
|
||||
* 7 拽纸,打印机感受到凭条被外力拖拽
|
||||
* 8 出纸传感器有纸
|
||||
*
|
||||
* @return 返回打印机状态代码 0:成功 1:失败
|
||||
*/
|
||||
Integer GetStatusspecial();
|
||||
|
||||
/**
|
||||
* 初始化打印机设置。
|
||||
*
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer SetInit();
|
||||
|
||||
/**
|
||||
* 打印二维码。
|
||||
*
|
||||
* @param s 二维码数据
|
||||
* @param i 参数 i
|
||||
* @param i1 参数 i1
|
||||
* @param i2 参数 i2
|
||||
*/
|
||||
void PrintQrcode(String s, int i, int i1, int i2);
|
||||
|
||||
/**
|
||||
* 设置左边距。
|
||||
*
|
||||
* @param i 左边距值
|
||||
*/
|
||||
void SetLeftmargin(int i);
|
||||
|
||||
/**
|
||||
* 打印字符串。
|
||||
*
|
||||
* @param s 字符串内容
|
||||
* @param i 参数 i
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer PrintString(String s, int i);
|
||||
|
||||
/**
|
||||
* 打印剩余的二维码。
|
||||
*
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer PrintRemainQR();
|
||||
|
||||
/**
|
||||
* 设置 设置汉字模式 模式。
|
||||
*
|
||||
* @param i 模式参数
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer SetReadZKmode(int i);
|
||||
|
||||
/**
|
||||
* 切纸。
|
||||
*
|
||||
* @param i 切纸参数
|
||||
* 0 全切
|
||||
* 1 半切
|
||||
* @return 返回操作结果代码
|
||||
*/
|
||||
Integer PrintCutpaper(int i);
|
||||
|
||||
/**
|
||||
* 设置 HT 座位信息。
|
||||
*
|
||||
* @param s 座位信息
|
||||
* @param i 参数 i
|
||||
*/
|
||||
void SetHTseat(String s, int i);
|
||||
|
||||
/**
|
||||
* 打印下一个 HT 数据。
|
||||
*/
|
||||
void PrintNextHT();
|
||||
|
||||
/**
|
||||
* 打印BMP
|
||||
*
|
||||
* @param strPath BMP文件路径
|
||||
*/
|
||||
Integer PrintDiskbmpfile(String strPath);
|
||||
|
||||
/**
|
||||
* 打印BMP
|
||||
*
|
||||
* @param strPath BMP文件路径
|
||||
*/
|
||||
Integer PrintDiskimgfile(String strPath);
|
||||
|
||||
|
||||
/**
|
||||
* 检测黑标进纸到打印位置
|
||||
*/
|
||||
Integer PrintMarkpositionPrint();
|
||||
|
||||
/**
|
||||
* 检测黑标进纸到切纸位置
|
||||
*/
|
||||
Integer PrintMarkpositioncut();
|
||||
|
||||
/**
|
||||
* 打印黑标切纸
|
||||
* <p>
|
||||
* 0 检测黑标全切
|
||||
* 1 不检测黑标半切
|
||||
*/
|
||||
Integer PrintMarkcutpaper(int iMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义自定义异常类,用于表示注册控件时发生的错误
|
||||
*/
|
||||
public static class PrinterRegistrationException extends Exception {
|
||||
public PrinterRegistrationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PrinterRegistrationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.dpkj.modules.express.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Auther: 萧道子
|
||||
* @Date: 2024/4/29 17:03
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Print implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String base64;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.dpkj.modules.express.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Auther: 萧道子
|
||||
* @Date: 2024/4/28 14:44
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PrinterStatus implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String text;
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -1,79 +0,0 @@
|
|||
package com.dpkj.ems.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.dpkj.Application;
|
||||
import com.dpkj.common.config.FileConfig;
|
||||
import com.dpkj.modules.express.service.PrinterService;
|
||||
import com.dpkj.modules.express.utils.FileUtils;
|
||||
import com.dpkj.modules.express.utils.PrinterUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
|
||||
class PrinterUtilTest {
|
||||
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
@Autowired
|
||||
private FileConfig fileConfig;
|
||||
|
||||
@Test
|
||||
void getPrintSDK() throws PrinterUtil.PrinterRegistrationException {
|
||||
PrinterUtil.MsPrintSdk sdk = PrinterUtil.getPrintSDK();
|
||||
int i = sdk.SetUsbportauto();
|
||||
Console.log(i);
|
||||
|
||||
int i1 = sdk.SetInit();
|
||||
Console.log(i1);
|
||||
|
||||
int i2 = sdk.GetStatusspecial();
|
||||
Console.log(i2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void t2() throws IOException {
|
||||
String base64Path = "G:\\Temp\\text\\base64.txt";
|
||||
String base64 = FileUtil.readString(FileUtil.file(base64Path), StandardCharsets.UTF_8);
|
||||
|
||||
String bpmPath = "G:\\Temp\\img";
|
||||
List<BufferedImage> bufferedImages = FileUtils.convertBase64PdfToBufferedImage(base64);
|
||||
FileUtils.saveBufferedImageToBmp(bufferedImages);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void t3() throws Exception {
|
||||
String base64Path = "G:\\Temp\\text\\base64.txt";
|
||||
String base64 = FileUtil.readString(FileUtil.file(base64Path), StandardCharsets.UTF_8);
|
||||
|
||||
// String bpmPath = "G:\\Temp\\img";
|
||||
String bpmPath = fileConfig.getPath();
|
||||
List<BufferedImage> bufferedImages = FileUtils.convertBase64PdfToBufferedImage(base64);
|
||||
List<File> files = FileUtils.saveBufferedImageToBmp(bufferedImages);
|
||||
|
||||
/*for (File file : files) {
|
||||
String filePath = file.getAbsolutePath();
|
||||
printerService.printBmpByPath(filePath);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Test
|
||||
void t4() throws IOException {
|
||||
String base64Path = "G:\\Temp\\text\\base64.txt";
|
||||
String base64 = FileUtil.readString(FileUtil.file(base64Path), StandardCharsets.UTF_8);
|
||||
|
||||
List<BufferedImage> bufferedImages = FileUtils.convertBase64PdfToBufferedImage(base64);
|
||||
System.out.println(bufferedImages);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.dpkj.ems.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.dpkj.modules.express.utils.FileUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
class PrinterUtilTest2 {
|
||||
|
||||
@Test
|
||||
void t4() throws IOException {
|
||||
String base64Path = "G:\\Temp\\text\\base64.txt";
|
||||
String base64 = FileUtil.readString(FileUtil.file(base64Path), StandardCharsets.UTF_8);
|
||||
|
||||
List<BufferedImage> bufferedImages = FileUtils.convertBase64PdfToBufferedImage(base64);
|
||||
System.out.println(bufferedImages);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue