Browse Source

信创文件预览

tags/24080901
PoffyZhang 4 months ago
parent
commit
9f7428746f
3 changed files with 41 additions and 7 deletions
  1. +8
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java
  2. +27
    -3
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java
  3. +6
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java

+ 8
- 2
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java View File

@@ -139,8 +139,14 @@ public class PurchaseController {

@GetMapping("/xcfhxReportFiles/{code}")
@ApiOperation("获取信创文件预览")
public String xcfhxReportFiles(@PathVariable String code) {
return purchaseManage.xcfhxReportFiles(code);
public void xcfhxReportFiles(@PathVariable String code) {
purchaseManage.xcfhxReportFiles(code);
}

@GetMapping("/exportXcfhFile/{code}")
@ApiOperation("直接导出信创文件")
public void exportXcfhFile(@PathVariable String code,HttpServletResponse response) {
purchaseManage.exportXcfhFile(code,response);
}

@GetMapping("/purchaseIntention/{unitId}")


+ 27
- 3
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java View File

@@ -15,9 +15,10 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.file.Files;

/**
* @Classname MhXchxFileHelper
@@ -66,4 +67,27 @@ public class MhXchxFileHelper {
return JSONUtil.toJsonStr(retFileInfo);
}

public void exportReport(String reportFile, HttpServletResponse response){
if (StrUtils.isBlank(reportFile)) {
throw BizException.wrap("信创报告文件不能为空");
}

File file = mhFileClient.downloadToTmpFile(reportFile);
// 设置响应的内容类型和头信息
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");

// 使用ServletOutputStream写文件内容
try (InputStream in = Files.newInputStream(file.toPath());
ServletOutputStream out = response.getOutputStream()) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

}
}

+ 6
- 2
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java View File

@@ -833,7 +833,11 @@ public class PurchaseManage {
throw BizException.wrap("新增失败");
}

public String xcfhxReportFiles(String code) {
return mhXchxFileHelper.getXchxFile(code, null);
public void xcfhxReportFiles(String code) {
mhXchxFileHelper.getXchxFile(code, null);
}

public void exportXcfhFile(String code,HttpServletResponse response) {
mhXchxFileHelper.exportReport(code, response);
}
}

Loading…
Cancel
Save