|
@@ -5,14 +5,15 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
-import com.itextpdf.text.DocumentException;
|
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
-import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
|
|
|
|
import com.qmth.distributed.print.business.bean.dto.FieldsDto;
|
|
import com.qmth.distributed.print.business.bean.dto.FieldsDto;
|
|
|
|
+import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
|
|
import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
|
|
import com.qmth.distributed.print.business.bean.result.ExaminationResult;
|
|
import com.qmth.distributed.print.business.bean.result.ExaminationResult;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
-import com.qmth.distributed.print.business.enums.*;
|
|
|
|
|
|
+import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
|
+import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
|
|
+import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.templete.service.TaskLogicService;
|
|
import com.qmth.distributed.print.business.templete.service.TaskLogicService;
|
|
import com.qmth.distributed.print.business.util.*;
|
|
import com.qmth.distributed.print.business.util.*;
|
|
@@ -21,7 +22,6 @@ import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import com.qmth.distributed.print.common.util.Base64Util;
|
|
import com.qmth.distributed.print.common.util.Base64Util;
|
|
import com.qmth.distributed.print.common.util.ResultUtil;
|
|
import com.qmth.distributed.print.common.util.ResultUtil;
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
@@ -98,10 +98,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
CacheService cacheService;
|
|
CacheService cacheService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- FreemarkerUtil freemarkerUtil;
|
|
|
|
|
|
+ BasicCourseService basicCourseService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- BasicCourseService basicCourseService;
|
|
|
|
|
|
+ CreatePdfUtil createPdfUtil;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 执行导入用户逻辑
|
|
* 执行导入用户逻辑
|
|
@@ -201,12 +201,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
|
|
examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
|
|
List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
|
|
List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
|
|
|
|
|
|
- List<String> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
|
|
|
|
- List<String> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
|
|
|
|
- List<String> paperPdfList = new ArrayList<>();//所有试卷
|
|
|
|
- List<String> examStudentPdfList = new ArrayList<>();//所有题卡
|
|
|
|
- List<String> backupPaperPdfList = new ArrayList<>();//备份试卷
|
|
|
|
- List<String> cardPdfList = new ArrayList<>();//备份题卡
|
|
|
|
|
|
+ List<PdfDto> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
|
|
|
|
+ List<PdfDto> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
|
|
|
|
+ List<PdfDto> paperPdfList = new ArrayList<>();//所有试卷
|
|
|
|
+ List<PdfDto> examStudentPdfList = new ArrayList<>();//所有题卡
|
|
|
|
+ List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
|
|
|
|
+ List<PdfDto> cardPdfList = new ArrayList<>();//备份题卡
|
|
|
|
|
|
if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
|
|
if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
|
|
//获取普通印品
|
|
//获取普通印品
|
|
@@ -215,15 +215,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
|
|
JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
|
|
Long attachmentId = (Long) jsonObjectOrdinary.get("attachmentId");
|
|
Long attachmentId = (Long) jsonObjectOrdinary.get("attachmentId");
|
|
BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
|
|
BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
|
|
- createCheckIn(basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
|
|
|
|
|
|
+ createPdfUtil.createCheckIn(basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
- List<String> paperPdfTempList = new ArrayList<>();//所有试卷
|
|
|
|
- List<String> examStudentTempPdfList = new ArrayList<>();//所有题卡
|
|
|
|
- List<String> backupPaperTempPdfList = new ArrayList<>();//备份试卷
|
|
|
|
- List<String> cardPdfTempList = new ArrayList<>();//备份题卡
|
|
|
|
|
|
+ List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
|
|
|
|
+ List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
|
|
|
|
+ List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
|
|
|
|
+ List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
|
|
|
|
|
|
//查询试卷
|
|
//查询试卷
|
|
QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
@@ -256,23 +256,23 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
|
|
|
|
//抽取卷型
|
|
//抽取卷型
|
|
- String paperType = getPaperType(examPrintPlan, examTaskDetail);
|
|
|
|
|
|
+ String paperType = createPdfUtil.getPaperType(examPrintPlan, examTaskDetail);
|
|
|
|
|
|
//获取试卷pdf
|
|
//获取试卷pdf
|
|
- getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
|
|
|
|
|
|
+ createPdfUtil.getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
|
|
paperPdfList.addAll(paperPdfTempList);
|
|
paperPdfList.addAll(paperPdfTempList);
|
|
backupPaperPdfList.addAll(backupPaperTempPdfList);
|
|
backupPaperPdfList.addAll(backupPaperTempPdfList);
|
|
|
|
|
|
basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
|
|
basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
|
|
for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
- getCardAttachmentId(examCardDetail, attachmentIds);
|
|
|
|
|
|
+ createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
|
|
|
|
|
|
//把模板页面上的 ${} 替换成实际内容
|
|
//把模板页面上的 ${} 替换成实际内容
|
|
- String cardContent = replaceHtmlTemplete(examCardDetail);
|
|
|
|
|
|
+ String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
|
|
String studentContent = cardContent;
|
|
String studentContent = cardContent;
|
|
|
|
|
|
for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
|
|
for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
|
|
- basicAttachmentList.add(cardHtml(cardContent, paperType, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList));
|
|
|
|
|
|
+ basicAttachmentList.add(createPdfUtil.cardHtml(cardContent, paperType, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList));
|
|
}
|
|
}
|
|
cardPdfList.addAll(cardPdfTempList);
|
|
cardPdfList.addAll(cardPdfTempList);
|
|
|
|
|
|
@@ -292,15 +292,15 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
|
|
BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
|
|
ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
|
|
ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
|
|
if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
|
|
if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
|
|
- createSignBook(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
|
|
|
|
|
|
+ createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
|
|
} else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAG")) {//卷袋贴
|
|
} else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAG")) {//卷袋贴
|
|
- createPaperPackage(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
|
|
|
|
|
|
+ createPdfUtil.createPaperPackage(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for (ExamStudent t : examStudentList) {
|
|
for (ExamStudent t : examStudentList) {
|
|
- basicAttachmentList.add(examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
|
|
|
|
|
|
+ basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
|
|
}
|
|
}
|
|
examStudentPdfList.addAll(examStudentTempPdfList);
|
|
examStudentPdfList.addAll(examStudentTempPdfList);
|
|
examStudentService.saveOrUpdateBatch(examStudentList);
|
|
examStudentService.saveOrUpdateBatch(examStudentList);
|
|
@@ -313,18 +313,18 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
Integer paperPageA3 = 0;
|
|
Integer paperPageA3 = 0;
|
|
Integer cardPageA3 = 0;
|
|
Integer cardPageA3 = 0;
|
|
- paperPageA3 = paperPageA3 + paperPdfTempList.size() + backupPaperTempPdfList.size();
|
|
|
|
- cardPageA3 = cardPageA3 + examStudentTempPdfList.size() + cardPdfTempList.size();
|
|
|
|
|
|
+ paperPageA3 = paperPageA3 + paperPdfTempList.stream().mapToInt(PdfDto::getPageCount).sum() + backupPaperTempPdfList.stream().mapToInt(PdfDto::getPageCount).sum();
|
|
|
|
+ cardPageA3 = cardPageA3 + examStudentTempPdfList.stream().mapToInt(PdfDto::getPageCount).sum() + cardPdfTempList.stream().mapToInt(PdfDto::getPageCount).sum();
|
|
examDetailCourse.setPaperPagesA3(paperPageA3);
|
|
examDetailCourse.setPaperPagesA3(paperPageA3);
|
|
examDetailCourse.setCardPagesA3(cardPageA3);
|
|
examDetailCourse.setCardPagesA3(cardPageA3);
|
|
}
|
|
}
|
|
detailCourseService.saveOrUpdateBatch(examDetailCourseList);
|
|
detailCourseService.saveOrUpdateBatch(examDetailCourseList);
|
|
//合并pdf
|
|
//合并pdf
|
|
- basicAttachmentList.add(mergePdf(tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
|
|
|
|
|
|
+ basicAttachmentList.add(createPdfUtil.mergePdf(tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
|
|
}
|
|
}
|
|
map.computeIfAbsent("size", v -> examDetailList.size());
|
|
map.computeIfAbsent("size", v -> examDetailList.size());
|
|
//最后一步删除附件
|
|
//最后一步删除附件
|
|
- deleteAttachment(attachmentIds, ftlList);
|
|
|
|
|
|
+ createPdfUtil.deleteAttachment(attachmentIds, ftlList);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("请求出错", e);
|
|
log.error("请求出错", e);
|
|
basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
|
|
basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
|
|
@@ -415,7 +415,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
|
|
|
|
PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
|
|
PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
|
|
- if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus){
|
|
|
|
|
|
+ if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus) {
|
|
throw ExceptionResultEnum.ERROR.exception(printPlanStatus + "状态下的印刷计划不允许导入");
|
|
throw ExceptionResultEnum.ERROR.exception(printPlanStatus + "状态下的印刷计划不允许导入");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -529,10 +529,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 校验课程信息
|
|
// 校验课程信息
|
|
- basicCourseService.verifyCourseInfo(schoolId,courseCode,courseName,userId);
|
|
|
|
|
|
+ basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
|
|
|
|
|
|
// 解析时间
|
|
// 解析时间
|
|
- Map<String,Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examDate,examTime);
|
|
|
|
|
|
+ Map<String, Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examDate, examTime);
|
|
String examStartTime = String.valueOf(timeMap.get("startTime"));
|
|
String examStartTime = String.valueOf(timeMap.get("startTime"));
|
|
String examEndTime = String.valueOf(timeMap.get("endTime"));
|
|
String examEndTime = String.valueOf(timeMap.get("endTime"));
|
|
|
|
|
|
@@ -572,386 +572,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
return Stream.of(tmp);
|
|
return Stream.of(tmp);
|
|
}).distinct().collect(Collectors.toList());
|
|
}).distinct().collect(Collectors.toList());
|
|
for (Map<String, Object> stringObjectMap : checkList) {
|
|
for (Map<String, Object> stringObjectMap : checkList) {
|
|
- Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
|
|
|
|
- String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
|
|
|
|
- String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
|
|
|
|
- commonService.checkData(checkSchoolId,checkCourseCode,checkPaperNumber);
|
|
|
|
|
|
+ Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
|
|
|
|
+ String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
|
|
|
|
+ String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
|
|
|
|
+ commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber);
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 创建登记表
|
|
|
|
- *
|
|
|
|
- * @param basicAttachment
|
|
|
|
- * @param ordinaryPdfList
|
|
|
|
- * @param printCount
|
|
|
|
- */
|
|
|
|
- private void createCheckIn(BasicAttachment basicAttachment, List<String> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
|
|
|
|
- String type = basicAttachment.getType();
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
|
|
- if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.PDF_PREFIX)) {
|
|
|
|
- String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
|
- String url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
|
|
|
|
- File localFile = ossUtil.ossDownload(filePath, url);
|
|
|
|
- for (int i = 0; i < printCount; i++) {
|
|
|
|
- ordinaryPdfList.add(localFile.getPath());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 生成卷袋贴
|
|
|
|
- *
|
|
|
|
- * @param basicAttachment
|
|
|
|
- * @param schoolName
|
|
|
|
- * @param examDetailCourse
|
|
|
|
- * @param examStudentList
|
|
|
|
- * @param variablePdfList
|
|
|
|
- * @param printCount
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- private void createPaperPackage(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<String> variablePdfList, Integer printCount) throws IOException {
|
|
|
|
- Map<String, Object> htmlMap = new HashMap<>();
|
|
|
|
- htmlMap.put("examDetailCourseId", examDetailCourse.getId());
|
|
|
|
- htmlMap.put("schoolName", schoolName);
|
|
|
|
- htmlMap.put("examName", "测试exam1");
|
|
|
|
- htmlMap.put("courseName", examDetailCourse.getCourseName());
|
|
|
|
- htmlMap.put("courseCode", examDetailCourse.getCourseCode());
|
|
|
|
- htmlMap.put("examSite", "测试examSite1");
|
|
|
|
- htmlMap.put("examRoom", "测试examRoom1");
|
|
|
|
- htmlMap.put("startTime", "2021-04-13 00:00:00");
|
|
|
|
- htmlMap.put("endTime", "2021-04-14 00:00:00");
|
|
|
|
- htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
|
|
|
|
- htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
|
|
|
|
-
|
|
|
|
- htmlMap.put("startCollege", "测试startCollege1");
|
|
|
|
- htmlMap.put("className", "测试className1");
|
|
|
|
- htmlMap.put("proctorCollege", "测试proctorCollege1");
|
|
|
|
- htmlMap.put("examManager", "测试examManager1");
|
|
|
|
-
|
|
|
|
- htmlMap.put("minSite", "测试minSite1");
|
|
|
|
- htmlMap.put("maxSite", "测试maxSite1");
|
|
|
|
- htmlMap.put("studentCount", examStudentList.size());
|
|
|
|
-
|
|
|
|
- htmlMap.put("tag", "测试tag1");
|
|
|
|
-
|
|
|
|
- htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
|
|
|
|
- htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
|
|
- htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
|
|
- freemarkerUtil.createPaperPackage(htmlMap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 创建签到表
|
|
|
|
- *
|
|
|
|
- * @param basicAttachment
|
|
|
|
- * @param schoolName
|
|
|
|
- * @param examDetailCourse
|
|
|
|
- * @param examStudentList
|
|
|
|
- * @param variablePdfList
|
|
|
|
- * @param printCount
|
|
|
|
- */
|
|
|
|
- private void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<String> variablePdfList, Integer printCount) throws IOException {
|
|
|
|
- Map<String, Object> htmlMap = new HashMap<>();
|
|
|
|
- htmlMap.put("examDetailCourseId", examDetailCourse.getId());
|
|
|
|
- htmlMap.put("schoolName", schoolName);
|
|
|
|
- htmlMap.put("courseName", examDetailCourse.getCourseName());
|
|
|
|
- htmlMap.put("courseCode", examDetailCourse.getCourseCode());
|
|
|
|
- htmlMap.put("examName", "测试exam1");
|
|
|
|
- htmlMap.put("examRoom", "测试examRoom1");
|
|
|
|
- htmlMap.put("classTeacher", "测试老师1");
|
|
|
|
- htmlMap.put("startTime", "2021-04-13 00:00:00");
|
|
|
|
- htmlMap.put("endTime", "2021-04-14 00:00:00");
|
|
|
|
- htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
|
|
|
|
- htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
|
|
|
|
-
|
|
|
|
- int totalCount = examStudentList.size();
|
|
|
|
- if (totalCount > 0) {
|
|
|
|
- List<Map> subList = new ArrayList<>();
|
|
|
|
- int pageCount = totalCount % 80 == 0 ? totalCount / 80 : totalCount / 80 + 1;
|
|
|
|
- for (int i = 0; i < pageCount; i++) {
|
|
|
|
- Map subMap = new HashMap();
|
|
|
|
- subMap.put("index", i + 1);
|
|
|
|
- int studentCount;
|
|
|
|
- List<ExamStudent> subStudents;
|
|
|
|
- if (pageCount == 1) {
|
|
|
|
- studentCount = totalCount;
|
|
|
|
- subStudents = examStudentList;
|
|
|
|
- } else if (pageCount > 1 && i == pageCount - 1) {
|
|
|
|
- studentCount = totalCount - (pageCount - 1) * 80;
|
|
|
|
- subStudents = examStudentList.subList(80 * i, examStudentList.size());
|
|
|
|
- } else {
|
|
|
|
- studentCount = 80;
|
|
|
|
- subStudents = examStudentList.subList(80 * i, 80 * (i + 1));
|
|
|
|
- }
|
|
|
|
- subMap.put("studentCount", studentCount);
|
|
|
|
- List<ExamStudentDto> examStudentList1 = new ArrayList<>();
|
|
|
|
- List<ExamStudentDto> examStudentList2 = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- Gson gson = new Gson();
|
|
|
|
- int mod = subStudents.size() % 2;
|
|
|
|
- int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
|
|
|
|
- for (int j = 0; j < htmlTableCount; j++) {
|
|
|
|
- ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
|
|
|
|
- examStudentDto.setIndex(j + 1);
|
|
|
|
- examStudentList1.add(examStudentDto);
|
|
|
|
- }
|
|
|
|
- for (int j = htmlTableCount; j < subStudents.size(); j++) {
|
|
|
|
- ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
|
|
|
|
- examStudentDto.setIndex(j + 1);
|
|
|
|
- examStudentList2.add(examStudentDto);
|
|
|
|
- }
|
|
|
|
- if (examStudentList1.size() > examStudentList2.size()) {
|
|
|
|
- for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
|
|
|
|
- examStudentList2.add(new ExamStudentDto());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- subMap.put("studentList1", examStudentList1);
|
|
|
|
- subMap.put("studentList2", examStudentList2);
|
|
|
|
- subList.add(subMap);
|
|
|
|
- }
|
|
|
|
- htmlMap.put("subList", subList);
|
|
|
|
- }
|
|
|
|
- htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
|
|
|
|
- htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
|
|
- htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
|
|
- freemarkerUtil.createSignBook(htmlMap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 替换html通用模版
|
|
|
|
- *
|
|
|
|
- * @param examCardDetail
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public String replaceHtmlTemplete(ExamCardDetail examCardDetail) {
|
|
|
|
- String content = examCardDetail.getHtmlContent();
|
|
|
|
- log.info("contentTemp:{}", content);
|
|
|
|
- content = content.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
|
|
|
|
- content = content.replaceAll("\\$\\{examNumberStr\\}", "");
|
|
|
|
- return content;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取题卡attachmentId
|
|
|
|
- *
|
|
|
|
- * @param examCardDetail
|
|
|
|
- * @param attachmentIds
|
|
|
|
- */
|
|
|
|
- public void getCardAttachmentId(ExamCardDetail examCardDetail, Set<Long> attachmentIds) {
|
|
|
|
- if (Objects.nonNull(examCardDetail.getAttachmentId())) {
|
|
|
|
- JSONObject jsonObjectCard = JSONObject.parseObject(examCardDetail.getAttachmentId());
|
|
|
|
- JSONArray jsonArrayCard = (JSONArray) jsonObjectCard.get("card");
|
|
|
|
- for (int i = 0; i < jsonArrayCard.size(); i++) {
|
|
|
|
- JSONObject object = (JSONObject) jsonArrayCard.get(i);
|
|
|
|
- if (Objects.nonNull(object.get("attachmentId"))) {
|
|
|
|
- attachmentIds.add(Long.parseLong(String.valueOf(object.get("attachmentId"))));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取试卷pdf
|
|
|
|
- *
|
|
|
|
- * @param examTaskDetail
|
|
|
|
- * @param backupCount
|
|
|
|
- * @param pdfList
|
|
|
|
- * @return
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- public void getPaperPdf(ExamTaskDetail examTaskDetail, Integer backupCount, List<String>... pdfList) throws IOException {
|
|
|
|
- JSONObject jsonObjectPaper = JSONObject.parseObject(examTaskDetail.getPaperAttachmentIds());
|
|
|
|
- JSONArray jsonArrayPaper = jsonObjectPaper.getJSONArray("paper");
|
|
|
|
- for (int i = 0; i < jsonArrayPaper.size(); i++) {
|
|
|
|
- JSONObject object = (JSONObject) jsonArrayPaper.get(i);
|
|
|
|
- if (Objects.nonNull(object.get("attachmentId"))) {
|
|
|
|
- Long attachmentId = Long.parseLong(String.valueOf(object.get("attachmentId")));
|
|
|
|
- BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
|
|
|
|
- String filePath = commonService.getFile(basicAttachment.getPath(), false).getPath();
|
|
|
|
- pdfList[0].add(filePath);
|
|
|
|
- for (int j = 1; j <= backupCount; j++) {
|
|
|
|
- pdfList[1].add(filePath);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 抽取试卷
|
|
|
|
- *
|
|
|
|
- * @param examPrintPlan
|
|
|
|
- * @param examTaskDetail
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail) {
|
|
|
|
- //抽取卷型
|
|
|
|
- DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
|
|
|
|
- //未曝光卷型
|
|
|
|
- String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
|
|
|
|
- //已曝光卷型
|
|
|
|
- String exposedPaperType = examTaskDetail.getExposedPaperType();
|
|
|
|
- String[] paperTypes = null;
|
|
|
|
- if (drawRule == DrawRuleEnum.ONE) {
|
|
|
|
- if (Objects.isNull(unexposedPaperType)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
- } else {
|
|
|
|
- paperTypes = unexposedPaperType.split("/");
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(unexposedPaperType)) {
|
|
|
|
- paperTypes = unexposedPaperType.split("/");
|
|
|
|
- } else {
|
|
|
|
- paperTypes = exposedPaperType.split("/");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- int paperRandom = new Random().nextInt(paperTypes.length);
|
|
|
|
- String paperType = paperTypes[paperRandom];
|
|
|
|
- examTaskDetail.setPaperType(paperType);
|
|
|
|
- return paperType;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 合并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<>();
|
|
|
|
- int pageA3Count = 0;
|
|
|
|
- int pageA4Count = 0;
|
|
|
|
- for (int i = 0; i < list.length; i++) {
|
|
|
|
- if (i < 2) {
|
|
|
|
- pageA4Count = pageA4Count + list[i].size();
|
|
|
|
- } else {
|
|
|
|
- pageA3Count = pageA3Count + list[i].size();
|
|
|
|
- }
|
|
|
|
- mergePdfList.addAll(list[i]);
|
|
|
|
- }
|
|
|
|
- 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());
|
|
|
|
- examDetail.setPagesA3(pageA3Count);
|
|
|
|
- examDetail.setPagesA4(pageA4Count);
|
|
|
|
- examDetail.setStatus(ExamDetailStatusEnum.READY);
|
|
|
|
- detailService.saveOrUpdate(examDetail);
|
|
|
|
- ossUtil.ossUpload(dirName, localPdfFile, DigestUtils.md5Hex(new FileInputStream(localPdfFile)));
|
|
|
|
- localPdfFile.delete();
|
|
|
|
- for (String s : mergePdfList) {
|
|
|
|
- new File(s).delete();
|
|
|
|
- }
|
|
|
|
- return basicAttachment;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 删除附件
|
|
|
|
- *
|
|
|
|
- * @param attachmentIds
|
|
|
|
- * @param ftlList
|
|
|
|
- */
|
|
|
|
- public void deleteAttachment(Set<Long> attachmentIds, Set<File> ftlList) {
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(ftlList) && ftlList.size() > 0) {
|
|
|
|
- for (File file : ftlList) {
|
|
|
|
- file.delete();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 考生题卡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 jsonArray
|
|
|
|
- * @param userId
|
|
|
|
- * @param cardPdfList
|
|
|
|
- * @return
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, 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("examDetailCourseId", examDetailCourse.getId());
|
|
|
|
- object.put("attachmentId", cardAttachment.getId());
|
|
|
|
- jsonArray.add(object);
|
|
|
|
- return cardAttachment;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|