|
@@ -2,20 +2,23 @@ package com.qmth.distributed.print.business.util;
|
|
|
|
|
|
import com.itextpdf.text.*;
|
|
import com.itextpdf.text.*;
|
|
import com.itextpdf.text.pdf.*;
|
|
import com.itextpdf.text.pdf.*;
|
|
-import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
|
|
|
|
-import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
|
|
import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
|
|
import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
|
|
import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
|
|
-import com.qmth.distributed.print.business.entity.ExamDetail;
|
|
+import com.qmth.distributed.print.business.service.PrintCommonService;
|
|
-import com.qmth.distributed.print.business.entity.ExamDetailCourse;
|
|
+import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
|
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
-import com.qmth.teachcloud.common.util.ConvertUtil;
|
|
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
+import java.io.File;
|
|
-import java.io.ByteArrayOutputStream;
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -34,14 +37,16 @@ public class CreatePrintPdfUtil {
|
|
* @param destFileName 文件名
|
|
* @param destFileName 文件名
|
|
* @param saveLocal 是事保存本地文件
|
|
* @param saveLocal 是事保存本地文件
|
|
*/
|
|
*/
|
|
- public void createSignPdf(HttpServletResponse response, PdfSignDto pdfFillDto, String destFileName, boolean saveLocal) throws Exception {
|
|
+ public String createSignPdf(PdfSignDto pdfFillDto, String destFileName, boolean saveLocal) throws Exception {
|
|
|
|
|
|
|
|
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
+
|
|
|
|
+ File file = createFolder(SystemConstant.PDF_PREFIX);
|
|
try {
|
|
try {
|
|
|
|
|
|
- PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
|
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
+ PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
|
|
|
|
|
|
|
MyHeaderFooter headerFooter = new MyHeaderFooter();
|
|
MyHeaderFooter headerFooter = new MyHeaderFooter();
|
|
@@ -53,32 +58,32 @@ public class CreatePrintPdfUtil {
|
|
this.generateSignPDF(document, pdfWriter, pdfFillDto);
|
|
this.generateSignPDF(document, pdfWriter, pdfFillDto);
|
|
|
|
|
|
document.close();
|
|
document.close();
|
|
|
|
+
|
|
|
|
+
|
|
} catch (DocumentException e) {
|
|
} catch (DocumentException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- if (saveLocal) {
|
|
+ PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
|
|
- PdfFillUtils.saveFile(baos, destFileName);
|
|
+ return dictionaryConfig.uploadPdfFile(file);
|
|
- } else {
|
|
|
|
- ConvertUtil.outputFile(response, baos, destFileName);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
* 卷袋贴生成
|
|
* 卷袋贴生成
|
|
*
|
|
*
|
|
- * @param response response
|
|
|
|
* @param pdfPackageDto 卷袋贴参数
|
|
* @param pdfPackageDto 卷袋贴参数
|
|
* @param destFileName 保存文件名
|
|
* @param destFileName 保存文件名
|
|
* @param saveLocal 是否保存本地
|
|
* @param saveLocal 是否保存本地
|
|
*/
|
|
*/
|
|
- public void createPackagePdf(HttpServletResponse response, PdfPackageDto pdfPackageDto, String destFileName, boolean saveLocal) throws Exception {
|
|
+ public String createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName, boolean saveLocal) throws Exception {
|
|
|
|
|
|
|
|
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
+
|
|
|
|
+ File file = createFolder(SystemConstant.PDF_PREFIX);
|
|
try {
|
|
try {
|
|
|
|
|
|
- PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
|
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
+ PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
|
|
|
document.open();
|
|
document.open();
|
|
|
|
|
|
@@ -88,11 +93,9 @@ public class CreatePrintPdfUtil {
|
|
} catch (DocumentException e) {
|
|
} catch (DocumentException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- if (saveLocal) {
|
|
+
|
|
- PdfFillUtils.saveFile(baos, destFileName);
|
|
+ PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
|
|
- } else {
|
|
+ return dictionaryConfig.uploadPdfFile(file);
|
|
- ConvertUtil.outputFile(response, baos, destFileName);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -122,6 +125,9 @@ public class CreatePrintPdfUtil {
|
|
for (Map<String, String> stringMap : basicPlate) {
|
|
for (Map<String, String> stringMap : basicPlate) {
|
|
basicTable.addCell(PdfFillUtils.createCell(stringMap.get("name") + ":" + stringMap.get("value"), PdfFillUtils.textFont12, null, 16f, Element.ALIGN_LEFT, 0, 1, 3));
|
|
basicTable.addCell(PdfFillUtils.createCell(stringMap.get("name") + ":" + stringMap.get("value"), PdfFillUtils.textFont12, null, 16f, Element.ALIGN_LEFT, 0, 1, 3));
|
|
}
|
|
}
|
|
|
|
+ if (basicPlate.size() % 2 > 0) {
|
|
|
|
+ basicTable.addCell(PdfFillUtils.createCell(" ", PdfFillUtils.textFont12, null, 16f, Element.ALIGN_LEFT, 0, 1, 3));
|
|
|
|
+ }
|
|
document.add(basicTable);
|
|
document.add(basicTable);
|
|
|
|
|
|
document.add(blank);
|
|
document.add(blank);
|
|
@@ -238,6 +244,30 @@ public class CreatePrintPdfUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private File createFolder(String prefix) {
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
|
+ pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
|
|
|
|
+ pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
|
+ pdfStringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(prefix);
|
|
|
|
+ String pdfDirName = pdfStringJoiner.toString();
|
|
|
|
+ DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
|
|
|
|
+ String destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
|
|
|
|
+ File file = new File(destUrl);
|
|
|
|
+ try {
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ }
|
|
|
|
+ return file;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
* 签到表考生签到table表头宽度选择
|
|
* 签到表考生签到table表头宽度选择
|
|
*
|
|
*
|
|
@@ -270,14 +300,16 @@ public class CreatePrintPdfUtil {
|
|
* @param percent 宽度
|
|
* @param percent 宽度
|
|
*/
|
|
*/
|
|
private Font chooseFont(String value, float percent) {
|
|
private Font chooseFont(String value, float percent) {
|
|
- if (value.length() < percent) {
|
|
+ if (StringUtils.isNotBlank(value)) {
|
|
- return PdfFillUtils.textFont12;
|
|
+ if (value.length() < percent) {
|
|
- } else if (value.length() >= percent && value.length() < 1.5 * percent) {
|
|
+ return PdfFillUtils.textFont12;
|
|
- return PdfFillUtils.textFont10;
|
|
+ } else if (value.length() >= percent && value.length() < 1.5 * percent) {
|
|
- } else if (value.length() >= 1.5 * percent && value.length() < 2 * percent) {
|
|
+ return PdfFillUtils.textFont10;
|
|
- return PdfFillUtils.textFont9;
|
|
+ } else if (value.length() >= 1.5 * percent && value.length() < 2 * percent) {
|
|
|
|
+ return PdfFillUtils.textFont9;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return PdfFillUtils.textFont8;
|
|
+ return PdfFillUtils.textFont12;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -452,8 +484,8 @@ public class CreatePrintPdfUtil {
|
|
|
|
|
|
try {
|
|
try {
|
|
CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
|
|
CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
|
|
- createPrintPdfUtil.createSignPdf(null, pdfFillDto, "D:/sign.pdf", true);
|
|
+ createPrintPdfUtil.createSignPdf(pdfFillDto, "D:/sign.pdf", true);
|
|
- createPrintPdfUtil.createPackagePdf(null, pdfPackageDto, "D:/package.pdf", true);
|
|
+ createPrintPdfUtil.createPackagePdf(pdfPackageDto, "D:/package.pdf", true);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|