diff --git a/pom.xml b/pom.xml
index d958cce..86af71a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
1.8
- 5.8.25
+ 5.8.36
5.14.0
3.0.2
@@ -54,6 +54,12 @@
${hutool.version}
+
+ cn.hutool
+ hutool-all
+ ${hutool.version}
+
+
net.java.dev.jna
@@ -119,12 +125,6 @@
3.1.28
-
- cn.hutool
- hutool-all
- 5.8.15
-
-
javax.validation
diff --git a/src/main/java/com/dpkj/modules/print/service/impl/MS439PrintServiceImpl.java b/src/main/java/com/dpkj/modules/print/service/impl/MS439PrintServiceImpl.java
index 40aba89..3a1951e 100644
--- a/src/main/java/com/dpkj/modules/print/service/impl/MS439PrintServiceImpl.java
+++ b/src/main/java/com/dpkj/modules/print/service/impl/MS439PrintServiceImpl.java
@@ -8,11 +8,13 @@ import com.dpkj.common.utils.ThirdService;
import com.dpkj.modules.print.enums.*;
import com.dpkj.modules.print.request.MS439Request;
import com.dpkj.modules.print.service.MS439PrintService;
+import com.dpkj.modules.print.utils.PDFUtils;
import com.dpkj.modules.print.vo.PrinterStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
+import java.io.File;
import java.util.Objects;
/**
@@ -31,6 +33,12 @@ public class MS439PrintServiceImpl implements MS439PrintService {
@Override
public LexMarkResultDTO> printImage(MS439Request request) {
+ // 校验是本地地址还是http开头的
+ PDFUtils.AddressType addressType = PDFUtils.checkAddressType(request.getFileDir());
+ if (addressType.equals(PDFUtils.AddressType.HTTP)) {
+ request.setFileDir(PDFUtils.downloadPdf(request.getFileDir()));
+ }
+
LexMarkResultDTO status = this.getStatus(request.getPagesource());
PrinterStatus ms439 = status.getData();
@@ -78,7 +86,19 @@ public class MS439PrintServiceImpl implements MS439PrintService {
lexMarkDTO.setParam(param.toString());
LexMarkResultDTO paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
-// thirdService.close("HtmPrinter");
+
+ File file = new File(request.getFileDir());
+ // 检查文件是否存在
+ if (file.exists()) {
+ // 尝试删除文件
+ if (file.delete()) {
+ log.info("文件删除成功: " + request.getFileDir());
+ } else {
+ log.info("文件删除失败: " + request.getFileDir());
+ }
+ } else {
+ log.info("文件不存在: " + request.getFileDir());
+ }
return paramLexMarkResultDTO;
}
diff --git a/src/main/java/com/dpkj/modules/print/utils/PDFUtils.java b/src/main/java/com/dpkj/modules/print/utils/PDFUtils.java
new file mode 100644
index 0000000..fef9af9
--- /dev/null
+++ b/src/main/java/com/dpkj/modules/print/utils/PDFUtils.java
@@ -0,0 +1,88 @@
+package com.dpkj.modules.print.utils;
+
+import com.dpkj.common.exception.RRException;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+
+@Slf4j
+public class PDFUtils {
+
+ private static final String defaultPath = "D:/images";
+
+ public enum AddressType {
+ HTTP,
+ LOCAL,
+ OTHER,
+ UNKNOWN
+ }
+
+ /**
+ * 校验地址类型
+ * @param address 地址
+ */
+ public static AddressType checkAddressType(String address) {
+ if (address == null || address.isEmpty()) {
+ return AddressType.UNKNOWN;
+ }
+
+ // 检查是否为 HTTP 或 HTTPS 地址
+ if (address.startsWith("http://") || address.startsWith("https://")) {
+ return AddressType.HTTP;
+ }
+
+ // 简单判断是否为本地地址
+ // 本地地址可能以文件协议 file:// 开头,或者是一个相对路径或绝对路径
+ if (address.startsWith("file://") ||
+ (address.contains(":") && address.contains("\\")) ||
+ (address.startsWith("/"))) {
+ return AddressType.LOCAL;
+ }
+
+ return AddressType.OTHER;
+ }
+
+ public static String downloadPdf(String pdfUrl) {
+ String savePath = defaultPath + "/genera_image_" + System.currentTimeMillis() + ".pdf";
+ try {
+ // 创建 URL 对象
+ URL url = new URL(pdfUrl);
+ // 打开 HTTP 连接
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ // 设置请求方法为 GET
+ connection.setRequestMethod("GET");
+
+ // 获取响应码
+ int responseCode = connection.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ // 获取输入流
+ try (InputStream inputStream = connection.getInputStream();
+ // 创建文件输出流
+ FileOutputStream outputStream = new FileOutputStream(savePath)) {
+
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ // 循环读取数据并写入文件
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ log.info("PDF 文件下载成功,保存路径: " + savePath);
+ }
+ } else {
+ log.error("下载失败,响应码: " + responseCode);
+ }
+ // 断开连接
+ connection.disconnect();
+ }catch (Exception e) {
+ throw new RRException("PDF文件下载失败");
+ }
+
+ return savePath;
+ }
+
+
+}