|
@@ -1,7 +1,13 @@
|
|
|
package org.springblade.archive.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.aliyun.oss.OSSClient;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.itextpdf.text.*;
|
|
|
+import com.itextpdf.text.pdf.BaseFont;
|
|
|
+import com.itextpdf.text.pdf.PdfPCell;
|
|
|
+import com.itextpdf.text.pdf.PdfPTable;
|
|
|
+import com.itextpdf.text.pdf.PdfWriter;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springblade.archive.entity.ArchiveExaminingReport;
|
|
@@ -14,13 +20,19 @@ import org.springblade.archive.vo.ArchiveExaminingSocketVo;
|
|
|
import org.springblade.archive.vo.ArchiveExaminingVo;
|
|
|
import org.springblade.common.constant.ArchiveConstant;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springblade.resource.feign.NewISmsClient;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -33,7 +45,10 @@ import java.util.List;
|
|
|
@AllArgsConstructor
|
|
|
public class ArchiveExaminingReportImpl extends BaseServiceImpl<ArchiveExaminingReportMapper, ArchiveExaminingReport> implements IArchiveExaminingReportService {
|
|
|
private final WebSocketServer webSocketServer;
|
|
|
+
|
|
|
private final IArchiveExaminingReportDetailService detailService;
|
|
|
+
|
|
|
+ private final NewIOSSClient iossClient;
|
|
|
/**
|
|
|
* 推送状态到前端
|
|
|
* @param id
|
|
@@ -67,7 +82,7 @@ public class ArchiveExaminingReportImpl extends BaseServiceImpl<ArchiveExamining
|
|
|
*/
|
|
|
@Async
|
|
|
@Override
|
|
|
- public void getExamining(ArchiveExaminingVo vo, Long id) throws InterruptedException {
|
|
|
+ public void getExamining(ArchiveExaminingVo vo, Long id) throws InterruptedException, DocumentException, IOException {
|
|
|
ArchiveExaminingReport report = new ArchiveExaminingReport();
|
|
|
report.setId(id);
|
|
|
report.setStatus(2);
|
|
@@ -158,9 +173,111 @@ public class ArchiveExaminingReportImpl extends BaseServiceImpl<ArchiveExamining
|
|
|
//生成报告,生成PDF
|
|
|
report.setStatus(3);
|
|
|
this.updateById(report);
|
|
|
+ String url = this.generateReportPdf(id);
|
|
|
Thread.sleep(7000L);
|
|
|
//完成
|
|
|
+ report.setReportPdfUrl(url);
|
|
|
report.setStatus(4);
|
|
|
this.updateById(report);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成检测报告PDF
|
|
|
+ */
|
|
|
+ private String generateReportPdf(Long id) throws DocumentException, IOException {
|
|
|
+ int high = 20;
|
|
|
+ int widthPercentage = 100;
|
|
|
+ String uuid = StringUtil.randomUUID();
|
|
|
+ String localUrl = "/www/wwwroot/Users/hongchuangyanfa/Desktop/archiveExaminingPdf/";
|
|
|
+ //新建一个pdf文档对象,前一个参数是纸张大小,后四个为边距
|
|
|
+ Document document = new Document(PageSize.A4, 5, 5, 30, 30);
|
|
|
+ //建立一个书写器
|
|
|
+ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(localUrl+uuid+".pdf"));
|
|
|
+ document.open();
|
|
|
+ //创建字体
|
|
|
+ BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
|
|
+ //字体对象,这里可以创建一个方法
|
|
|
+ Font size14font = new Font(baseFont, 14, Font.BOLD); //大小为14的正常字体
|
|
|
+ Font size10font = new Font(baseFont, 10, Font.NORMAL); //大小为10的正常字体
|
|
|
+ Font size10font2 = new Font(baseFont, 10, Font.BOLD); //大小为10的正常字体
|
|
|
+ //添加标题
|
|
|
+ //创建第一行表格
|
|
|
+ PdfPTable tableName = new PdfPTable(1);
|
|
|
+ tableName.setWidthPercentage(widthPercentage); //设置标题长度占纸张比例
|
|
|
+ //给表格赋值
|
|
|
+ tableName.addCell(pdfTableStyle("电子文件四性检测报告", size14font, 50, true, true));
|
|
|
+ //将表格添加到文档对象中
|
|
|
+ document.add(tableName);
|
|
|
+ //依据文献
|
|
|
+ PdfPTable two = new PdfPTable(1);
|
|
|
+ two.setWidthPercentage(widthPercentage);
|
|
|
+ two.addCell(pdfTableStyle("依据文献:\n" +
|
|
|
+ "[1]文书类电子档案检测一般要求:DA/T 70-2018 [2] 电子档案“四性”检测要求及其实现方法[J].浙江档案\n" +
|
|
|
+ "出具系统电子文件归档真实性、完整性、可用性、安全性检测报告",size10font,37,false,false));
|
|
|
+ document.add(two);
|
|
|
+ //表头文字
|
|
|
+ String[] name = new String[]{"检测类别", "检测项目", "统计不合格", "不合格对象"};
|
|
|
+ //创建第二行,并设置第二行中的表格数
|
|
|
+ PdfPTable twoTable = new PdfPTable(name.length);
|
|
|
+ twoTable.setWidthPercentage(widthPercentage);
|
|
|
+ //该数组是每个表格的宽度
|
|
|
+ float[] floats = new float[name.length];
|
|
|
+ floats[0] = 0.1f;
|
|
|
+ floats[1] = 0.7f;
|
|
|
+ floats[2] = 0.1f;
|
|
|
+ floats[3] = 0.1f;
|
|
|
+ //循环将表头数据添加到第二行表格中
|
|
|
+ for (int i = 0; i < name.length; i++) {
|
|
|
+ PdfPCell pdfPCell = pdfTableStyle(name[i], size10font2, high, true, true);
|
|
|
+ pdfPCell.setBackgroundColor(new BaseColor(231,230,230));
|
|
|
+ twoTable.addCell(pdfPCell);
|
|
|
+ }
|
|
|
+ //设置表格的宽度
|
|
|
+ twoTable.setTotalWidth(floats);
|
|
|
+ document.add(twoTable);
|
|
|
+ //表单数据
|
|
|
+ List<ArchiveExaminingReportDetail> list = detailService.list(new LambdaQueryWrapper<ArchiveExaminingReportDetail>()
|
|
|
+ .eq(ArchiveExaminingReportDetail::getReportId, id));
|
|
|
+ //将数据放入表格中
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ ArchiveExaminingReportDetail detail = list.get(i);
|
|
|
+ PdfPTable dataTable = new PdfPTable(name.length);
|
|
|
+ dataTable.setWidthPercentage(widthPercentage);
|
|
|
+ dataTable.setTotalWidth(floats);
|
|
|
+ //将数组中的数据按照顺序添加
|
|
|
+ dataTable.addCell(pdfTableStyle(detail.getExaminingType(), size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(detail.getExaminingItem(), size10font, high, false, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(detail.getUnqualifiedCount()+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(detail.getUnqualifiedObject(), size10font, high, true, true));
|
|
|
+ document.add(dataTable);
|
|
|
+
|
|
|
+ }
|
|
|
+ document.close();
|
|
|
+ writer.close();
|
|
|
+ BladeFile bladeFile = iossClient.uploadFile(uuid+".pdf", localUrl+uuid+".pdf");
|
|
|
+ return bladeFile.getLink();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表格的样式
|
|
|
+ * @param content 内容
|
|
|
+ * @param font 字体对象
|
|
|
+ * @param high 表格高度
|
|
|
+ * @Param isAlignCenter 是否水平居中
|
|
|
+ * @Param isAlignMidde 是否垂直居中
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ static PdfPCell pdfTableStyle(String content, Font font, int high, boolean isAlignCenter, boolean isAlignMidle){
|
|
|
+ PdfPCell pdfPCell = new PdfPCell(new Phrase(content,font));
|
|
|
+ pdfPCell.setMinimumHeight(high);
|
|
|
+ pdfPCell.setUseAscender(true); // 设置可以居中
|
|
|
+ if (isAlignCenter){
|
|
|
+ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
|
|
|
+ }
|
|
|
+ if (isAlignMidle){
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
|
|
|
+ }
|
|
|
+ return pdfPCell;
|
|
|
+ }
|
|
|
}
|