hexiao 2 years ago
parent
commit
f8ff8a5dcb

+ 13 - 13
purchase-admin/src/main/java/com/ozs/web/controller/common/CommonController.java

@@ -6,6 +6,7 @@ import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.ozs.common.vo.FileDownVo;
 import com.ozs.system.domain.SysFileInfo;
 import com.ozs.system.service.SysFileService;
 import io.swagger.annotations.Api;
@@ -13,10 +14,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import com.ozs.common.config.PurchaseConfig;
 import com.ozs.common.constant.Constants;
@@ -50,22 +49,23 @@ public class CommonController {
     /**
      * 通用下载请求
      *
-     * @param fileName 文件名称
-     * @param delete   是否删除
      */
-    @GetMapping("/download")
-    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
+    @PostMapping("/download")
+    public void fileDownload(@RequestBody FileDownVo vo, HttpServletResponse response, HttpServletRequest request) {
         try {
-            if (!FileUtils.checkAllowDownload(fileName)) {
-                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            if(ObjectUtils.isEmpty(vo)){
+                throw new Exception("参数不能为空");
             }
-            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
-            String filePath = PurchaseConfig.getDownloadPath() + fileName.substring("/profile/upload/".length(),fileName.length());
+            if (!FileUtils.checkAllowDownload(vo.getFileName())) {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", vo.getFileName()));
+            }
+            String realFileName = System.currentTimeMillis() + vo.getFileName().substring(vo.getFileName().indexOf("_") + 1);
+            String filePath = PurchaseConfig.getDownloadPath() + vo.getFileName().substring("/profile/upload/".length(),vo.getFileName().length());
 
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
             FileUtils.setAttachmentResponseHeader(response, realFileName);
             FileUtils.writeBytes(filePath, response.getOutputStream());
-            if (delete) {
+            if (vo.getDelete()) {
                 FileUtils.deleteFile(filePath);
             }
         } catch (Exception e) {

+ 14 - 0
purchase-common/src/main/java/com/ozs/common/vo/FileDownVo.java

@@ -0,0 +1,14 @@
+package com.ozs.common.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class FileDownVo {
+
+    String fileName;
+    Boolean delete;
+}