|
@@ -57,6 +57,7 @@ import java.io.*;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -169,7 +170,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
PrintCommonService printCommonService;
|
|
|
|
|
|
@Resource
|
|
|
- private BasicPrintConfigService basicPrintConfigService;
|
|
|
+ private BasicExamService basicExamService;
|
|
|
|
|
|
/**
|
|
|
* 创建pdf前置条件
|
|
@@ -216,18 +217,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
/**
|
|
|
* 创建pdf核心逻辑
|
|
|
- *
|
|
|
* @param examDetailCourseList
|
|
|
- * @param examPrintPlan
|
|
|
- * @param examDetail
|
|
|
- * @param sysUser
|
|
|
- * @param paperTypeParam
|
|
|
- * @param basicAttachmentList
|
|
|
+ * @param examPrintPlan 印刷计划
|
|
|
+ * @param examDetail 考场对象
|
|
|
+ * @param sysUser 当前用户
|
|
|
+ * @param paperTypeParam 试卷类型
|
|
|
+ * @param basicAttachmentList 附件集合
|
|
|
* @param attachmentIds
|
|
|
* @param list
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- * @throws DocumentException
|
|
|
*/
|
|
|
@Transactional
|
|
|
public List<BasicAttachment> createPdfCoreLogic(List<ExamDetailCourse> examDetailCourseList,
|
|
@@ -242,32 +239,27 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
|
|
|
Map<Long, BasicCardRule> basicCardRuleMap = new HashMap<>();
|
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
|
- List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
|
|
|
- List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
|
|
|
- List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
|
|
|
- List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
|
|
|
+ List<PdfDto> studentPaperPdfList = new ArrayList<>();//所有试卷
|
|
|
+ List<PdfDto> studentCardPdfList = new ArrayList<>();//所有题卡
|
|
|
+ List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
|
|
|
+ List<PdfDto> backupCardPdfList = new ArrayList<>();//备份题卡
|
|
|
|
|
|
String printContent = examPrintPlan.getPrintContent();
|
|
|
if (StringUtils.isBlank(printContent)) {
|
|
|
return null;
|
|
|
}
|
|
|
//查询试卷
|
|
|
- List<ExamTask> examTaskList = examTaskService.findByFlowStatus(sysUser.getSchoolId()
|
|
|
- , examDetailCourse.getCourseCode()
|
|
|
- , examDetailCourse.getCourseName()
|
|
|
- , examDetailCourse.getPaperNumber()
|
|
|
- , FlowStatusEnum.FINISH);
|
|
|
+ List<ExamTask> examTaskList = examTaskService.findByFlowStatus(sysUser.getSchoolId(), examDetailCourse.getCourseCode(), examDetailCourse.getCourseName(), examDetailCourse.getPaperNumber(), FlowStatusEnum.FINISH);
|
|
|
if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
|
|
|
throw ExceptionResultEnum.EXAM_TASK_IS_NULL.exception();
|
|
|
}
|
|
|
Set<Long> examTaskIds = examTaskList.stream().map(ExamTask::getId).collect(Collectors.toSet());
|
|
|
- Map<Long, ExamTask> examTaskMap = examTaskList.stream().collect(
|
|
|
- Collectors.toMap(ExamTask::getId, Function.identity(), (dto1, dto2) -> dto1));
|
|
|
+ Map<Long, ExamTask> examTaskMap = examTaskList.stream().collect(Collectors.toMap(ExamTask::getId, Function.identity(), (dto1, dto2) -> dto1));
|
|
|
|
|
|
QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
|
|
|
- .eq(ExamTaskDetail::getEnable, true);
|
|
|
+ examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds).eq(ExamTaskDetail::getEnable, true);
|
|
|
List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
|
|
|
+
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
|
|
@@ -277,28 +269,27 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
throw ExceptionResultEnum.EXAM_CARD_IS_NULL.exception();
|
|
|
}
|
|
|
|
|
|
- //查询题卡规则
|
|
|
ExamTask examTask = examTaskMap.get(examTaskDetail.getExamTaskId());
|
|
|
+
|
|
|
+ //查询题卡规则
|
|
|
BasicCardRule basicCardRule = null;
|
|
|
- if (Objects.nonNull(examTask)) {
|
|
|
- if (!basicCardRuleMap.containsKey(examTask.getCardRuleId())) {
|
|
|
- basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
- BasicCardRule finalBasicCardRule = basicCardRule;
|
|
|
- basicCardRuleMap.computeIfAbsent(examTask.getCardRuleId(), v -> finalBasicCardRule);
|
|
|
- } else {
|
|
|
- basicCardRule = basicCardRuleMap.get(examTask.getCardRuleId());
|
|
|
- }
|
|
|
+ if (!basicCardRuleMap.containsKey(examTask.getCardRuleId())) {
|
|
|
+ basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
+ BasicCardRule finalBasicCardRule = basicCardRule;
|
|
|
+ basicCardRuleMap.computeIfAbsent(examTask.getCardRuleId(), v -> finalBasicCardRule);
|
|
|
+ } else {
|
|
|
+ basicCardRule = basicCardRuleMap.get(examTask.getCardRuleId());
|
|
|
}
|
|
|
- QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
|
|
|
- List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
|
|
|
|
//拼装key
|
|
|
- String key = examDetail.getSchoolId()
|
|
|
- + "_" + examDetail.getExamStartTime()
|
|
|
- + "_" + examDetail.getExamEndTime()
|
|
|
- + "_" + examDetailCourse.getCourseCode()
|
|
|
- + "_" + examDetailCourse.getPaperNumber();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("_");
|
|
|
+ stringJoiner.add(String.valueOf(examDetail.getSchoolId()))
|
|
|
+ .add(String.valueOf(examDetail.getExamStartTime()))
|
|
|
+ .add(String.valueOf(examDetail.getExamEndTime()))
|
|
|
+ .add(examDetailCourse.getCourseCode())
|
|
|
+ .add(examDetailCourse.getPaperNumber());
|
|
|
+ String key = stringJoiner.toString();
|
|
|
+
|
|
|
String paperType;
|
|
|
if (Objects.nonNull(paperTypeParam)) {
|
|
|
paperType = paperTypeParam;
|
|
@@ -311,72 +302,139 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
//查询考生
|
|
|
QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
|
|
|
- examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
|
|
|
- .eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
|
|
|
+ examStudentQueryWrapper.lambda().eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
|
|
|
List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
|
|
|
|
+ // 查询考试
|
|
|
+ BasicExam basicExam = basicExamService.getById(examTask.getExamId());
|
|
|
+ //
|
|
|
List<String> paperTypes = Arrays.asList(paperType.split(",")).stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList());
|
|
|
- int i1 = 0;
|
|
|
- for (ExamStudent t : examStudentList) {
|
|
|
- int mod = i1 % examTaskDetail.getDrawCount();
|
|
|
- String stuPaperType = paperTypes.get(mod);
|
|
|
- t.setPaperType(stuPaperType);
|
|
|
- i1++;
|
|
|
- }
|
|
|
-
|
|
|
- List<PaperPdfDto> paperPdfDto = null;
|
|
|
-
|
|
|
int backupCount = examPrintPlan.getBackupCount() != null ? examPrintPlan.getBackupCount() : 0;
|
|
|
|
|
|
- if (printContent.contains("PAPER")) {
|
|
|
- paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
|
|
|
-
|
|
|
- //获取试卷pdf
|
|
|
- PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperTempPdfList);
|
|
|
- if (Objects.nonNull(pdfDto)) {
|
|
|
- examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
|
|
|
- } else {
|
|
|
- examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
|
|
|
+ if (examStudentList != null && examStudentList.size() > 0) {
|
|
|
+ AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
|
+ for (ExamStudent t : examStudentList) {
|
|
|
+ int i1 = atomicInteger.getAndIncrement();
|
|
|
+ int mod = i1 % examTaskDetail.getDrawCount();
|
|
|
+ t.setPaperType(paperTypes.get(mod));
|
|
|
}
|
|
|
- // 备用试卷
|
|
|
- list[0].addAll(backupPaperTempPdfList);
|
|
|
|
|
|
- for (ExamStudent t : examStudentList) {
|
|
|
+ // 试卷
|
|
|
+ if (printContent.contains("PAPER")) {
|
|
|
+ List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
|
|
|
+
|
|
|
+ //获取试卷pdf
|
|
|
+ PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperPdfList);
|
|
|
if (Objects.nonNull(pdfDto)) {
|
|
|
- createPdfUtil.getExamStudentPaperPdf(t.getPaperType(), paperPdfDto, paperPdfTempList);
|
|
|
+ examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
|
|
|
+ } else {
|
|
|
+ examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
|
|
|
+ }
|
|
|
+ // 备用试卷
|
|
|
+ list[0].addAll(backupPaperPdfList);
|
|
|
+
|
|
|
+ for (ExamStudent t : examStudentList) {
|
|
|
+ if (Objects.nonNull(pdfDto)) {
|
|
|
+ PdfDto stuPdfDto = createPdfUtil.getExamStudentPaperPdf(t.getPaperType(), paperPdfDto, studentPaperPdfList);
|
|
|
+ }
|
|
|
}
|
|
|
+ // 考生试卷
|
|
|
+ list[2].addAll(studentPaperPdfList);
|
|
|
}
|
|
|
- // 试卷
|
|
|
- list[2].addAll(paperPdfTempList);
|
|
|
- }
|
|
|
|
|
|
- basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
|
|
|
- if (printContent.contains("CARD")) {
|
|
|
- for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
|
+ basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
|
|
|
+ if (printContent.contains("CARD")) {
|
|
|
+ QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
|
|
|
+
|
|
|
createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
|
|
|
|
|
|
//把模板页面上的 ${} 替换成实际内容
|
|
|
- String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
|
|
|
+ String cardContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
|
|
|
String studentContent = examCardDetail.getHtmlContent();
|
|
|
|
|
|
for (int i = 1; i <= backupCount; i++) {
|
|
|
- BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList, basicCardRule);
|
|
|
+ BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
|
|
|
examDetailCourse.setCardPagesA3(basicAttachment.getPages());
|
|
|
basicAttachmentList.add(basicAttachment);
|
|
|
}
|
|
|
// 备用题卡
|
|
|
- list[1].addAll(cardPdfTempList);
|
|
|
+ list[1].addAll(backupCardPdfList);
|
|
|
|
|
|
for (ExamStudent t : examStudentList) {
|
|
|
- basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, examDetail, examDetailCourse, sysUser.getId(), examStudentTempPdfList, basicCardRule));
|
|
|
+ basicAttachmentList.add(createPdfUtil.examStudentHtml(studentContent, t, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
|
|
|
+ }
|
|
|
+ // 题卡
|
|
|
+ list[3].addAll(studentCardPdfList);
|
|
|
+ jsonObject.put("card", jsonArray);
|
|
|
+ examDetailCourse.setAttachmentId(jsonObject.toJSONString());
|
|
|
+ }
|
|
|
+ examStudentService.saveOrUpdateBatch(examStudentList);
|
|
|
+ } else if (examDetail.getPrintCount() != null){
|
|
|
+ // 试卷
|
|
|
+ if (printContent.contains("PAPER")) {
|
|
|
+ List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
|
|
|
+
|
|
|
+ //获取试卷pdf
|
|
|
+ PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperPdfList);
|
|
|
+ if (Objects.nonNull(pdfDto)) {
|
|
|
+ examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
|
|
|
+ } else {
|
|
|
+ examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
|
|
|
}
|
|
|
+ // 备用试卷
|
|
|
+ list[0].addAll(backupPaperPdfList);
|
|
|
+
|
|
|
+ AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
|
+ int i = 0;
|
|
|
+ while (i < examDetail.getPrintCount()) {
|
|
|
+ int i1 = atomicInteger.getAndIncrement();
|
|
|
+ int mod = i1 % examTaskDetail.getDrawCount();
|
|
|
+ if (Objects.nonNull(pdfDto)) {
|
|
|
+ PdfDto stuPdfDto = createPdfUtil.getExamStudentPaperPdf(paperTypes.get(mod), paperPdfDto, studentPaperPdfList);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 考生试卷
|
|
|
+ list[2].addAll(studentPaperPdfList);
|
|
|
+ }
|
|
|
+
|
|
|
+ basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
|
|
|
+ if (printContent.contains("CARD")) {
|
|
|
+ QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
|
|
|
+
|
|
|
+ createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
|
|
|
+
|
|
|
+ //把模板页面上的 ${} 替换成实际内容
|
|
|
+ String cardContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
|
|
|
+
|
|
|
+ for (int i = 1; i <= backupCount; i++) {
|
|
|
+ BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
|
|
|
+ examDetailCourse.setCardPagesA3(basicAttachment.getPages());
|
|
|
+ basicAttachmentList.add(basicAttachment);
|
|
|
+ }
|
|
|
+ // 备用题卡
|
|
|
+ list[1].addAll(backupCardPdfList);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ while (i < examDetail.getPrintCount()) {
|
|
|
+ ExamStudent student = new ExamStudent();
|
|
|
+ student.setTicketNumber(Integer.toString(i));
|
|
|
+ basicAttachmentList.add(createPdfUtil.examStudentHtml(cardContent, student, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+
|
|
|
// 题卡
|
|
|
- list[3].addAll(examStudentTempPdfList);
|
|
|
+ list[3].addAll(studentCardPdfList);
|
|
|
jsonObject.put("card", jsonArray);
|
|
|
examDetailCourse.setAttachmentId(jsonObject.toJSONString());
|
|
|
}
|
|
|
+ examStudentService.saveOrUpdateBatch(examStudentList);
|
|
|
}
|
|
|
- examStudentService.saveOrUpdateBatch(examStudentList);
|
|
|
}
|
|
|
examDetailCourse.setAttachmentId(jsonObject.toJSONString());
|
|
|
examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
|
|
@@ -1104,7 +1162,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
|
|
|
String htmlContent;
|
|
|
if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
|
|
|
- htmlContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
|
|
|
} else {
|
|
|
BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|