Commit 567f9062 authored by 王飞's avatar 王飞

Merge branch 'gaixiankang' into 'dev'

PDF通用 下载、更新

See merge request !132
parents a9f1ab98 658c90b6
...@@ -155,6 +155,15 @@ public class Task { ...@@ -155,6 +155,15 @@ public class Task {
@ApiModelProperty("选择的项目") @ApiModelProperty("选择的项目")
private String taskList; private String taskList;
@ApiModelProperty("整车信息安全检验报告模板")
private String retentionUrl;
@ApiModelProperty("企业留档文件存储地址")
private String vehicleInformationUrl;
@ApiModelProperty("车型试验原始记录模板")
private String modelTestUrl;
@ApiModelProperty("指向待执行节点的指针[0、1、2]") @ApiModelProperty("指向待执行节点的指针[0、1、2]")
private int pointer; private int pointer;
......
...@@ -17,8 +17,9 @@ public interface PdfTemplateManagementService { ...@@ -17,8 +17,9 @@ public interface PdfTemplateManagementService {
/** /**
* 企业留档文件PDF下载 * 企业留档文件PDF下载
* @param taskId
* @return * @return
* @throws Exception * @throws Exception
*/ */
String generateRetentionFile() throws Exception; String generateRetentionFile(Long taskId) throws Exception;
} }
...@@ -6,10 +6,13 @@ import com.ruoyi.common.utils.DateUtils; ...@@ -6,10 +6,13 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PdfBaseWriter; import com.ruoyi.common.utils.PdfBaseWriter;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.vo.PhotoStorageVO; import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.domain.vo.ReviewEnterpriseArchiveViewVO;
import com.ruoyi.service.PdfTemplateManagementService; import com.ruoyi.service.PdfTemplateManagementService;
import com.ruoyi.service.ReviewEnterpriseArchiveService;
import io.minio.MinioClient; import io.minio.MinioClient;
import io.minio.ObjectWriteArgs; import io.minio.ObjectWriteArgs;
import io.minio.PutObjectArgs; import io.minio.PutObjectArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -43,6 +46,9 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -43,6 +46,9 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
@Value("${minio.secretKey}") @Value("${minio.secretKey}")
private String secretKey; private String secretKey;
@Autowired
private ReviewEnterpriseArchiveService reviewEnterpriseArchiveService;
/** /**
* 检验报告PDF下载 * 检验报告PDF下载
* @param response * @param response
...@@ -109,10 +115,12 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -109,10 +115,12 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
/** /**
* 企业留档文件PDF下载 * 企业留档文件PDF下载
* @param taskId
* @return * @return
* @throws Exception
*/ */
@Override @Override
public String generateRetentionFile() throws Exception { public String generateRetentionFile(Long taskId) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 新建 // 新建
PdfBaseWriter document = new PdfBaseWriter(outputStream); PdfBaseWriter document = new PdfBaseWriter(outputStream);
...@@ -141,26 +149,23 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe ...@@ -141,26 +149,23 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
List<String> list = Arrays.asList("文件名称", "文件目录", "标准章节", "标准要求", "审查要点"); List<String> list = Arrays.asList("文件名称", "文件目录", "标准章节", "标准要求", "审查要点");
float[] columnWidths = {20, 20, 20, 70, 70}; float[] columnWidths = {20, 20, 20, 70, 70};
PdfPTable table = document.createWithHeaderTable(list, columnWidths); PdfPTable table = document.createWithHeaderTable(list, columnWidths);
document.writeCell("A文件", Element.ALIGN_LEFT, 1, 1, table); // 查询数据
document.writeCell("B文件", Element.ALIGN_LEFT, 1, 1, table); List<ReviewEnterpriseArchiveViewVO> viewList = reviewEnterpriseArchiveService.view(taskId);
document.writeCell("C文件", Element.ALIGN_LEFT, 1, 1, table); for (ReviewEnterpriseArchiveViewVO view : viewList) {
document.writeCell("车辆制造商应具备车辆全生命周期的汽车信息安全管理体系", Element.ALIGN_LEFT, 1, 1, table); document.writeCell(view.getFileName(), Element.ALIGN_LEFT, 1, view.getItems().size(), table);
document.writeCell("E文件",Element.ALIGN_LEFT, 1, 1, table); view.getItems().forEach(item -> {
document.writeCell("F文件", Element.ALIGN_LEFT,1, 2, table); document.writeCell(item.getCatalogue(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("1.1", Element.ALIGN_LEFT,1, 1, table); document.writeCell(item.getChapter(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("5.1", Element.ALIGN_LEFT, 1, 1, table); document.writeCell(item.getStandard(), Element.ALIGN_LEFT, 1, 1, table);
document.writeCell("要求1", Element.ALIGN_LEFT, 1, 1, table); document.writeCell(item.getKeyPoint(), 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);
document.addContent(table); document.addContent(table);
// 关闭 // 关闭
document.close(); document.close();
// 上传到Minio // 上传到Minio
return uploadMinio(outputStream, "企业留档文件"); return uploadMinio(outputStream, "企业留档文件" + "_" + taskId);
} }
/** /**
......
package com.ruoyi.web; 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.annotation.Anonymous;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.domain.Task;
import com.ruoyi.service.PdfTemplateManagementService; 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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -20,6 +25,9 @@ import javax.servlet.http.HttpServletResponse; ...@@ -20,6 +25,9 @@ import javax.servlet.http.HttpServletResponse;
@RequestMapping("/pdf") @RequestMapping("/pdf")
public class PdfTemplateManagementController { public class PdfTemplateManagementController {
@Autowired
private TaskService taskService;
@Autowired @Autowired
private PdfTemplateManagementService pdfTemplateManagementService; private PdfTemplateManagementService pdfTemplateManagementService;
...@@ -42,15 +50,15 @@ public class PdfTemplateManagementController { ...@@ -42,15 +50,15 @@ public class PdfTemplateManagementController {
/** /**
* 企业留档文件PDF下载 * 企业留档文件PDF下载
* @param response * @param request
*/ */
@Anonymous @Anonymous
@ApiOperation("企业留档文件PDF下载") @ApiOperation("企业留档文件PDF下载")
@GetMapping(value = "/retentionFile", produces = "application/json") @PostMapping("/retentionFile")
public R<String> downloadRetentionFile() { public R<String> downloadRetentionFile(@Validated @RequestBody PdfFileRequest request) {
try { try {
// demo-模板 // demo-模板
String url = pdfTemplateManagementService.generateRetentionFile(); String url = pdfTemplateManagementService.generateRetentionFile(request.getTaskId());
return R.ok(url); return R.ok(url);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -58,4 +66,82 @@ public class PdfTemplateManagementController { ...@@ -58,4 +66,82 @@ 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)) {
// TODO 生成整车
}
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)) {
// TODO 生成车型
}
break;
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:
// TODO 更新整车
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:
// 更新
// TODO 更新车型
break;
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