|
@@ -2,7 +2,11 @@ package com.jeesite.modules.bjflapi.report;
|
|
|
|
|
|
import com.jeesite.common.collect.ListUtils;
|
|
|
import com.jeesite.common.collect.MapUtils;
|
|
|
+import com.jeesite.common.constant.Constants;
|
|
|
import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.modules.file.entity.FileEntity;
|
|
|
+import com.jeesite.modules.file.entity.FileUpload;
|
|
|
+import com.jeesite.modules.file.utils.FileUploadUtils;
|
|
|
import com.jeesite.modules.report.entity.ResearchBriefReport;
|
|
|
import com.jeesite.modules.report.entity.ResearchBriefReportLabel;
|
|
|
import com.jeesite.modules.report.service.ResearchBriefReportLabelRelevancyService;
|
|
@@ -10,13 +14,15 @@ import com.jeesite.modules.report.service.ResearchBriefReportService;
|
|
|
import com.jeesite.modules.sys.utils.R;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-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.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -28,6 +34,9 @@ public class ResearchBriefReportControllerApi {
|
|
|
private ResearchBriefReportService researchBriefReportService;
|
|
|
@Resource
|
|
|
private ResearchBriefReportLabelRelevancyService relevancyService;
|
|
|
+ @Value("${file.baseDir}")
|
|
|
+ private String basePath;
|
|
|
+ private final static String serverPath = "/userfiles/fileupload/";
|
|
|
|
|
|
/**
|
|
|
* 简报智库分页列表
|
|
@@ -110,4 +119,37 @@ public class ResearchBriefReportControllerApi {
|
|
|
public R<List<ResearchBriefReport>> choicenessReports(String marketType) {
|
|
|
return R.ok(researchBriefReportService.choicenessReports(marketType));
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download", method = RequestMethod.GET)
|
|
|
+ public void download(String id, HttpServletResponse response) {
|
|
|
+ List<FileUpload> list = FileUploadUtils.findFileUpload(id, Constants.briefReport.BRIEFING_INFO_PREVIEW_PDF);
|
|
|
+ String fileName = basePath + serverPath;
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ FileEntity fileEntity = list.get(0).getFileEntity();
|
|
|
+ if (fileEntity != null) {
|
|
|
+ fileName = fileName + fileEntity.getFilePath() + fileEntity.getFileId() + '.' + fileEntity.getFileExtension() ;
|
|
|
+ }
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ FileInputStream fileInputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ File file = new File(fileName);
|
|
|
+ fileInputStream = new FileInputStream(file);
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+ IOUtils.copy(fileInputStream, outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ response.setHeader("Content-Disposition",
|
|
|
+ "inline; filename= file");
|
|
|
+ outputStream.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ } finally {
|
|
|
+ // 使用IOUtils关闭流,它会安全地处理null值
|
|
|
+ IOUtils.closeQuietly(fileInputStream);
|
|
|
+ IOUtils.closeQuietly(outputStream);
|
|
|
+ }
|
|
|
+// return response;
|
|
|
+ }
|
|
|
}
|