From 087991c76f078defe5eb55d84223021b4199fb3d Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期一, 17 二月 2025 11:22:50 +0800 Subject: [PATCH] 设备模块修改bug --- framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 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 195b688..8ffb2d1 100644 --- a/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java +++ b/framework/src/main/java/com/yuanchu/mom/utils/FileSaveUtil.java @@ -14,6 +14,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * 淇濆瓨鏂囦欢宸ュ叿 @@ -25,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; @@ -36,6 +43,11 @@ @PostConstruct public void getFile() { FILE_PATH = this.file; + } + + @PostConstruct + public void getWordUrl(){ + WORD_URL_PATH = this.wordUrl; } @PostConstruct @@ -114,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