From 51ec98113c6d49d0f7eec4e3c030e55e337e97db Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期一, 26 五月 2025 15:47:16 +0800 Subject: [PATCH] 芯导软件(江苏)有限公司 delete --- framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java b/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java index 00e2ca6..8ffb2d1 100644 --- a/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java +++ b/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java @@ -6,12 +6,16 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.FileSystemUtils; +import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; + import javax.annotation.PostConstruct; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * 淇濆瓨鏂囦欢宸ュ叿 @@ -23,10 +27,15 @@ // 鍙杫ml涓殑璺緞 + / private static String FILE_PATH; + private static String WORD_URL_PATH; + private static String[] ALLOWED; @Value("${file.path}") private String file; + + @Value("${wordUrl}") + private String wordUrl; @Value("${file.allowed}") private String[] allowed; @@ -34,6 +43,11 @@ @PostConstruct public void getFile() { FILE_PATH = this.file; + } + + @PostConstruct + public void getWordUrl(){ + WORD_URL_PATH = this.wordUrl; } @PostConstruct @@ -69,6 +83,9 @@ } public static Boolean DeleteFile(String fileName) { + if (ObjectUtils.isEmpty(fileName)) { + return false; + } return FileSystemUtils.deleteRecursively(new File(FILE_PATH + "/" + fileName)); } /** @@ -109,4 +126,37 @@ } return false; } + + + /** + * 淇濆瓨鏂囦欢鍒皐ord鏂囦欢澶归噷 + * @param file + * @return + */ + public static String uploadWordFile(MultipartFile file) { + String urlString; + String pathName; + String path; + try { + String contentType = file.getContentType(); + if (contentType != null && contentType.startsWith("image/")) { + // 鏄浘鐗� + path = FILE_PATH; + } else { + // 鏄枃浠� + path = WORD_URL_PATH; + } + File realpath = new File(path); + if (!realpath.exists()) { + realpath.mkdirs(); + } + pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "-" + file.getOriginalFilename(); + urlString = realpath + "/" + pathName; + file.transferTo(new File(urlString)); + return pathName; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } } -- Gitblit v1.9.3