Commit 3099c0c8 authored by wdy's avatar wdy

Merge branch 'dev' of http://gitlab.91isoft.com:90/wangfei/vehicle-quality-review into wangdingyi

parents e238c94d c3174724
...@@ -10,10 +10,12 @@ public interface PdfTemplateManagementService { ...@@ -10,10 +10,12 @@ public interface PdfTemplateManagementService {
/** /**
* 检验报告PDF下载 * 检验报告PDF下载
* @param response *
* @param taskId
* @return
* @throws Exception * @throws Exception
*/ */
void generateInspectionReport(HttpServletResponse response) throws Exception; String generateInspectionReport(Long taskId) throws Exception;
/** /**
* 企业留档文件PDF下载 * 企业留档文件PDF下载
......
...@@ -51,17 +51,19 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -51,17 +51,19 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
/** /**
* 检验报告PDF下载 * 检验报告PDF下载
* @param response *
* @param taskId
* @return
*/ */
@Override @Override
public void generateInspectionReport(HttpServletResponse response) throws Exception { public String generateInspectionReport(Long taskId) throws Exception {
PdfReader reader = null; PdfReader reader = null;
PdfStamper ps = null; PdfStamper ps = null;
OutputStream fos = null;
ByteArrayOutputStream bos = null; ByteArrayOutputStream bos = null;
try { try {
// 模板绝对路径--服务器 // 模板绝对路径--服务器
String fileName = "/template/receipt_template_02_27.pdf"; // String fileName = "/template/receipt_template_02_27.pdf";
String fileName = "E:/文件/PDF模板/receipt_template_02_27.pdf";
// 读取现有模板内容 // 读取现有模板内容
reader = new PdfReader(fileName); reader = new PdfReader(fileName);
// 创建输出流 // 创建输出流
...@@ -85,17 +87,10 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -85,17 +87,10 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
//必须要调用这个,否则文档不会生成的 //必须要调用这个,否则文档不会生成的
ps.setFormFlattening(true); ps.setFormFlattening(true);
ps.close(); ps.close();
//生成pdf路径存放的路径
fos = response.getOutputStream();
fos.write(bos.toByteArray());
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
if(fos!=null){
fos.flush();
fos.close();
}
if (bos != null){ if (bos != null){
bos.close(); bos.close();
} }
...@@ -103,6 +98,8 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -103,6 +98,8 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
reader.close(); reader.close();
} }
} }
assert bos != null;
return uploadMinio(bos, "检验报告_" + taskId);
} }
private InspectionReportPdfVO requireData() { private InspectionReportPdfVO requireData() {
...@@ -131,7 +128,7 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -131,7 +128,7 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
.remark("备注") .remark("备注")
.taskNumber("任务编号") .taskNumber("任务编号")
.sampleSum("样品数量") .sampleSum("样品数量")
.vehicleType("车类型") .vehicleType("车类型")
.vehicleModel("车辆型号") .vehicleModel("车辆型号")
.vehicleIdentificationNumber("车辆识别码") .vehicleIdentificationNumber("车辆识别码")
.sampleNumberSummary("样品编号汇总") .sampleNumberSummary("样品编号汇总")
...@@ -198,7 +195,7 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -198,7 +195,7 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
document.close(); document.close();
// 上传到Minio // 上传到Minio
return uploadMinio(outputStream, "企业留档文件" + "_" + taskId); return uploadMinio(outputStream, "企业留档文件_" + taskId);
} }
/** /**
......
...@@ -15,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
/** /**
* @author gxk * @author gxk
*/ */
...@@ -33,18 +31,19 @@ public class PdfTemplateManagementController { ...@@ -33,18 +31,19 @@ public class PdfTemplateManagementController {
/** /**
* 检验报告PDF下载 * 检验报告PDF下载
* @param response * @param request
*/ */
@Anonymous @Anonymous
@ApiOperation("检验报告PDF下载") @ApiOperation("检验报告PDF下载")
@GetMapping(value = "/inspectionReport", produces = "application/json") @PostMapping("/inspectionReport")
public void download(HttpServletResponse response) { public R<String> download(@Validated @RequestBody PdfFileRequest request) {
response.setHeader("content-disposition","attachment;fileName="+"ReceiptPrinter.pdf");
try { try {
// demo-模板 // demo-模板
pdfTemplateManagementService.generateInspectionReport(response); String url = pdfTemplateManagementService.generateInspectionReport(request.getTaskId());
return R.ok(url);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return R.fail();
} }
} }
...@@ -83,7 +82,9 @@ public class PdfTemplateManagementController { ...@@ -83,7 +82,9 @@ public class PdfTemplateManagementController {
case 0: case 0:
url = task.getVehicleInformationUrl(); url = task.getVehicleInformationUrl();
if (StrUtil.isBlank(url)) { if (StrUtil.isBlank(url)) {
// TODO 生成整车 // 生成整车信息安全检验报告
url = pdfTemplateManagementService.generateInspectionReport(request.getTaskId());
taskService.update(new UpdateWrapper<Task>().lambda().eq(Task::getId, request.getTaskId()).set(Task::getVehicleInformationUrl, url));
} }
break; break;
case 1: case 1:
...@@ -123,7 +124,9 @@ public class PdfTemplateManagementController { ...@@ -123,7 +124,9 @@ public class PdfTemplateManagementController {
try { try {
switch (request.getType()) { switch (request.getType()) {
case 0: case 0:
// TODO 更新整车 // 更新整车PDF文件
url = pdfTemplateManagementService.generateInspectionReport(request.getTaskId());
taskService.update(new UpdateWrapper<Task>().lambda().eq(Task::getId, request.getTaskId()).set(Task::getVehicleInformationUrl, url));
break; break;
case 1: case 1:
// 根据任务ID新生成 // 根据任务ID新生成
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment