Przeglądaj źródła

Merge remote-tracking branch 'origin/develop' into develop

zishan-an 1 rok temu
rodzic
commit
43af932fd2

+ 8 - 0
pom.xml

@@ -260,6 +260,14 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>9</source>
+                    <target>9</target>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>

+ 37 - 4
src/main/java/com/kexun/controller/FileUploadController.java

@@ -1,8 +1,23 @@
 package com.kexun.controller;
-
+import org.springframework.core.io.FileSystemResource;
 import com.alibaba.fastjson.JSONObject;
 import com.kexun.entity.ModelEntity;
 import org.apache.commons.io.FileUtils;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.io.*;
+import java.net.URLEncoder;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.Files;
+import java.util.Base64;
+
+import org.springframework.util.StringUtils;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;
@@ -22,9 +37,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * @Author zhangming
@@ -53,6 +66,26 @@ public class FileUploadController {
     @Value("${config.fileupload.warpath}")
     private String warPath;
 
+
+    @GetMapping("/download/{filename}")
+    public Result downloadFile(@PathVariable("filename") String filename, SysUser sysUser) throws IOException {
+        String filePath = fileuploadPath +sysUser.getUserName()+'/'+ filename; // 设置文件路径
+        File file = new File(filePath);
+
+
+        if(file.exists()) {
+            byte[] fileContent = Files.readAllBytes(file.toPath());
+            String base64 = Base64.getEncoder().encodeToString(fileContent);
+            JSONObject resJson = new JSONObject();
+            resJson.put("file", base64);
+            return Result.success("ok", resJson);
+        }
+        else{
+            return Result.error("文件不存在!");
+        }
+
+    }
+
     @PostMapping("/filechange")
     public Result filechange(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
             , @RequestParam String output_list, SysUser sysUser, @RequestParam long id

+ 4 - 1
src/main/java/com/kexun/controller/ModelController.java

@@ -13,6 +13,8 @@ import com.kexun.service.*;
 import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import springfox.documentation.spring.web.json.Json;
+
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -50,8 +52,9 @@ public class ModelController {
     @Autowired
     private FilterResultService parseResultService;
 
-
     private JsonFile jsonFile = new JsonFile();
+
+
     @GetMapping("getModelNo")
     public Result getModelNo(){
         JSONObject resJson = new JSONObject();