|
@@ -27,9 +27,11 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(MaterialGenerateServiceImpl.class);
|
|
private static final Logger log = LoggerFactory.getLogger(MaterialGenerateServiceImpl.class);
|
|
|
|
|
|
- private static final int LINE_NUMBER = 30;
|
|
|
|
|
|
+ private static final int FIRST_PAGE_STUDENT_ROW_COUNT = 28;// 首页最多显示多少行学生
|
|
|
|
|
|
- private static final int STUDENT_NUMBER_ROW = 2;
|
|
|
|
|
|
+ private static final int NOT_FIRST_PAGE_STUDENT_ROW_COUNT = 34;// 非首页最多显示多少行学生
|
|
|
|
+
|
|
|
|
+ private static final int STUDENT_GROUP_COUNT = 2;// 每行显示几组学生信息
|
|
|
|
|
|
private static final int FONT_SIZE = 12;
|
|
private static final int FONT_SIZE = 12;
|
|
|
|
|
|
@@ -39,27 +41,41 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
public File generateSignInForm(MaterialTitleInfo title, List<StudentApplyVO> studentList) {
|
|
public File generateSignInForm(MaterialTitleInfo title, List<StudentApplyVO> studentList) {
|
|
Document doc = null;
|
|
Document doc = null;
|
|
ItextDocumentInfo pageModel = new ItextDocumentInfo();
|
|
ItextDocumentInfo pageModel = new ItextDocumentInfo();
|
|
- List<StudentApplyVO> tempList = new ArrayList<StudentApplyVO>();
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
File file = File.createTempFile("Material" + FastUUID.get(), ".tmp");
|
|
File file = File.createTempFile("Material" + FastUUID.get(), ".tmp");
|
|
doc = pageModel.prepareDocument(file);
|
|
doc = pageModel.prepareDocument(file);
|
|
doc.setMargins(20, 20, 20, 20);
|
|
doc.setMargins(20, 20, 20, 20);
|
|
- // title.getTaskName()
|
|
|
|
- Paragraph p1 = new Paragraph("签到表").setFontSize(18).setBold()
|
|
|
|
- .setTextAlignment(TextAlignment.CENTER).setMarginTop(-2);
|
|
|
|
- doc.add(p1);
|
|
|
|
- int fontSize = 12;
|
|
|
|
- doc.add(subHead(title, studentList.size(), fontSize));
|
|
|
|
- for (int k = 0; k < studentList.size(); k++) {
|
|
|
|
- tempList.add(studentList.get(k));
|
|
|
|
- if (tempList.size() == LINE_NUMBER * STUDENT_NUMBER_ROW || k == studentList.size() - 1) {
|
|
|
|
- createSignInTable(tempList, doc);
|
|
|
|
- if (tempList.size() == LINE_NUMBER * STUDENT_NUMBER_ROW) {
|
|
|
|
|
|
+ doc.add(new Paragraph("签到表").setFontSize(18).setBold().setTextAlignment(TextAlignment.CENTER).setMarginTop(-2));
|
|
|
|
+
|
|
|
|
+ int totalSize = studentList.size();
|
|
|
|
+ doc.add(subHead(title, totalSize, FONT_SIZE));
|
|
|
|
+ doc.add(overviewTable(FONT_SIZE, 100, 80, 20));//todo
|
|
|
|
+
|
|
|
|
+ List<StudentApplyVO> tempList = new ArrayList<>();
|
|
|
|
+ for (int index = 0; index < totalSize; index++) {
|
|
|
|
+ tempList.add(studentList.get(index));
|
|
|
|
+
|
|
|
|
+ int rowCount = 0;
|
|
|
|
+ if (index < FIRST_PAGE_STUDENT_ROW_COUNT * STUDENT_GROUP_COUNT) {
|
|
|
|
+ // 首页
|
|
|
|
+ rowCount = FIRST_PAGE_STUDENT_ROW_COUNT;
|
|
|
|
+ } else {
|
|
|
|
+ // 非首页
|
|
|
|
+ rowCount = NOT_FIRST_PAGE_STUDENT_ROW_COUNT;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (tempList.size() == rowCount * STUDENT_GROUP_COUNT || index == totalSize - 1) {
|
|
|
|
+ createSignInTable(tempList, doc, rowCount);
|
|
|
|
+
|
|
|
|
+ if (tempList.size() == rowCount * STUDENT_GROUP_COUNT) {
|
|
doc.add(new AreaBreak());
|
|
doc.add(new AreaBreak());
|
|
}
|
|
}
|
|
|
|
+
|
|
tempList.clear();
|
|
tempList.clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
return file;
|
|
return file;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
@@ -68,12 +84,11 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
} finally {
|
|
} finally {
|
|
ItextPdfUtil.closePdf(doc);
|
|
ItextPdfUtil.closePdf(doc);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void createSignInTable(List<StudentApplyVO> tempList, Document doc) {
|
|
|
|
- Table tableTitle = tableTitle();
|
|
|
|
- int number = Math.min(tempList.size(), LINE_NUMBER);
|
|
|
|
|
|
+ private void createSignInTable(List<StudentApplyVO> tempList, Document doc, int rowCount) {
|
|
|
|
+ Table tableTitle = tableTitle(FONT_SIZE);
|
|
|
|
+ int number = Math.min(tempList.size(), rowCount);
|
|
int nameFontSize = FONT_SIZE;
|
|
int nameFontSize = FONT_SIZE;
|
|
for (int i = 0; i < number; i++) {
|
|
for (int i = 0; i < number; i++) {
|
|
StudentApplyVO result = null;
|
|
StudentApplyVO result = null;
|
|
@@ -106,7 +121,7 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
.setFontSize(10).setHeight(LINE_HEIGHT));
|
|
.setFontSize(10).setHeight(LINE_HEIGHT));
|
|
}
|
|
}
|
|
if (tempList.size() >= i + number + 1) {
|
|
if (tempList.size() >= i + number + 1) {
|
|
- result = tempList.get(i + 30);
|
|
|
|
|
|
+ result = tempList.get(i + rowCount);
|
|
if (result != null && result.getName().length() > 4) {
|
|
if (result != null && result.getName().length() > 4) {
|
|
nameFontSize = 10;
|
|
nameFontSize = 10;
|
|
}
|
|
}
|
|
@@ -137,10 +152,9 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
doc.add(tableTitle);
|
|
doc.add(tableTitle);
|
|
}
|
|
}
|
|
|
|
|
|
- private Table subHead(MaterialTitleInfo title, int studentSize, int titleFontSize) {
|
|
|
|
|
|
+ private Table subHead(MaterialTitleInfo title, int studentSize, int fontSize) {
|
|
Table table = new Table(new float[]{1.2f, 1f}).setWidthPercent(100);
|
|
Table table = new Table(new float[]{1.2f, 1f}).setWidthPercent(100);
|
|
String address = title.getRoomName();
|
|
String address = title.getRoomName();
|
|
- int fontSize = titleFontSize;
|
|
|
|
if (address != null && address.length() > 18) {
|
|
if (address != null && address.length() > 18) {
|
|
fontSize = 10;
|
|
fontSize = 10;
|
|
}
|
|
}
|
|
@@ -156,24 +170,50 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
|
|
return table;
|
|
return table;
|
|
}
|
|
}
|
|
|
|
|
|
- private Table tableTitle() {
|
|
|
|
|
|
+ private Table overviewTable(int fontSize, int totalSize, int finishSize, int absentSize) {
|
|
|
|
+ Table table = new Table(new float[]{1f, 1f, 1f, 1f}).setWidthPercent(100);
|
|
|
|
+ table.addCell(new Cell(1, 1).add("应考人数").setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+ table.addCell(new Cell(1, 1).add(String.valueOf(totalSize)).setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+
|
|
|
|
+ table.addCell(new Cell(1, 1).add("缺考人数").setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(40f));
|
|
|
|
+ table.addCell(new Cell(1, 1).add(String.valueOf(absentSize)).setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+
|
|
|
|
+ table.addCell(new Cell(1, 1).add("实考人数").setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+ table.addCell(new Cell(1, 1).add(String.valueOf(finishSize)).setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+
|
|
|
|
+ table.addCell(new Cell(1, 1).add("监考老师签名").setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(40f));
|
|
|
|
+ table.addCell(new Cell(1, 1).add(" ").setTextAlignment(TextAlignment.LEFT)
|
|
|
|
+ .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(fontSize).setMarginLeft(20f));
|
|
|
|
+
|
|
|
|
+ table.setMarginTop(10);
|
|
|
|
+ table.setMarginBottom(10);
|
|
|
|
+ return table;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Table tableTitle(int fontSize) {
|
|
Table signTable = new Table(new float[]{1f, 1.3f, 0.5f, 1f, 1f, 1.3f, 0.5f, 1f}).setWidthPercent(100);
|
|
Table signTable = new Table(new float[]{1f, 1.3f, 0.5f, 1f, 1f, 1.3f, 0.5f, 1f}).setWidthPercent(100);
|
|
- for (int i = 0; i < STUDENT_NUMBER_ROW; i++) {
|
|
|
|
|
|
+ for (int i = 0; i < STUDENT_GROUP_COUNT; i++) {
|
|
signTable.addCell(
|
|
signTable.addCell(
|
|
new Cell(1, 1).add("姓名").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
new Cell(1, 1).add("姓名").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
- .setFontSize(FONT_SIZE).setBold());
|
|
|
|
|
|
+ .setFontSize(fontSize).setBold());
|
|
signTable.addCell(
|
|
signTable.addCell(
|
|
new Cell(1, 1).add("学号").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
new Cell(1, 1).add("学号").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
- .setFontSize(FONT_SIZE).setBold());
|
|
|
|
|
|
+ .setFontSize(fontSize).setBold());
|
|
signTable.addCell(
|
|
signTable.addCell(
|
|
new Cell(1, 1).add("座号").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
new Cell(1, 1).add("座号").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
- .setFontSize(FONT_SIZE).setBold());
|
|
|
|
|
|
+ .setFontSize(fontSize).setBold());
|
|
signTable.addCell(
|
|
signTable.addCell(
|
|
new Cell(1, 1).add("签字").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
new Cell(1, 1).add("签字").setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
|
|
- .setFontSize(FONT_SIZE).setBold());
|
|
|
|
|
|
+ .setFontSize(fontSize).setBold());
|
|
}
|
|
}
|
|
return signTable;
|
|
return signTable;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|