|
@@ -1,11 +1,15 @@
|
|
|
package com.qmth.distributed.print.business.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.itextpdf.text.*;
|
|
|
import com.itextpdf.text.pdf.*;
|
|
|
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.examRule.CodeNameEnableRate;
|
|
|
import com.qmth.distributed.print.business.entity.BasicTemplate;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.FontSizeEnum;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -16,6 +20,7 @@ import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* pdf模板内容填充
|
|
@@ -144,7 +149,7 @@ public class CreatePrintPdfUtil {
|
|
|
//表头
|
|
|
Map<String, String> studentHeadPlate = pdfFillDto.getStudentHeadPlate();
|
|
|
//计算表格宽度
|
|
|
- float[] columnWidth = chooseColumnWidth(studentHeadPlate.size(), diallel);
|
|
|
+ float[] columnWidth = createColumnWidth(basicTemplate);
|
|
|
int columnCount = studentHeadPlate.size();
|
|
|
|
|
|
PdfPTable studentTable = PdfFillUtils.createTable(columnWidth);
|
|
@@ -160,7 +165,7 @@ public class CreatePrintPdfUtil {
|
|
|
if ("座位号".equals(value)) {
|
|
|
value = "座号";
|
|
|
}
|
|
|
- studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, PdfFillUtils.textFont9, BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, chooseFont(basicTemplate), BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
j++;
|
|
|
}
|
|
|
}
|
|
@@ -174,19 +179,19 @@ public class CreatePrintPdfUtil {
|
|
|
Map<String, String> stringMap1 = studentPlate.get(2 * i);
|
|
|
for (int j = 0; j < stringMap1.size(); j++) {
|
|
|
String value = stringMap1.get(headKeys[j]);
|
|
|
- studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, PdfFillUtils.textFont9, null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, chooseFont(basicTemplate), null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
}
|
|
|
|
|
|
if (studentPlateCount % 2 > 0 && 2 * i + 1 == studentPlate.size()) {
|
|
|
for (int i1 = 0; i1 < columnCount; i1++) {
|
|
|
- studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, "", PdfFillUtils.textFont9, null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, "", chooseFont(basicTemplate), null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
Map<String, String> stringMap2 = studentPlate.get(2 * i + 1);
|
|
|
for (int j = 0; j < stringMap2.size(); j++) {
|
|
|
String value = stringMap2.get(headKeys[j + columnCount]);
|
|
|
- studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, PdfFillUtils.textFont9, null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, chooseFont(basicTemplate), null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -200,7 +205,7 @@ public class CreatePrintPdfUtil {
|
|
|
if ("座位号".equals(value)) {
|
|
|
value = "座号";
|
|
|
}
|
|
|
- studentTable.addCell(PdfFillUtils.createCell(value, PdfFillUtils.textFont9, BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, chooseFont(basicTemplate), BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
k++;
|
|
|
}
|
|
|
|
|
@@ -212,7 +217,7 @@ public class CreatePrintPdfUtil {
|
|
|
Map<String, String> stringMap1 = studentPlate.get(i);
|
|
|
for (int j = 0; j < stringMap1.size(); j++) {
|
|
|
String value = stringMap1.get(headKeys[j]);
|
|
|
- studentTable.addCell(PdfFillUtils.createCell(value, PdfFillUtils.textFont9, null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
+ studentTable.addCell(PdfFillUtils.createCell1(lineHeightTimes, value, chooseFont(basicTemplate), null, Element.ALIGN_CENTER, 0, 1, 1));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -347,42 +352,24 @@ public class CreatePrintPdfUtil {
|
|
|
/**
|
|
|
* 签到表考生签到table表头宽度选择
|
|
|
*
|
|
|
- * @param size 表头字段数量
|
|
|
- * @param diallel
|
|
|
+ * @param basicTemplate 表头字段数量
|
|
|
*/
|
|
|
- private float[] chooseColumnWidth(int size, Boolean diallel) {
|
|
|
+ private float[] createColumnWidth(BasicTemplate basicTemplate) {
|
|
|
+ JSONObject object = JSONObject.parseObject(basicTemplate.getDisplayRange());
|
|
|
+ List<CodeNameEnableRate> tableDisplayRanges = JSONObject.parseArray(object.getString("table"), CodeNameEnableRate.class);
|
|
|
+ List<Float> rateList = tableDisplayRanges.stream().filter(CodeNameEnableRate::getEnable).map(m -> Float.parseFloat(String.valueOf(m.getRate()))).collect(Collectors.toList());
|
|
|
float[] columnWidth;
|
|
|
- if (diallel) {
|
|
|
- if (size == 1) {
|
|
|
- columnWidth = new float[]{50, 50};
|
|
|
- } else if (size == 2) {
|
|
|
- columnWidth = new float[]{20, 30, 20, 30};
|
|
|
- } else if (size == 3) {
|
|
|
- columnWidth = new float[]{15, 20, 15, 15, 20, 15};
|
|
|
- } else if (size == 4) {
|
|
|
- columnWidth = new float[]{6, 14, 15, 15, 6, 14, 15, 15};
|
|
|
- } else if (size == 5) {
|
|
|
- columnWidth = new float[]{4, 8, 10, 20, 8, 4, 8, 10, 20, 8};
|
|
|
- } else if (size == 6) {
|
|
|
- columnWidth = new float[]{6, 9, 9, 9, 9, 8, 6, 9, 9, 9, 9, 8};
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("签到表最多只能显示6个信息");
|
|
|
+ if (basicTemplate.getDiallel()) {
|
|
|
+ columnWidth = new float[rateList.size() * 2];
|
|
|
+ for (int i = 0; i < 2; i++) {
|
|
|
+ for (int i1 = 0; i1 < rateList.size(); i1++) {
|
|
|
+ columnWidth[rateList.size() * i + i1] = rateList.get(i1) / 2;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- if (size == 1) {
|
|
|
- columnWidth = new float[]{100};
|
|
|
- } else if (size == 2) {
|
|
|
- columnWidth = new float[]{50, 50};
|
|
|
- } else if (size == 3) {
|
|
|
- columnWidth = new float[]{30, 40, 30};
|
|
|
- } else if (size == 4) {
|
|
|
- columnWidth = new float[]{12, 28, 30, 30};
|
|
|
- } else if (size == 5) {
|
|
|
- columnWidth = new float[]{8, 16, 20, 38, 18};
|
|
|
- } else if (size == 6) {
|
|
|
- columnWidth = new float[]{12, 18, 18, 18, 18, 16};
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("签到表最多只能显示6个信息");
|
|
|
+ columnWidth = new float[rateList.size()];
|
|
|
+ for (int i = 0; i < rateList.size(); i++) {
|
|
|
+ columnWidth[i] = rateList.get(i);
|
|
|
}
|
|
|
}
|
|
|
return columnWidth;
|
|
@@ -391,20 +378,28 @@ public class CreatePrintPdfUtil {
|
|
|
/**
|
|
|
* 根据表格大小,选择字号
|
|
|
*
|
|
|
- * @param value 值
|
|
|
- * @param percent 宽度
|
|
|
+ * @param basicTemplate 值
|
|
|
*/
|
|
|
- private Font chooseFont(String value, float percent) {
|
|
|
- /*if (StringUtils.isNotBlank(value)) {
|
|
|
- if (value.length() < percent) {
|
|
|
- return PdfFillUtils.textFont12;
|
|
|
- } else if (value.length() >= percent && value.length() < 1.5 * percent) {
|
|
|
- return PdfFillUtils.textFont10;
|
|
|
- } else if (value.length() >= 1.5 * percent && value.length() < 2 * percent) {
|
|
|
- return PdfFillUtils.textFont9;
|
|
|
- }
|
|
|
- }*/
|
|
|
- return PdfFillUtils.textFont11;
|
|
|
+ private Font chooseFont(BasicTemplate basicTemplate) {
|
|
|
+ FontSizeEnum fontSize = basicTemplate.getFontSize();
|
|
|
+ if (fontSize == null) {
|
|
|
+ return PdfFillUtils.textFont9;
|
|
|
+ }
|
|
|
+ Font font = PdfFillUtils.textFont9;
|
|
|
+ switch (fontSize) {
|
|
|
+ case SMALL:
|
|
|
+ font = PdfFillUtils.textFont9;
|
|
|
+ break;
|
|
|
+ case MEDIUM:
|
|
|
+ font = PdfFillUtils.textFont11;
|
|
|
+ break;
|
|
|
+ case LARGE:
|
|
|
+ font = PdfFillUtils.textFont14;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return font;
|
|
|
}
|
|
|
|
|
|
/**
|