feat:增加自动创建路径
This commit is contained in:
parent
8095ead92c
commit
02c725de01
|
@ -9,6 +9,7 @@ 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.FolderUtils;
|
||||
import com.dpkj.modules.print.utils.PDFUtils;
|
||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -36,6 +37,8 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
|||
|
||||
@Override
|
||||
public LexMarkResultDTO<?> printImage(MS439Request request) {
|
||||
FolderUtils.checkFolderAndCreate(request.getFileDir());
|
||||
|
||||
// 校验是本地地址还是http开头的
|
||||
PDFUtils.AddressType addressType = PDFUtils.checkAddressType(request.getFileDir());
|
||||
if (addressType.equals(PDFUtils.AddressType.HTTP)) {
|
||||
|
|
|
@ -11,7 +11,9 @@ import com.dpkj.common.utils.TemplateUtils;
|
|||
import com.dpkj.common.utils.ThirdService;
|
||||
import com.dpkj.modules.print.enums.*;
|
||||
import com.dpkj.modules.print.service.PrintService;
|
||||
import com.dpkj.modules.print.utils.FolderUtils;
|
||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||
import jdk.jfr.Frequency;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
@ -47,6 +49,8 @@ public class RegisterServiceImpl implements PrintService {
|
|||
|
||||
@Override
|
||||
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
FolderUtils.checkFolderAndCreate(saveDir);
|
||||
|
||||
if (height <= 0) {
|
||||
width = FIXED_WIDTH;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.dpkj.modules.print.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 文件夹处理
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-03-31 17:28:34
|
||||
*/
|
||||
@Slf4j
|
||||
public class FolderUtils {
|
||||
|
||||
public static void checkFolderAndCreate(String folderPath){
|
||||
File fileOrFolder = new File(folderPath);
|
||||
String targetPath;
|
||||
if (fileOrFolder.isFile()) {
|
||||
// 如果是文件,获取文件所在目录路径
|
||||
targetPath = fileOrFolder.getParent();
|
||||
} else {
|
||||
// 如果不是文件(可能是不存在的文件夹或已存在的文件夹),使用原始路径
|
||||
targetPath = folderPath;
|
||||
}
|
||||
|
||||
File targetFolder = new File(targetPath);
|
||||
if (!targetFolder.exists()) {
|
||||
boolean success = targetFolder.mkdirs();
|
||||
if (success) {
|
||||
log.info("文件夹创建成功: " + targetPath);
|
||||
} else {
|
||||
log.error("文件夹创建失败: " + targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue