|
@@ -1,5 +1,6 @@
|
|
package com.qmth.distributed.print.business.templete.service.impl;
|
|
package com.qmth.distributed.print.business.templete.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -13,6 +14,7 @@ import com.qmth.distributed.print.business.bean.params.ArraysParams;
|
|
import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
|
|
import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
|
|
|
|
+import com.qmth.distributed.print.business.enums.MakeMethodEnum;
|
|
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
@@ -39,6 +41,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
|
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
@@ -103,6 +106,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
@Resource
|
|
@Resource
|
|
CreatePdfUtil createPdfUtil;
|
|
CreatePdfUtil createPdfUtil;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ BasicTemplateService basicTemplateService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
RedisTemplate<String, Object> redisTemplate;
|
|
RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
@@ -597,4 +603,142 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws IOException {
|
|
|
|
+ int count = 0;
|
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner zipJoiner = new StringJoiner("")
|
|
|
|
+ .add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
|
+ StringJoiner dirName = new StringJoiner("")
|
|
|
|
+ .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.ZIP_PREFIX);
|
|
|
|
+ String dirNameTmp = dirName.toString().replaceAll("\\\\", "/");
|
|
|
|
+ File zipFile = new File(zipJoiner.toString() + dirNameTmp);
|
|
|
|
+ if (!zipFile.getParentFile().exists()) {
|
|
|
|
+ zipFile.getParentFile().mkdirs();
|
|
|
|
+ zipFile.createNewFile();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 跟文件路径
|
|
|
|
+ String zipLocalRootPath = SystemConstant.TEMP_FILES_DIR + File.separator + System.currentTimeMillis();
|
|
|
|
+ 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.getSchoolId() + "-" + examTask.getCourseName() + "-" + examTask.getPaperNumber();
|
|
|
|
+ String firstPath = zipLocalRootPath + File.separator + examTaskSign;
|
|
|
|
+ List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(new QueryWrapper<ExamTaskDetail>().lambda().eq(ExamTaskDetail::getExamTaskId,id));
|
|
|
|
+ if (examTaskDetailList.size() != 1){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("获取命题任务详情失败 命题任务id : " + id);
|
|
|
|
+ }
|
|
|
|
+ ExamTaskDetail examTaskDetail = examTaskDetailList.get(0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 处理试卷样品
|
|
|
|
+ List<Map> paperInfo = JSONObject.parseArray(examTaskDetail.getPaperAttachmentIds(), Map.class);
|
|
|
|
+ System.out.println("paperInfo = " + JSON.toJSONString(paperInfo));
|
|
|
|
+ Set<Long> attPaperIds = new HashSet<>();
|
|
|
|
+ for (Map paperMap : paperInfo) {
|
|
|
|
+ if (Objects.isNull(paperMap.get("attachmentId"))){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到附件id");
|
|
|
|
+ }
|
|
|
|
+ Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
|
|
|
|
+ attPaperIds.add(attachmentId);
|
|
|
|
+ }
|
|
|
|
+ List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
|
|
|
|
+ if (Objects.nonNull(paperAttachmentList)){
|
|
|
|
+ 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("path"), paperPath);
|
|
|
|
+ count ++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理审核样品
|
|
|
|
+ List<Map> confirmInfo = JSONObject.parseArray(examTaskDetail.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);
|
|
|
|
+ }
|
|
|
|
+ List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
|
|
|
|
+ if (Objects.nonNull(confirmAttachmentList)){
|
|
|
|
+ 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("path"), confirmPath);
|
|
|
|
+ count ++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理题卡
|
|
|
|
+ Long cardId = examTaskDetail.getCardId();
|
|
|
|
+ ExamCard examCard = examCardService.getById(cardId);
|
|
|
|
+ if (Objects.isNull(examCard)){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到答题卡 cardId = " + cardId);
|
|
|
|
+ }
|
|
|
|
+ MakeMethodEnum makeMethodEnum = examCard.getMakeMethod();
|
|
|
|
+ if (MakeMethodEnum.SELECT.equals(makeMethodEnum)){
|
|
|
|
+ Long templateId = examCard.getTemplateId();
|
|
|
|
+ if (templateId == null || templateId == 0){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到题卡对应的模板 templateId = " + templateId);
|
|
|
|
+ }
|
|
|
|
+ BasicTemplate basicTemplate = basicTemplateService.getById(templateId);
|
|
|
|
+ if (Objects.isNull(basicTemplate)){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到模板信息 templateId = " + templateId);
|
|
|
|
+ }
|
|
|
|
+ Long attachmentId = basicTemplate.getAttachmentId();
|
|
|
|
+ if (attachmentId == null || attachmentId == 0){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到模板对应的附件 templateId = " + templateId);
|
|
|
|
+ }
|
|
|
|
+ BasicAttachment cardAttachment = basicAttachmentService.getById(attachmentId);
|
|
|
|
+ if (Objects.isNull(cardAttachment)){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到附件 attachmentId = " + attachmentId);
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
|
|
|
|
+ String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
|
|
|
|
+ ossUtil.ossDownload((String) jsonObject.get("path"), cardPath);
|
|
|
|
+ count ++;
|
|
|
|
+ }else {
|
|
|
|
+ List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId,cardId));
|
|
|
|
+ if (examCardDetailList.size() != 1){
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡明细信息异常 card_id = " + cardId);
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ count ++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), true);
|
|
|
|
+ ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirNameTmp);
|
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
|
+ tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
|
+ ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
|
+ zipFile.delete();
|
|
|
|
+ map.put("count",count);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
}
|
|
}
|