Commit 46573d01 authored by 盖献康's avatar 盖献康

PDF - PDF通用 下载、更新

parent ef243516
......@@ -155,6 +155,15 @@ public class Task {
@ApiModelProperty("选择的项目")
private String taskList;
@ApiModelProperty("整车信息安全检验报告模板")
private String retentionUrl;
@ApiModelProperty("企业留档文件存储地址")
private String vehicleInformationUrl;
@ApiModelProperty("车型试验原始记录模板")
private String modelTestUrl;
@ApiModelProperty("指向待执行节点的指针[0、1、2]")
private int pointer;
......
......@@ -17,8 +17,9 @@ public interface PdfTemplateManagementService {
/**
* 企业留档文件PDF下载
* @param taskId
* @return
* @throws Exception
*/
String generateRetentionFile() throws Exception;
String generateRetentionFile(Long taskId) throws Exception;
}
......@@ -6,10 +6,13 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PdfBaseWriter;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.domain.vo.ReviewEnterpriseArchiveViewVO;
import com.ruoyi.service.PdfTemplateManagementService;
import com.ruoyi.service.ReviewEnterpriseArchiveService;
import io.minio.MinioClient;
import io.minio.ObjectWriteArgs;
import io.minio.PutObjectArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -43,6 +46,9 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
@Value("${minio.secretKey}")
private String secretKey;
@Autowired
private ReviewEnterpriseArchiveService reviewEnterpriseArchiveService;
/**
* 检验报告PDF下载
* @param response
......@@ -109,10 +115,12 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
/**
* 企业留档文件PDF下载
* @param taskId
* @return
* @throws Exception
*/
@Override
public String generateRetentionFile() throws Exception {
public String generateRetentionFile(Long taskId) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 新建
PdfBaseWriter document = new PdfBaseWriter(outputStream);
......@@ -141,20 +149,17 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
List<String> list = Arrays.asList("文件名称", "文件目录", "标准章节", "标准要求", "审查要点");
float[] columnWidths = {20, 20, 20, 70, 70};
PdfPTable table = document.createWithHeaderTable(list, columnWidths);
document.writeCell("A文件", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("B文件", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("C文件", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("车辆制造商应具备车辆全生命周期的汽车信息安全管理体系", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("E文件",Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("F文件", Element.ALIGN_LEFT,1, 2, table);
document.writeCell("1.1", Element.ALIGN_LEFT,1, 1, table);
document.writeCell("5.1", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("要求1", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("要点1", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("1.2", Element.ALIGN_LEFT,1, 1, table);
document.writeCell("5.2", Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("要求2", Element.ALIGN_LEFT,1, 1, table);
document.writeCell("要点2", Element.ALIGN_LEFT,1, 1, table);
// 查询数据
List<ReviewEnterpriseArchiveViewVO> viewList = reviewEnterpriseArchiveService.view(taskId);
for (ReviewEnterpriseArchiveViewVO view : viewList) {
document.writeCell(view.getFileName(), Element.ALIGN_LEFT, 1, view.getItems().size(), table);
view.getItems().forEach(item -> {
document.writeCell(item.getCatalogue(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell(item.getChapter(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell(item.getStandard(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell(item.getKeyPoint(), Element.ALIGN_LEFT, 1, 1, table);
});
}
document.addContent(table);
// 关闭
document.close();
......
package com.ruoyi.web;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.domain.Task;
import com.ruoyi.service.PdfTemplateManagementService;
import com.ruoyi.service.TaskService;
import com.ruoyi.web.request.PdfFileRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
......@@ -20,6 +25,9 @@ import javax.servlet.http.HttpServletResponse;
@RequestMapping("/pdf")
public class PdfTemplateManagementController {
@Autowired
private TaskService taskService;
@Autowired
private PdfTemplateManagementService pdfTemplateManagementService;
......@@ -42,15 +50,15 @@ public class PdfTemplateManagementController {
/**
* 企业留档文件PDF下载
* @param response
* @param request
*/
@Anonymous
@ApiOperation("企业留档文件PDF下载")
@GetMapping(value = "/retentionFile", produces = "application/json")
public R<String> downloadRetentionFile() {
@PostMapping("/retentionFile")
public R<String> downloadRetentionFile(@Validated @RequestBody PdfFileRequest request) {
try {
// demo-模板
String url = pdfTemplateManagementService.generateRetentionFile();
String url = pdfTemplateManagementService.generateRetentionFile(request.getTaskId());
return R.ok(url);
} catch (Exception e) {
e.printStackTrace();
......@@ -58,4 +66,86 @@ public class PdfTemplateManagementController {
}
}
/**
* 下载PDF通用(三个PDF)
* @param request
* @return
*/
@Anonymous
@ApiOperation("下载PDF通用")
@PostMapping("/download")
public R<String> downloadPdf(@Validated @RequestBody PdfFileRequest request) {
// 根据taskId、pdf类型判断库里存不存在minio地址
String url = "";
Task task = taskService.getOne(new QueryWrapper<Task>().lambda().eq(Task::getId, request.getTaskId()));
try {
switch (request.getType()) {
case 0:
url = task.getVehicleInformationUrl();
if (StrUtil.isBlank(url)) {
// 新生成
System.out.println("0");
}
break;
case 1:
url = task.getRetentionUrl();
if (StrUtil.isBlank(url)) {
// 根据任务ID新生成
url = pdfTemplateManagementService.generateRetentionFile(request.getTaskId());
// 更改
taskService.update(new UpdateWrapper<Task>().lambda().eq(Task::getId, request.getTaskId()).set(Task::getRetentionUrl, url));
}
break;
case 2:
url = task.getModelTestUrl();
if (StrUtil.isBlank(url)) {
System.out.println("2");
}
break;
default:
System.out.println("default");
break;
}
} catch (Exception e) {
e.printStackTrace();
return R.fail();
}
return R.ok(url);
}
/**
* 更新PDF通用
* @param request
*/
@Anonymous
@ApiOperation("更新PDF通用")
@PostMapping("/update")
public R<String> updatePdf(@Validated @RequestBody PdfFileRequest request) {
String url = "";
try {
switch (request.getType()) {
case 0:
// 更新
System.out.println("0");
break;
case 1:
// 根据任务ID新生成
url = pdfTemplateManagementService.generateRetentionFile(request.getTaskId());
// 更改
taskService.update(new UpdateWrapper<Task>().lambda().eq(Task::getId, request.getTaskId()).set(Task::getRetentionUrl, url));
break;
case 2:
// 更新
System.out.println("2");
break;
default:
System.out.println("default");
break;
}
} catch (Exception e) {
e.printStackTrace();
return R.fail();
}
return R.ok(url);
}
}
package com.ruoyi.web.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
/**
* PDF文件请求DTO
* @author gxk
*/
@Data
@Builder
@ApiModel
@NoArgsConstructor
@AllArgsConstructor
public class PdfFileRequest {
@ApiModelProperty("任务ID")
@NotNull(message = "任务ID不能为空")
private Long taskId;
@ApiModelProperty("PDF类型(0-整车、1-企业留档、2-车型)")
@NotNull(message = "PDF类型不能为空")
private Integer type;
}
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