|
@@ -9,9 +9,16 @@ import com.project.zcustom.domain.addional.LargeIssue;
|
|
import com.project.zcustom.service.unit.ILargeIssueService;
|
|
import com.project.zcustom.service.unit.ILargeIssueService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -71,4 +78,24 @@ public class LargeIssueController extends BaseController {
|
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
|
return toAjax(largeIssueService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
|
|
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)); // 返回文件流
|
|
|
|
+ }
|
|
}
|
|
}
|