|
@@ -18,10 +18,7 @@ import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.enums.*;
|
|
import com.qmth.distributed.print.business.enums.*;
|
|
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.ConvertUtil;
|
|
|
|
-import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
|
-import com.qmth.distributed.print.business.util.ExcelUtil;
|
|
|
|
-import com.qmth.distributed.print.business.util.OssUtil;
|
|
|
|
|
|
+import com.qmth.distributed.print.business.util.*;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
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.FileUtil;
|
|
import com.qmth.distributed.print.common.util.FileUtil;
|
|
@@ -963,115 +960,74 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
// 根文件路径
|
|
// 根文件路径
|
|
String zipLocalRootPath = SystemConstant.TEMP_FILES_DIR + File.separator + System.currentTimeMillis();
|
|
String zipLocalRootPath = SystemConstant.TEMP_FILES_DIR + File.separator + System.currentTimeMillis();
|
|
|
|
|
|
- List<ExamTask> examTasks = (List<ExamTask>) map.get("examTasks");
|
|
|
|
- for (ExamTask examTask : examTasks) {
|
|
|
|
- ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTask.getId());
|
|
|
|
|
|
+ List<ExamTaskDetailDto> examTasks = (List<ExamTaskDetailDto>) map.get("examTasks");
|
|
|
|
+ for (ExamTaskDetailDto examTask : examTasks) {
|
|
|
|
+ String courseCodeName = examTask.getCourseCode() + "(" + examTask.getCourseName() + ")";
|
|
|
|
+ ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(Long.valueOf(examTask.getId()));
|
|
|
|
|
|
// 试卷
|
|
// 试卷
|
|
|
|
+ String paperSavePath = zipLocalRootPath + File.separator + "试卷";
|
|
String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
|
|
String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
|
|
-
|
|
|
|
- // 题卡
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Long[] ids = (Long[]) map.get("ids");
|
|
|
|
- for (Long id : ids) {
|
|
|
|
- ExamTask examTask = examTaskService.getById(id);
|
|
|
|
- if (Objects.isNull(examTask)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到命题任务");
|
|
|
|
- }
|
|
|
|
- String examTaskSign = examTask.getCourseName() + "-" + examTask.getPaperNumber();
|
|
|
|
- String firstPath = zipLocalRootPath + File.separator + examTaskSign;
|
|
|
|
- ReviewSampleDto reviewSampleDto = examTaskService.findReviewSampleInfoByExamTaskId(id);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 处理试卷样品
|
|
|
|
- List<Map> paperInfo = JSONObject.parseArray(reviewSampleDto.getPaperAttachmentIds(), Map.class);
|
|
|
|
- if (Objects.isNull(paperInfo)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
|
|
|
|
- }
|
|
|
|
- Set<Long> attPaperIds = new HashSet<>();
|
|
|
|
- for (Map paperMap : paperInfo) {
|
|
|
|
- if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
|
|
|
|
- Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
|
|
|
|
- attPaperIds.add(attachmentId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (attPaperIds.size() > 0) {
|
|
|
|
- List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
|
|
|
|
- for (BasicAttachment paperAttachment : paperAttachmentList) {
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(paperAttachment.getPath());
|
|
|
|
- String paperPath = firstPath + File.separator + "试卷" + File.separator + paperAttachment.getName() + paperAttachment.getType();
|
|
|
|
- ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(paperAttachmentIds)) {
|
|
|
|
+ List<Map> paperInfo = JSONObject.parseArray(paperAttachmentIds, Map.class);
|
|
|
|
+ if (Objects.isNull(paperInfo)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- // 处理审核样品
|
|
|
|
- List<Map> confirmInfo = JSONObject.parseArray(reviewSampleDto.getPaperConfirmAttachmentIds(), Map.class);
|
|
|
|
- System.out.println("confirmInfo = " + JSON.toJSONString(confirmInfo));
|
|
|
|
- Set<Long> attConfirmIds = new HashSet<>();
|
|
|
|
- for (Map confirmMap : confirmInfo) {
|
|
|
|
- if (Objects.isNull(confirmMap.get("attachmentId"))) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到附件id");
|
|
|
|
- }
|
|
|
|
- Long attachmentId = Long.valueOf(String.valueOf(confirmMap.get("attachmentId")));
|
|
|
|
- attConfirmIds.add(attachmentId);
|
|
|
|
- }
|
|
|
|
- if (attConfirmIds.size() > 0) {
|
|
|
|
- List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
|
|
|
|
- for (BasicAttachment confirmAttachment : confirmAttachmentList) {
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(confirmAttachment.getPath());
|
|
|
|
- String confirmPath = firstPath + File.separator + "审核样本" + File.separator + confirmAttachment.getName() + confirmAttachment.getType();
|
|
|
|
- ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath);
|
|
|
|
|
|
+ for (Map paperMap : paperInfo) {
|
|
|
|
+ if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
|
|
|
|
+ String name = paperMap.get("name").toString();
|
|
|
|
+ Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
|
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
|
+ if (Objects.nonNull(attachment)) {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
|
|
|
|
+ String paperPath = paperSavePath + File.separator + courseCodeName + File.separator + examTask.getPaperNumber() + File.separator + attachment.getName() + attachment.getType();
|
|
|
|
+ ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 题卡
|
|
|
|
+ String cardSavePath = zipLocalRootPath + File.separator + "题卡";
|
|
// 处理题卡
|
|
// 处理题卡
|
|
- Long cardId = reviewSampleDto.getCardId();
|
|
|
|
- ExamCard examCard = examCardService.getById(cardId);
|
|
|
|
|
|
+ ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
|
|
if (Objects.isNull(examCard)) {
|
|
if (Objects.isNull(examCard)) {
|
|
throw ExceptionResultEnum.ERROR.exception("找不到答题卡");
|
|
throw ExceptionResultEnum.ERROR.exception("找不到答题卡");
|
|
}
|
|
}
|
|
MakeMethodEnum makeMethodEnum = examCard.getMakeMethod();
|
|
MakeMethodEnum makeMethodEnum = examCard.getMakeMethod();
|
|
|
|
+
|
|
|
|
+ String cardPath = cardSavePath + File.separator + courseCodeName + File.separator + examTask.getPaperNumber();
|
|
|
|
+ String cardHtmlPath = cardPath + File.separator + examCard.getTitle() + SystemConstant.HTML_PREFIX;
|
|
|
|
+ String cardPdfPath = cardPath + File.separator + examCard.getTitle() + SystemConstant.PDF_PREFIX;
|
|
|
|
+ // 通用题卡
|
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
|
|
|
|
+ String htmlContent;
|
|
if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
|
|
if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
|
|
- Long templateId = examCard.getTemplateId();
|
|
|
|
- if (templateId == null || templateId == 0) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("找不到题卡对应的模板");
|
|
|
|
- }
|
|
|
|
- BasicTemplate basicTemplate = basicTemplateService.getById(templateId);
|
|
|
|
- if (Objects.isNull(basicTemplate)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("找不到模板信息");
|
|
|
|
- }
|
|
|
|
- Long attachmentId = basicTemplate.getAttachmentId();
|
|
|
|
- if (attachmentId == null || attachmentId == 0) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("找不到模板对应的附件");
|
|
|
|
- }
|
|
|
|
- BasicAttachment cardAttachment = basicAttachmentService.getById(attachmentId);
|
|
|
|
- if (Objects.isNull(cardAttachment)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("找不到附件");
|
|
|
|
- }
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
|
|
|
|
- String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
|
|
|
|
- ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
|
|
|
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
|
|
} else {
|
|
} else {
|
|
- List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
|
|
|
|
- if (examCardDetailList.size() != 1) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("题卡明细信息异常");
|
|
|
|
- }
|
|
|
|
- ExamCardDetail examCardDetail = examCardDetailService.getByCardId(cardId);
|
|
|
|
- String htmlContent = examCardDetail.getHtmlContent();
|
|
|
|
- byte[] bytes = htmlContent.getBytes();
|
|
|
|
- String cardPath = firstPath + File.separator + "题卡" + File.separator + examCard.getTitle() + SystemConstant.HTML_PREFIX;
|
|
|
|
- File localFile = new File(cardPath);
|
|
|
|
- if (!localFile.getParentFile().exists()) {
|
|
|
|
- localFile.getParentFile().mkdirs();
|
|
|
|
- }
|
|
|
|
- FileCopyUtils.copy(bytes, localFile);
|
|
|
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
|
+ }
|
|
|
|
+ // html
|
|
|
|
+ File localFile = new File(cardHtmlPath);
|
|
|
|
+ if (!localFile.getParentFile().exists()) {
|
|
|
|
+ localFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
|
|
+ // 生成html文件
|
|
|
|
+ FileCopyUtils.copy(htmlContent.getBytes(), localFile);
|
|
|
|
+ // 转pdf文件
|
|
|
|
+ File file = new File(cardPdfPath);
|
|
|
|
+ if(!file.exists()){
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
}
|
|
}
|
|
|
|
|
|
File zipFile = new File(zipJoiner.toString() + dirNameTmp);
|
|
File zipFile = new File(zipJoiner.toString() + dirNameTmp);
|
|
if (!zipFile.getParentFile().exists()) {
|
|
if (!zipFile.getParentFile().exists()) {
|
|
zipFile.getParentFile().mkdirs();
|
|
zipFile.getParentFile().mkdirs();
|
|
|
|
+ }
|
|
|
|
+ if(!zipFile.exists()){
|
|
zipFile.createNewFile();
|
|
zipFile.createNewFile();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1084,6 +1040,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
ConvertUtil.delFolder(zipLocalRootPath);
|
|
ConvertUtil.delFolder(zipLocalRootPath);
|
|
zipFile.delete();
|
|
zipFile.delete();
|
|
|
|
+ map.put("count", 1);
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
}
|
|
}
|