瀏覽代碼

1、修改上传附件

zhoux 2 年之前
父節點
當前提交
c9cdffa1ab
共有 1 個文件被更改,包括 27 次插入2 次删除
  1. 27 2
      src/main/java/com/dk/mdm/controller/FileController.java

+ 27 - 2
src/main/java/com/dk/mdm/controller/FileController.java

@@ -11,7 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
-import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.UUID;
 import java.util.UUID;
 
 
 @RestController
 @RestController
@@ -45,7 +45,8 @@ public class FileController {
             JSONObject json = new JSONObject();
             JSONObject json = new JSONObject();
             json.put("path", filePath.replace(uploadPath, ""));
             json.put("path", filePath.replace(uploadPath, ""));
             json.put("name", fileName);
             json.put("name", fileName);
-            json.put("createTime", LocalDate.now());
+            json.put("type",getFileType(fileName));
+            json.put("createTime", LocalDateTime.now());
             return ResponseResultUtil.success(json);
             return ResponseResultUtil.success(json);
         } catch (IOException e) {
         } catch (IOException e) {
             e.printStackTrace();
             e.printStackTrace();
@@ -54,6 +55,30 @@ public class FileController {
     }
     }
 
 
     /**
     /**
+     * @desc   : 获取文件类型
+     * @author : 周兴
+     * @date   : 2024-03-27 14:09
+     */
+    private String getFileType(String fileName) {
+        String[] arr = fileName.split(".");
+        String fileType = arr[arr.length - 1].toLowerCase();
+
+        if (fileType == "jpg" || fileType == "jepg" || fileType == "png") {
+            return "img";
+        }
+        if (fileType == "mp4" || fileType == "avi" || fileType == "mov") {
+            return "video";
+        }
+        if (fileType == "xls" || fileType == "xlsx") {
+            return "excel";
+        }
+        if (fileType == "pdf") {
+            return "pdf";
+        }
+        return "";
+    }
+
+    /**
      * @desc   : 根据类型创建目录文件夹
      * @desc   : 根据类型创建目录文件夹
      * @author : 洪旭东
      * @author : 洪旭东
      * @date   : 2023-06-26 14:10
      * @date   : 2023-06-26 14:10