zhanghao 3 nedēļas atpakaļ
vecāks
revīzija
c9555c1f03

+ 27 - 0
project-zcustom/src/main/java/com/project/zcustom/controller/backManager/engineering/LargeIssueController.java

@@ -9,9 +9,16 @@ import com.project.zcustom.domain.addional.LargeIssue;
 import com.project.zcustom.service.unit.ILargeIssueService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -71,4 +78,24 @@ public class LargeIssueController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(largeIssueService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @GetMapping("/downloadFile")
+    public ResponseEntity<InputStreamResource> downloadFile(@RequestParam String filePath) throws IOException {
+        // 获取服务器根目录下的 xx 文件夹中的文件
+        File file = new File(System.getProperty("user.dir") + filePath);
+
+        if (!file.exists()) {
+            return ResponseEntity.notFound().build();  // 如果文件不存在,返回 404
+        }
+
+        // 创建文件流
+        FileInputStream fileInputStream = new FileInputStream(file);
+
+        // 设置 HTTP 响应头,返回文件流
+        return ResponseEntity.ok()
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())  // 设置文件下载
+                .contentType(MediaType.APPLICATION_OCTET_STREAM)  // 文件类型为二进制流
+                .contentLength(file.length())  // 设置文件大小
+                .body(new InputStreamResource(fileInputStream));  // 返回文件流
+    }
 }

+ 1 - 1
project-zcustom/src/main/java/com/project/zcustom/controller/engineering/PlatProjectCheckController.java

@@ -104,7 +104,7 @@ public class PlatProjectCheckController extends BaseController {
             String filePath = ProjectConfig.getUploadPath();
             // 上传并返回新文件名称
             String fileName = FileUploadUtils.upload(filePath, file);
-            entity.setImagePath(fileName);
+            entity.setImagePath("/uploadPath" + fileName.substring(8));
         }catch (Exception e){
         }
         return toAjax(largeIssueService.updateById(entity));