|
@@ -9,7 +9,6 @@ import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
-import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.templete.service.TaskLogicService;
|
|
|
import com.qmth.distributed.print.business.util.GoogleBarCodeUtil;
|
|
@@ -33,7 +32,6 @@ import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -179,11 +177,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
|
|
|
List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
|
|
|
|
|
|
- StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
|
List<String> paperPdfList = new ArrayList<>();
|
|
|
List<String> cardPdfList = new ArrayList<>();
|
|
|
- List<String> studentPdfList = new ArrayList<>();
|
|
|
+ List<String> examStudentPdfList = new ArrayList<>();
|
|
|
//查询试卷
|
|
|
QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
|
examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
|
|
@@ -248,23 +245,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
for (String paperType : paperTypes) {
|
|
|
for (Integer integer = 1; integer <= examPrintPlan.getBackupCount(); integer++) {
|
|
|
- //通用题卡
|
|
|
- String cardTemp = cardContent;
|
|
|
- cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", paperType);
|
|
|
- //随机生成试卷条码并将图片转成base64
|
|
|
- cardTemp = cardTemp.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
|
|
|
- //通用题卡生成卷袋贴条码
|
|
|
- String paperCode = examDetailCourse.getPaperNumber();
|
|
|
- String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
|
|
|
- String paperCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 80px;right: 35px;transform: rotate(-90deg);transform-origin: center right;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + paperCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + paperCode + "</p></div>";
|
|
|
- cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
|
|
|
- BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, sysUser.getId(), cardPdfList);
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.put("name", paperType);
|
|
|
- object.put("examTaskDetailId", examTaskDetail.getId());
|
|
|
- object.put("attachmentId", cardAttachment.getId());
|
|
|
- jsonArray.add(object);
|
|
|
- basicAttachmentList.add(cardAttachment);
|
|
|
+ basicAttachmentList.add(cardHtml(cardContent, paperType, examDetailCourse, examCard, examTaskDetail, jsonArray, sysUser.getId(), cardPdfList));
|
|
|
}
|
|
|
|
|
|
//查询考生
|
|
@@ -274,33 +255,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
|
|
|
|
for (ExamStudent t : examStudentList) {
|
|
|
- if (Objects.nonNull(t.getAttachmentId())) {
|
|
|
- attachmentIds.add(t.getAttachmentId());
|
|
|
- }
|
|
|
- String studentHtml = studentContent;
|
|
|
- if (Objects.nonNull(t.getExtendFields())) {
|
|
|
- JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
|
|
|
- if (Objects.nonNull(jsonObjectExtend)) {
|
|
|
- for (int i = 0; i < jsonObjectExtend.size(); i++) {
|
|
|
- JSONObject object = (JSONObject) jsonObjectExtend.get(i);
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //生成学生考号条码并将图片转成base64
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(t.getTicketNumber(), false));
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", t.getTicketNumber());
|
|
|
- //随机生成学生试卷条码并将图片转成base64
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", paperType);
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", t.getStudentCode());
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{name\\}", t.getStudentName());
|
|
|
- studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
|
|
|
-
|
|
|
- //学生题卡
|
|
|
- BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, sysUser.getId(), studentPdfList);
|
|
|
- t.setAttachmentId(examStudentAttachment.getId());
|
|
|
- basicAttachmentList.add(examStudentAttachment);
|
|
|
+ basicAttachmentList.add(examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentPdfList));
|
|
|
}
|
|
|
examStudentService.saveOrUpdateBatch(examStudentList);
|
|
|
}
|
|
@@ -308,37 +263,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
examCardDetail.setAttachmentId(jsonObject.toJSONString());
|
|
|
}
|
|
|
examCardDetailService.saveOrUpdateBatch(examCardDetailList);
|
|
|
- List<String> mergePdfList = new ArrayList<>();
|
|
|
- mergePdfList.addAll(paperPdfList);
|
|
|
- mergePdfList.addAll(cardPdfList);
|
|
|
- mergePdfList.addAll(studentPdfList);
|
|
|
- String dirName = PdfUtil.mergePdf(mergePdfList.toArray(new String[mergePdfList.size()]), null);
|
|
|
- File localPdfFile = new File(stringJoiner.toString() + File.separator + dirName);
|
|
|
- JSONObject jsonPdf = new JSONObject();
|
|
|
- jsonPdf.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- jsonPdf.put(SystemConstant.PATH, dirName);
|
|
|
- jsonPdf.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.PDF);
|
|
|
- BasicAttachment basicAttachment = new BasicAttachment(jsonPdf.toJSONString(), localPdfFile.getName(), SystemConstant.PDF_PREFIX, new BigDecimal(localPdfFile.length()), DigestUtils.md5Hex(new FileInputStream(localPdfFile)), sysUser.getId());
|
|
|
- basicAttachmentService.save(basicAttachment);
|
|
|
- tbTask.setImportFileName(basicAttachment.getName());
|
|
|
- tbTask.setImportFilePath(basicAttachment.getPath());
|
|
|
- examDetail.setAttachmentId(basicAttachment.getId());
|
|
|
- detailService.saveOrUpdate(examDetail);
|
|
|
- basicAttachmentList.add(basicAttachment);
|
|
|
- ossUtil.ossUpload(dirName, localPdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(localPdfFile)))));
|
|
|
- localPdfFile.delete();
|
|
|
- for (String s : mergePdfList) {
|
|
|
- new File(s).delete();
|
|
|
- }
|
|
|
+
|
|
|
+ //合并pdf
|
|
|
+ basicAttachmentList.add(mergePdf(tbTask, examDetail, sysUser.getId(), paperPdfList, cardPdfList, examStudentPdfList));
|
|
|
}
|
|
|
}
|
|
|
//最后一步删除附件
|
|
|
- if (Objects.nonNull(attachmentIds) && attachmentIds.size() > 0) {
|
|
|
- QueryWrapper<BasicAttachment> basicAttachmentQueryWrapper = new QueryWrapper<>();
|
|
|
- basicAttachmentQueryWrapper.lambda().in(BasicAttachment::getId, attachmentIds);
|
|
|
- basicAttachmentService.batchDeleteAttachment(basicAttachmentService.list(basicAttachmentQueryWrapper));
|
|
|
- basicAttachmentService.removeByIds(attachmentIds);
|
|
|
- }
|
|
|
+ deleteAttachment(attachmentIds);
|
|
|
} catch (Exception e) {
|
|
|
log.error("请求出错", e);
|
|
|
basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
|
|
@@ -350,4 +281,126 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合并pdf
|
|
|
+ *
|
|
|
+ * @param tbTask
|
|
|
+ * @param examDetail
|
|
|
+ * @param userId
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public BasicAttachment mergePdf(TBTask tbTask, ExamDetail examDetail, Long userId, List<String>... list) throws IOException {
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
|
+ List<String> mergePdfList = new ArrayList<>();
|
|
|
+ mergePdfList.addAll(list[0]);
|
|
|
+ mergePdfList.addAll(list[1]);
|
|
|
+ mergePdfList.addAll(list[2]);
|
|
|
+ String dirName = PdfUtil.mergePdf(mergePdfList.toArray(new String[mergePdfList.size()]), null);
|
|
|
+ File localPdfFile = new File(stringJoiner.toString() + File.separator + dirName);
|
|
|
+ BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirName, userId);
|
|
|
+ tbTask.setImportFileName(basicAttachment.getName());
|
|
|
+ tbTask.setImportFilePath(basicAttachment.getPath());
|
|
|
+ examDetail.setAttachmentId(basicAttachment.getId());
|
|
|
+ detailService.saveOrUpdate(examDetail);
|
|
|
+ ossUtil.ossUpload(dirName, localPdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(localPdfFile)))));
|
|
|
+ localPdfFile.delete();
|
|
|
+ for (String s : mergePdfList) {
|
|
|
+ new File(s).delete();
|
|
|
+ }
|
|
|
+ return basicAttachment;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除附件
|
|
|
+ *
|
|
|
+ * @param attachmentIds
|
|
|
+ */
|
|
|
+ public void deleteAttachment(Set<Long> attachmentIds) {
|
|
|
+ if (Objects.nonNull(attachmentIds) && attachmentIds.size() > 0) {
|
|
|
+ QueryWrapper<BasicAttachment> basicAttachmentQueryWrapper = new QueryWrapper<>();
|
|
|
+ basicAttachmentQueryWrapper.lambda().in(BasicAttachment::getId, attachmentIds);
|
|
|
+ basicAttachmentService.batchDeleteAttachment(basicAttachmentService.list(basicAttachmentQueryWrapper));
|
|
|
+ basicAttachmentService.removeByIds(attachmentIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考生题卡html
|
|
|
+ *
|
|
|
+ * @param attachmentIds
|
|
|
+ * @param studentContent
|
|
|
+ * @param t
|
|
|
+ * @param paperType
|
|
|
+ * @param examCard
|
|
|
+ * @param userId
|
|
|
+ * @param examStudentPdfList
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public BasicAttachment examStudentHtml(Set<Long> attachmentIds, String studentContent, ExamStudent t, String paperType, ExamCard examCard, Long userId, List<String> examStudentPdfList) throws IOException {
|
|
|
+ if (Objects.nonNull(t.getAttachmentId())) {
|
|
|
+ attachmentIds.add(t.getAttachmentId());
|
|
|
+ }
|
|
|
+ String studentHtml = studentContent;
|
|
|
+ if (Objects.nonNull(t.getExtendFields())) {
|
|
|
+ JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
|
|
|
+ if (Objects.nonNull(jsonObjectExtend)) {
|
|
|
+ for (int i = 0; i < jsonObjectExtend.size(); i++) {
|
|
|
+ JSONObject object = (JSONObject) jsonObjectExtend.get(i);
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成学生考号条码并将图片转成base64
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(t.getTicketNumber(), false));
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", t.getTicketNumber());
|
|
|
+ //随机生成学生试卷条码并将图片转成base64
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", paperType);
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", t.getStudentCode());
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{name\\}", t.getStudentName());
|
|
|
+ studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
|
|
|
+
|
|
|
+ //学生题卡
|
|
|
+ BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, userId, examStudentPdfList);
|
|
|
+ t.setAttachmentId(examStudentAttachment.getId());
|
|
|
+ return examStudentAttachment;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用题卡html
|
|
|
+ *
|
|
|
+ * @param cardContent
|
|
|
+ * @param paperType
|
|
|
+ * @param examDetailCourse
|
|
|
+ * @param examCard
|
|
|
+ * @param examTaskDetail
|
|
|
+ * @param jsonArray
|
|
|
+ * @param userId
|
|
|
+ * @param cardPdfList
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, ExamTaskDetail examTaskDetail, JSONArray jsonArray, Long userId, List<String> cardPdfList) throws IOException {
|
|
|
+ //通用题卡
|
|
|
+ String cardTemp = cardContent;
|
|
|
+ cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", paperType);
|
|
|
+ //随机生成试卷条码并将图片转成base64
|
|
|
+ cardTemp = cardTemp.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
|
|
|
+ //通用题卡生成卷袋贴条码
|
|
|
+ String paperCode = examDetailCourse.getPaperNumber();
|
|
|
+ String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
|
|
|
+ String paperCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 80px;right: 35px;transform: rotate(-90deg);transform-origin: center right;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + paperCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + paperCode + "</p></div>";
|
|
|
+ cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
|
|
|
+ BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, userId, cardPdfList);
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("name", paperType);
|
|
|
+ object.put("examTaskDetailId", examTaskDetail.getId());
|
|
|
+ object.put("attachmentId", cardAttachment.getId());
|
|
|
+ jsonArray.add(object);
|
|
|
+ return cardAttachment;
|
|
|
+ }
|
|
|
}
|