|
@@ -1,28 +1,31 @@
|
|
|
package com.qmth.distributed.print.business.templete.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.gson.Gson;
|
|
|
+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.ExamCardStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.templete.service.TaskLogicService;
|
|
|
+import com.qmth.distributed.print.business.util.GoogleBarCodeUtil;
|
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
|
import com.qmth.distributed.print.business.util.excel.ExcelError;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.distributed.print.common.util.Base64Util;
|
|
|
+import com.qmth.distributed.print.common.util.ResultUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -34,6 +37,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TaskLogicServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
|
SysUserService sysUserService;
|
|
@@ -68,6 +72,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
@Resource
|
|
|
ExamStudentService examStudentService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
/**
|
|
|
* 执行导入用户逻辑
|
|
|
*
|
|
@@ -127,71 +134,172 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Map<String, Object> executeCreatePdfLogic(Map<String, Object> map) {
|
|
|
- TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
- SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
- //查询printPlan
|
|
|
- ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
|
|
|
- if (Objects.isNull(examPrintPlan)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("印刷计划为空");
|
|
|
- }
|
|
|
-
|
|
|
- //查询examDetail
|
|
|
- QueryWrapper<ExamDetail> examDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- examDetailQueryWrapper.lambda().eq(ExamDetail::getSchoolId, sysUser.getSchoolId())
|
|
|
- .eq(ExamDetail::getPrintPlanId, tbTask.getPrintPlanId());
|
|
|
- ExamDetail examDetail = detailService.getOne(examDetailQueryWrapper);
|
|
|
- if (Objects.isNull(examDetail)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("考务计划为空");
|
|
|
- }
|
|
|
+ public Map<String, Object> executeCreatePdfLogic(Map<String, Object> map) throws IOException {
|
|
|
+ List<BasicAttachment> basicAttachmentList = null;
|
|
|
+ try {
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
+ SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ //这里为保存附件html的逻辑
|
|
|
+ //查询题卡详情是否有附件id,有的话则把以前的附件删除
|
|
|
+ Set<Long> attachmentIds = null;
|
|
|
|
|
|
- //查询examDetailCourse
|
|
|
- QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
|
|
|
- examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
|
|
|
- List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
|
|
|
-
|
|
|
- for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
|
- //查询试卷
|
|
|
- QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
|
- examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
|
|
|
- .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
|
|
|
- .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
|
|
|
- .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
|
|
|
- .eq(ExamTask::getEnable, true)
|
|
|
- .eq(ExamTask::getStatus, ExamStatusEnum.FINISH);
|
|
|
- List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
|
|
|
- if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("命题任务为空");
|
|
|
+ //查询printPlan
|
|
|
+ ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
|
|
|
+ if (Objects.isNull(examPrintPlan)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划为空");
|
|
|
}
|
|
|
- Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
|
|
|
-
|
|
|
- QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
|
|
|
- .eq(ExamTaskDetail::getEnable, true);
|
|
|
- List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
|
|
|
- Set<Long> examTaskDetailIds = examTaskDetailList.stream().map(s -> s.getId()).collect(Collectors.toSet());
|
|
|
-
|
|
|
- //查询题卡
|
|
|
- QueryWrapper<ExamCard> examCardQueryWrapper = new QueryWrapper<>();
|
|
|
- examCardQueryWrapper.lambda().eq(ExamCard::getSchoolId, sysUser.getSchoolId())
|
|
|
- .eq(ExamCard::getCourseCode, examDetailCourse.getCourseCode())
|
|
|
- .eq(ExamCard::getCourseName, examDetailCourse.getCourseName())
|
|
|
- .eq(ExamCard::getStatus, ExamCardStatusEnum.SUBMIT);
|
|
|
- List<ExamCard> examCardList = examCardService.list(examCardQueryWrapper);
|
|
|
- if (Objects.isNull(examCardList) || examCardList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("题卡为空");
|
|
|
+
|
|
|
+ //查询examDetail
|
|
|
+ QueryWrapper<ExamDetail> examDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ examDetailQueryWrapper.lambda().eq(ExamDetail::getSchoolId, sysUser.getSchoolId())
|
|
|
+ .eq(ExamDetail::getPrintPlanId, tbTask.getPrintPlanId());
|
|
|
+ ExamDetail examDetail = detailService.getOne(examDetailQueryWrapper);
|
|
|
+ if (Objects.isNull(examDetail)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考务计划为空");
|
|
|
}
|
|
|
- Set<Long> examCardIds = examCardList.stream().map(s -> s.getId()).collect(Collectors.toSet());
|
|
|
+ attachmentIds = Objects.isNull(attachmentIds) ? attachmentIds = new HashSet<>() : attachmentIds;
|
|
|
+ attachmentIds.add(examDetail.getAttachmentId());
|
|
|
+
|
|
|
+ //查询examDetailCourse
|
|
|
+ QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
|
|
|
+ examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
|
|
|
+ List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
|
|
|
+
|
|
|
+ for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
|
+ //查询试卷
|
|
|
+ QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
|
+ examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
|
|
|
+ .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
|
|
|
+ .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
|
|
|
+ .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
|
|
|
+ .eq(ExamTask::getEnable, true)
|
|
|
+ .eq(ExamTask::getStatus, ExamStatusEnum.FINISH);
|
|
|
+ List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
|
|
|
+ if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("命题任务为空");
|
|
|
+ }
|
|
|
+ Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ 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) {
|
|
|
+ //查询题卡
|
|
|
+ ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
|
|
|
+ if (Objects.isNull(examCard)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡为空");
|
|
|
+ }
|
|
|
+ QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
|
|
|
+ List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
|
+
|
|
|
+ String[] paperTypes = examTaskDetail.getPaperType().split("/");
|
|
|
+ basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
|
|
|
+ for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
|
+ 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) object.get("attachmentId"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //把模板页面上的 ${} 替换成实际内容
|
|
|
+ String content = examCardDetail.getHtmlContent();
|
|
|
+ log.info("contentTemp:{}", content);
|
|
|
+ String cardContent = content;
|
|
|
+ String studentContent = content;
|
|
|
+ cardContent = cardContent.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
|
|
|
+ cardContent = cardContent.replaceAll("\\$\\{examNumberStr\\}", "");
|
|
|
+
|
|
|
+ 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, examCard.getSchoolId(), sysUser.getId());
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("name", paperType);
|
|
|
+ object.put("examTaskDetailId", examTaskDetail.getId());
|
|
|
+ object.put("attachmentId", cardAttachment.getId());
|
|
|
+ jsonArray.add(object);
|
|
|
+ basicAttachmentList.add(cardAttachment);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询考生
|
|
|
+ QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
|
|
|
+ examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
|
|
|
+ .eq(ExamStudent::getExamDetailCourseId, examTaskDetail.getId());
|
|
|
+ List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
|
|
|
|
- QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- examCardDetailQueryWrapper.lambda().in(ExamCardDetail::getCardId, examCardIds);
|
|
|
- List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
|
+ for (ExamStudent t : examStudentList) {
|
|
|
+// if (Objects.nonNull(t.getAttachmentIds())) {
|
|
|
+// 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());
|
|
|
|
|
|
- //查询考生
|
|
|
- QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
|
|
|
- examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
|
|
|
- .in(ExamStudent::getExamDetailCourseId, examTaskDetailIds);
|
|
|
- List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
|
+ //学生题卡
|
|
|
+ BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), studentHtml, examCard.getSchoolId(), sysUser.getId());
|
|
|
+ JSONObject jsonObjectExamStudent = new JSONObject();
|
|
|
+ jsonObjectExamStudent.put("htmlAttachmentId", examStudentAttachment.getId());
|
|
|
+ jsonObjectExamStudent.put("pdfAttachmentId", 123L);
|
|
|
+ t.setAttachmentIds(jsonObjectExamStudent.toJSONString());
|
|
|
+ basicAttachmentList.add(examStudentAttachment);
|
|
|
+ }
|
|
|
+ examStudentService.saveOrUpdateBatch(examStudentList);
|
|
|
+ }
|
|
|
+ jsonObject.put("card", jsonArray);
|
|
|
+ examCardDetail.setAttachmentId(jsonObject.toJSONString());
|
|
|
+ }
|
|
|
+ examCardDetailService.saveOrUpdateBatch(examCardDetailList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //最后一步删除附件
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("请求出错", e);
|
|
|
+ basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
return map;
|
|
|
}
|