feat:增加自动创建路径
This commit is contained in:
parent
9e13e1eaf0
commit
ab35bef704
|
@ -9,6 +9,7 @@ import com.dpkj.modules.autoReplyPrint.enums.ReceiptTemplateEnum;
|
||||||
import com.dpkj.modules.autoReplyPrint.request.ReceiptPrintRequest;
|
import com.dpkj.modules.autoReplyPrint.request.ReceiptPrintRequest;
|
||||||
import com.dpkj.modules.autoReplyPrint.service.ImagePrintService;
|
import com.dpkj.modules.autoReplyPrint.service.ImagePrintService;
|
||||||
import com.dpkj.modules.autoReplyPrint.service.impl.TemplateService;
|
import com.dpkj.modules.autoReplyPrint.service.impl.TemplateService;
|
||||||
|
import com.dpkj.modules.autoReplyPrint.utils.FolderUtils;
|
||||||
import com.dpkj.modules.autoReplyPrint.vo.PrinterStatus;
|
import com.dpkj.modules.autoReplyPrint.vo.PrinterStatus;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -48,6 +49,8 @@ public class ReceiptPrintController {
|
||||||
|
|
||||||
@PostMapping("/print")
|
@PostMapping("/print")
|
||||||
private Result<Void> print(@Validated @RequestBody ReceiptPrintRequest request) throws UnsupportedEncodingException {
|
private Result<Void> print(@Validated @RequestBody ReceiptPrintRequest request) throws UnsupportedEncodingException {
|
||||||
|
FolderUtils.checkFolderAndCreate(request.getFileDir());
|
||||||
|
|
||||||
String devName = "VID:0x0FE6,PID:0x811E"; // 采用默认的devName,不进行入参传值了
|
String devName = "VID:0x0FE6,PID:0x811E"; // 采用默认的devName,不进行入参传值了
|
||||||
String templateName = ReceiptTemplateEnum.getTemplateName(request.getTemplateName());
|
String templateName = ReceiptTemplateEnum.getTemplateName(request.getTemplateName());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.dpkj.modules.autoReplyPrint.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