|
@@ -28,6 +28,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -88,10 +93,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URL;
|
|
|
import java.nio.file.Files;
|
|
@@ -99,6 +101,7 @@ import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -140,6 +143,13 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
private final ArchiveConclusionMapper conclusionMapper;
|
|
|
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
+ //表格高度
|
|
|
+ private static int high = 20;
|
|
|
+ //表格宽度
|
|
|
+ private static int widthPercentage = 100;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -2779,6 +2789,18 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
task.setStatus(1);
|
|
|
//档案id
|
|
|
task.setArchiveIds(dto.getArchiveIds());
|
|
|
+ //设置申请档案的预览PDF,如果附件存在则拼接到PDF后面
|
|
|
+ ProjectInfo project = projectClient.getById(dto.getProjectId() + "");
|
|
|
+ List<Long> longs = Func.toLongList(dto.getArchiveIds());
|
|
|
+ List<ArchivesAutoVO2> vo2s = baseMapper.getAllArchive(longs);
|
|
|
+ try {
|
|
|
+ String pdfUrl = createAppPdf(project.getProjectName(),vo2s);
|
|
|
+ task.setAttachmentPdfUrl(pdfUrl);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ }
|
|
|
+ //如果存在附件则拼接
|
|
|
+ //保存任务
|
|
|
taskClient.saveTask(task);
|
|
|
//根据任务人设置task_parallel
|
|
|
List<SaveApplyDTO.CustomUserTask> userTasks = dto.getUserTasks();
|
|
@@ -2798,6 +2820,101 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //生成验收申请PDF
|
|
|
+ private String createAppPdf(String projectName, List<ArchivesAutoVO2> vo2s) throws Exception {
|
|
|
+ String fileUrl = "C:\\Users\\泓创研发01\\Desktop\\appPDF.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 size17font = new Font(baseFont, 17, Font.NORMAL); //大小为17的正常字体
|
|
|
+ //该数组是每个表格的宽度
|
|
|
+ float[] floats = new float[6];
|
|
|
+ floats[0] = 0.1f;
|
|
|
+ floats[1] = 0.1f;
|
|
|
+ floats[2] = 0.5f;
|
|
|
+ floats[3] = 0.1f;
|
|
|
+ floats[4] = 0.1f;
|
|
|
+ floats[5] = 0.1f;
|
|
|
+ tableHeader(projectName,document,size10font,size17font,floats);
|
|
|
+
|
|
|
+ //将数据放入表格中
|
|
|
+ int total = 0;
|
|
|
+ for (int i = 0; i < vo2s.size(); i++) {
|
|
|
+ ArchivesAutoVO2 vo2 = vo2s.get(i);
|
|
|
+ PdfPTable dataTable = new PdfPTable(6);
|
|
|
+ dataTable.setWidthPercentage(widthPercentage);
|
|
|
+ dataTable.setTotalWidth(floats);
|
|
|
+ dataTable.addCell(pdfTableStyle(i+1+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(vo2.getFileNumber(), size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(" "+vo2.getName(), size10font, high, false, false));
|
|
|
+ dataTable.addCell(pdfTableStyle(vo2.getPageN()+"", size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(vo2.getStorageTimeValue(), size10font, high, true, true));
|
|
|
+ dataTable.addCell(pdfTableStyle(vo2.getRemark(), size10font, high, true, true));
|
|
|
+ total += (int)Math.ceil(new Double(vo2.getName().length()+4) / 50);
|
|
|
+ //如果出现不相同,则合并之前的
|
|
|
+ document.add(dataTable);
|
|
|
+ if (total >= 35 && i != (vo2s.size()-1)) {
|
|
|
+ total = 0;
|
|
|
+ document.newPage();
|
|
|
+ tableHeader(projectName,document,size10font,size17font,floats);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表头
|
|
|
+ * @param document 整个文档
|
|
|
+ * @param size10font
|
|
|
+ * @param size17font
|
|
|
+ * @param floats 表头格式
|
|
|
+ * @throws DocumentException
|
|
|
+ */
|
|
|
+ void tableHeader(String projectName,Document document,Font size10font,Font size17font,float[] floats) throws DocumentException {
|
|
|
+ //添加标题
|
|
|
+ //创建第一行表格
|
|
|
+ PdfPTable tableName = new PdfPTable(1);
|
|
|
+ tableName.setWidthPercentage(widthPercentage); //设置标题长度占纸张比例
|
|
|
+ PdfPCell cell = pdfTableStyle("单位科学技术档案归档目录", size17font, 50, true, true);
|
|
|
+ cell.disableBorderSide(15);
|
|
|
+ //给表格赋值
|
|
|
+ tableName.addCell(cell);
|
|
|
+ //将表格添加到文档对象中
|
|
|
+ document.add(tableName);
|
|
|
+ //项目名称
|
|
|
+ PdfPTable two = new PdfPTable(1);
|
|
|
+ two.setWidthPercentage(widthPercentage);
|
|
|
+ PdfPCell cell2 = pdfTableStyle("项目名称:"+projectName, size10font, 20, false, false);
|
|
|
+ cell2.disableBorderSide(15);
|
|
|
+ two.addCell(cell2);
|
|
|
+ document.add(two);
|
|
|
+ //表头文字
|
|
|
+ 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);
|
|
|
+ twoTable.addCell(pdfPCell);
|
|
|
+ }
|
|
|
+ //设置表格的宽度
|
|
|
+ twoTable.setTotalWidth(floats);
|
|
|
+ document.add(twoTable);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public R<Boolean> batchUpdateIsApply(Integer isApply, List<Long> ids) {
|
|
|
this.update(new LambdaUpdateWrapper<ArchivesAuto>()
|
|
@@ -3257,4 +3374,33 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
Process process = Runtime.getRuntime().exec(cmds);
|
|
|
process.waitFor();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表格的样式
|
|
|
+ *
|
|
|
+ * @param content 内容
|
|
|
+ * @param font 字体对象
|
|
|
+ * @param high 表格高度
|
|
|
+ * @return
|
|
|
+ * @Param isAlignCenter 是否水平居中
|
|
|
+ * @Param isAlignMidde 是否垂直居中
|
|
|
+ */
|
|
|
+ static PdfPCell pdfTableStyle(String content, Font font, int high, boolean isAlignCenter, boolean isAlignMiddle) {
|
|
|
+ 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 (isAlignMiddle) {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
|
|
|
+ }else {
|
|
|
+ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); // 设置垂直居中
|
|
|
+ }
|
|
|
+ return pdfPCell;
|
|
|
+ }
|
|
|
}
|