From 972daa6f2c0d72d40a74387eb0f04acc09750c11 Mon Sep 17 00:00:00 2001
From: whycrzg <ruanzhigang@whycst.com>
Date: 星期五, 02 四月 2021 17:26:25 +0800
Subject: [PATCH] 修改 文档材料存储路径

---
 src/main/java/com/whyc/controller/ProjectManageController.java |   55 ++++++++++++-------------------------------------------
 1 files changed, 12 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/whyc/controller/ProjectManageController.java b/src/main/java/com/whyc/controller/ProjectManageController.java
index 9b8e63c..055290c 100644
--- a/src/main/java/com/whyc/controller/ProjectManageController.java
+++ b/src/main/java/com/whyc/controller/ProjectManageController.java
@@ -2,6 +2,7 @@
 
 import com.github.pagehelper.PageInfo;
 import com.whyc.config.MyProps;
+import com.whyc.config.ServerConfig;
 import com.whyc.dto.Response;
 import com.whyc.pojo.ProjectArchiveManage;
 import com.whyc.pojo.ProjectManage;
@@ -34,6 +35,9 @@
 
     @Autowired
     private MyProps myProps;
+
+    @Autowired
+    private ServerConfig serverConfig;
 
     @Autowired
     private ProjectProcessManageService service;
@@ -75,6 +79,7 @@
         return response;
     }
 
+
     /**
      * 鏂囦欢瀛樺偍鍚庡湴鍧�鏇存柊鍒板搴旈」鐩紪鍙风殑鍦板潃锛屼竴涓」鐩搴斿涓枃浠� db_experiment.tb_project_archive_manage
      * 鏄惁闇�瑕佸皢word杞琾df/棰勮鏂囦欢pdf
@@ -82,45 +87,6 @@
      * @param file
      * @return
      */
-    @PostMapping("upload")
-    @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�", value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡娣诲姞(閫夋嫨鏂囦欢)")
-    public Response upload(@RequestParam("file") MultipartFile file) {
-        // 鑾峰彇鍘熷鍚嶅瓧
-        String originalFilename = file.getOriginalFilename();
-        // 鑾峰彇鍚庣紑鍚�
-        // String suffixName = fileName.substring(fileName.lastIndexOf("."));
-        // 鏂囦欢淇濆瓨璺緞銆佸悗鏈熻�冭檻鎸夋棩鏈熸垨鑰呮湀浠藉缓dir
-        String filePath = myProps.getFilePath();
-        // 鏂囦欢閲嶅懡鍚嶏紝闃叉閲嶅,棰勮鏃堕渶瑕佹樉绀哄師鏂囦欢鍚� _ 鍒囧壊
-        String fileName = filePath + UUID.randomUUID() + "_" + originalFilename;
-        // 鏂囦欢瀵硅薄
-        File dest = new File(fileName);
-        // 鍒ゆ柇璺緞鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欏垱寤�
-        if (!dest.getParentFile().exists()) {
-            dest.getParentFile().mkdirs();
-        }
-        Response<Object> response = new Response<>();
-        HashMap<Object, Object> map = new HashMap<>();
-        try {
-            // 淇濆瓨鍒版湇鍔″櫒涓�
-            file.transferTo(dest);
-            map.put("fileType", file.getContentType());
-            map.put("name", originalFilename);
-            Double size = file.getSize() * 0.01 / 1024 / 1024 * 100;
-            String douStr = String.format("%.2f", size);
-            map.put("fileSize", douStr+" M");
-            map.put("url",fileName);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return response.setMsg(0, "涓婁紶澶辫触");
-        }
-        response.setCode(1);
-        response.setData(map);
-        return response;
-    }
-
-
-
     @PostMapping("/uploads")
     @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�", value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡娣诲姞(澶氶��)")
     public Response uploads(MultipartFile[] file) throws IOException {
@@ -130,26 +96,29 @@
         }
 
         ArrayList<Object> list = new ArrayList<>();
+//            String filePath = myProps.getFilePath();
+        String uploadPath = FileUtils.getProjectPath();
+//        System.out.println("uploadPath = " + uploadPath);
         for (MultipartFile multipartFile : file) {
             if (multipartFile.isEmpty()) {
                 return response.setMsg(0, "璇烽�夋嫨瑕佷笂浼犵殑鏂囦欢");
             }
             byte[] fileBytes = multipartFile.getBytes();
-            String filePath = myProps.getFilePath();
             //鍙栧緱褰撳墠涓婁紶鏂囦欢鐨勬枃浠跺悕绉�
             String originalFilename = multipartFile.getOriginalFilename();
             //鐢熸垚鏂囦欢鍚�
             String fileName = UUID.randomUUID() + "_" + originalFilename;
 
             HashMap<Object, Object> map = new HashMap<>();
+            map.put("name", originalFilename);
+            String url = serverConfig.getUrl();
+            map.put("url", url + "/uploadFile/" + fileName);
             try {
-                FileUtils.uploadFile(fileBytes, filePath, fileName);
+                FileUtils.uploadFile(fileBytes, uploadPath, fileName);
             } catch (IOException e) {
                 e.printStackTrace();
                 return response.setMsg(0, "涓婁紶澶辫触");
             }
-            map.put("fileName", originalFilename);
-            map.put("url", filePath + fileName);
             list.add(map);
 
         }

--
Gitblit v1.9.1