Преглед на файлове

Merge remote-tracking branch 'origin/V0.0.1' into V0.0.1

jingyuanchao преди 2 години
родител
ревизия
baf4461f02
променени са 1 файла, в които са добавени 27 реда и са изтрити 7 реда
  1. 27 7
      soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java

+ 27 - 7
soc-modules/soc-modules-file/src/main/java/com/xunmei/file/controller/SysFileController.java

@@ -9,10 +9,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
@@ -37,6 +34,13 @@ public class SysFileController
     @Value("${file.secretKey}")
     public String secretKey;
 
+    @Value("${file.domain}")
+    public String networkAdd;
+
+    @Value("${file.prefix}")
+    public String prefix;
+
+
 
     private static final String FILE_SUFFIX = "FILE_CODE_";
 
@@ -52,8 +56,9 @@ public class SysFileController
             String url = sysFileService.uploadFile(file);
             SysFile sysFile = new SysFile();
             sysFile.setName(FileUtils.getName(url));
-            sysFile.setUrl(url);
             String code = DesUtil.encrypt(url, secretKey);
+            url = prefix + url;
+            sysFile.setUrl(url);
             sysFile.setCode(code);
             return R.ok(sysFile);
         }
@@ -73,8 +78,9 @@ public class SysFileController
             String url = sysFileService.uploadFile(file,busType);
             SysFile sysFile = new SysFile();
             sysFile.setName(FileUtils.getName(url));
-            sysFile.setUrl(url);
             String code = DesUtil.encrypt(url, secretKey);
+            url = prefix + url;
+            sysFile.setUrl(url);
             sysFile.setCode(code);
             return R.ok(sysFile);
         }
@@ -96,7 +102,21 @@ public class SysFileController
             log.error("下载文件失败", e);
             throw new RuntimeException(e);
         }
+    }
 
-
+    /**
+     * 路径参数
+     * @param response
+     * @param code
+     */
+    @GetMapping("/getFile/{code}")
+    public void getFile(HttpServletResponse response, @PathVariable String code){
+        try {
+            String filePath = DesUtil.decode(code, secretKey);
+            sysFileService.downloadFile(response,filePath);
+        } catch (Exception e) {
+            log.error("下载文件失败", e);
+            throw new RuntimeException(e);
+        }
     }
 }