|
@@ -2,6 +2,13 @@ package org.springblade.archive.service.impl;
|
|
|
|
|
|
|
|
|
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.ArchiveExpertConclusion;
|
|
|
import org.springblade.archive.entity.ArchiveExpertScore;
|
|
|
import org.springblade.archive.entity.ExpertInspection;
|
|
@@ -9,15 +16,31 @@ import org.springblade.archive.mapper.ArchiveExpertScoreMapper;
|
|
|
import org.springblade.archive.mapper.ExpertInspectionMapper;
|
|
|
import org.springblade.archive.service.IArchiveExpertScoreService;
|
|
|
import org.springblade.archive.service.IExpertInspectionService;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class ArchiveExpertScoreServiceImpl extends BaseServiceImpl<ArchiveExpertScoreMapper, ArchiveExpertScore> implements IArchiveExpertScoreService {
|
|
|
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
+
|
|
|
+ //表格高度
|
|
|
+ private static int high = 20;
|
|
|
+ //表格宽度
|
|
|
+ private static int widthPercentage = 100;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void saveBaseScoreInfo(Long projectId,Long conclusionId) {
|
|
@@ -45,5 +68,166 @@ public class ArchiveExpertScoreServiceImpl extends BaseServiceImpl<ArchiveExpert
|
|
|
.eq(ArchiveExpertScore::getConclusionId,conclusion.getId()));
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String buildScorePdf(Long projectId,Long conclusionId) throws Exception {
|
|
|
+ //获取数据
|
|
|
+ List<ArchiveExpertScore> list = this.list(new LambdaQueryWrapper<ArchiveExpertScore>()
|
|
|
+ .eq(ArchiveExpertScore::getProjectId, projectId)
|
|
|
+ .eq(ArchiveExpertScore::getConclusionId, conclusionId));
|
|
|
+ if (list.size() == 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<Integer, List<ArchiveExpertScore>> map = list.stream().collect(Collectors.groupingBy(ArchiveExpertScore::getUnitType));
|
|
|
+ String fileUrl = "C:\\Users\\泓创研发01\\Desktop\\conclusionPDF.pdf";
|
|
|
+ //新建一个pdf文档对象,前一个参数是纸张大小,后四个为边距
|
|
|
+ Document document = new Document(PageSize.A4, 5, 5, 30, 30);
|
|
|
+ //建立一个书写器
|
|
|
+ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileUrl));
|
|
|
+ document.open();
|
|
|
+ //创建字体
|
|
|
+ BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
|
|
+ //字体对象,这里可以创建一个方法
|
|
|
+ Font size10font = new Font(baseFont, 10, Font.NORMAL); //大小为10的正常字体
|
|
|
+ Font size10font2 = new Font(baseFont, 10, Font.BOLD); //大小为10的粗字体
|
|
|
+ Font size17font = new Font(baseFont, 17, Font.NORMAL); //大小为17的正常字体
|
|
|
+ //该数组是每个表格的宽度
|
|
|
+ float[] floats = new float[6];
|
|
|
+ floats[0] = 0.5f;
|
|
|
+ floats[1] = 0.1f;
|
|
|
+ floats[2] = 0.1f;
|
|
|
+ floats[3] = 0.1f;
|
|
|
+ floats[4] = 0.1f;
|
|
|
+ floats[5] = 0.1f;
|
|
|
+ float[] floats2 = new float[5];
|
|
|
+ floats2[0] = 0.5f;
|
|
|
+ floats2[1] = 0.1f;
|
|
|
+ floats2[2] = 0.1f;
|
|
|
+ floats2[3] = 0.1f;
|
|
|
+ floats2[4] = 0.1f;
|
|
|
+ tableHeader(document,size17font);
|
|
|
+ tableUnit(document,size10font2,"建设单位");
|
|
|
+ //表头文字
|
|
|
+ String[] name = new String[]{"项目", "完整性", "扣分", "规范性","扣分","总得分"};
|
|
|
+ //创建第二行,并设置第二行中的表格数
|
|
|
+ PdfPTable twoTable = new PdfPTable(name.length);
|
|
|
+ twoTable.setWidthPercentage(widthPercentage);
|
|
|
+ //循环将表头数据添加到第二行表格中
|
|
|
+ for (int i = 0; i < name.length; i++) {
|
|
|
+ PdfPCell pdfPCell = pdfTableStyle(name[i], size10font,high, true, true);
|
|
|
+ pdfPCell.setBackgroundColor(new BaseColor(231,230,230));
|
|
|
+ twoTable.addCell(pdfPCell);
|
|
|
+ }
|
|
|
+ //设置表格的宽度
|
|
|
+ twoTable.setTotalWidth(floats);
|
|
|
+
|
|
|
+ document.add(twoTable);
|
|
|
+ //将数据放入表格中
|
|
|
+ int total = 0;
|
|
|
+ for (int i = 1; i <= 3; i++) {
|
|
|
+ if (i == 2){
|
|
|
+ tableUnit(document,size10font2,"监理单位");
|
|
|
+ }
|
|
|
+ if (i == 3){
|
|
|
+ tableUnit(document,size10font2,"施工单位");
|
|
|
+ }
|
|
|
+ List<ArchiveExpertScore> scores = map.get(i);
|
|
|
+ PdfPTable dataTable = new PdfPTable(5);
|
|
|
+ dataTable.setWidths(floats2);
|
|
|
+ dataTable.setWidthPercentage(100);
|
|
|
+ for (int j = 0; j < scores.size(); j++) {
|
|
|
+ ArchiveExpertScore score = scores.get(j);
|
|
|
+
|
|
|
+ dataTable.addCell(pdfTableStyle(score.getScoreItem(), size10font,high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(score.getIntegrality()+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(score.getIntegralityDeduction()+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(score.getNormative()+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(score.getNormativeDeduction()+"", size10font, high, true, true));
|
|
|
+ }
|
|
|
+ PdfPTable mergeTable = new PdfPTable(2);
|
|
|
+ float[] columnWidths3 = {9f, 1f};
|
|
|
+ mergeTable.setWidths(columnWidths3);
|
|
|
+ mergeTable.setWidthPercentage(100);
|
|
|
+ PdfPCell leftCell = new PdfPCell(dataTable);
|
|
|
+ mergeTable.addCell(leftCell);
|
|
|
+ PdfPCell rightCell = pdfTableStyle("66", size10font,scores.size() * high,true,true);
|
|
|
+ mergeTable.addCell(rightCell);
|
|
|
+ document.add(mergeTable);
|
|
|
+
|
|
|
+ }
|
|
|
+ document.close();
|
|
|
+ writer.close();
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile("ArchiveApp.pdf", fileUrl);
|
|
|
+ if (bladeFile == null || StringUtils.isBlank(bladeFile.getLink())) {
|
|
|
+ throw new ServiceException("上传PDF失败");
|
|
|
+ }
|
|
|
+ return bladeFile.getLink();
|
|
|
+ }
|
|
|
+
|
|
|
+ static void tableHeader(Document document,Font size17font) throws DocumentException {
|
|
|
+ //添加标题
|
|
|
+ //创建第一行表格
|
|
|
+ PdfPTable tableName = new PdfPTable(1);
|
|
|
+ tableName.setWidthPercentage(widthPercentage); //设置标题长度占纸张比例
|
|
|
+ PdfPCell cell = pdfTableStyle("项目档案验收评分表", size17font,50, true, true);
|
|
|
+ //给表格赋值
|
|
|
+ tableName.addCell(cell);
|
|
|
+ //将表格添加到文档对象中
|
|
|
+ document.add(tableName);
|
|
|
+ }
|
|
|
+
|
|
|
+ static void tableUnit(Document document,Font size10font2,String unitName) throws Exception {
|
|
|
+ //单位名称
|
|
|
+ PdfPTable two = new PdfPTable(1);
|
|
|
+ two.setWidthPercentage(widthPercentage);
|
|
|
+ PdfPCell cell2 = pdfTableStyle2(unitName, size10font2,20, false, true);
|
|
|
+ cell2.setBackgroundColor(new BaseColor(231,230,230));
|
|
|
+ two.addCell(cell2);
|
|
|
+ document.add(two);
|
|
|
+ }
|
|
|
+
|
|
|
+ static PdfPCell pdfTableStyle(String content, Font font, int high, boolean isAlignCenter, boolean isAlignMidle) {
|
|
|
+ Paragraph phrase = new Paragraph(content, font);
|
|
|
+ phrase.setAlignment(Paragraph.ALIGN_LEFT);
|
|
|
+ PdfPCell pdfPCell = new PdfPCell(phrase);
|
|
|
+ pdfPCell.setMinimumHeight(high);
|
|
|
+ pdfPCell.setUseAscender(true); // 设置可以居中
|
|
|
+ if (isAlignCenter) {
|
|
|
+ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
|
|
|
+ }else {
|
|
|
+ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
|
|
|
+ }
|
|
|
+ if (isAlignMidle) {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
|
|
|
+ }else {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); // 设置垂直居中
|
|
|
+ }
|
|
|
+
|
|
|
+ return pdfPCell;
|
|
|
+ }
|
|
|
+
|
|
|
+ static PdfPCell pdfTableStyle2(String content, Font size10font2,int high, boolean isAlignCenter, boolean isAlignMiddle) throws Exception {
|
|
|
+ Paragraph phrase = new Paragraph(content, size10font2);
|
|
|
+ phrase.setAlignment(Paragraph.ALIGN_LEFT);
|
|
|
+ PdfPCell pdfPCell = new PdfPCell(phrase);
|
|
|
+ pdfPCell.setMinimumHeight(high);
|
|
|
+ pdfPCell.setUseAscender(true); // 设置可以居中
|
|
|
+ if (isAlignCenter) {
|
|
|
+ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
|
|
|
+ }else {
|
|
|
+ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
|
|
|
+ }
|
|
|
+ if (isAlignMiddle) {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
|
|
|
+ }else {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); // 设置垂直居中
|
|
|
+ }
|
|
|
+
|
|
|
+ return pdfPCell;
|
|
|
+ }
|
|
|
}
|
|
|
|