|
@@ -2,21 +2,27 @@ package com.qmth.distributed.print.business.templete.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.aliyun.oss.common.utils.BinaryUtil;
|
|
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.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
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.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.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.GoogleBarCodeUtil;
|
|
import com.qmth.distributed.print.business.util.GoogleBarCodeUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.OssUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.PdfUtil;
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
import com.qmth.distributed.print.business.util.excel.ExcelError;
|
|
import com.qmth.distributed.print.business.util.excel.ExcelError;
|
|
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.Base64Util;
|
|
import com.qmth.distributed.print.common.util.Base64Util;
|
|
|
|
+import com.qmth.distributed.print.common.util.HexUtils;
|
|
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.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -24,7 +30,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -75,6 +85,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
@Resource
|
|
@Resource
|
|
BasicAttachmentService basicAttachmentService;
|
|
BasicAttachmentService basicAttachmentService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ OssUtil ossUtil;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 执行导入用户逻辑
|
|
* 执行导入用户逻辑
|
|
*
|
|
*
|
|
@@ -167,7 +180,11 @@ 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);
|
|
|
|
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
|
|
|
|
+ List<String> paperPdfList = new ArrayList<>();
|
|
|
|
+ List<String> cardPdfList = new ArrayList<>();
|
|
|
|
+ List<String> studentPdfList = new ArrayList<>();
|
|
//查询试卷
|
|
//查询试卷
|
|
QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
|
|
examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
|
|
examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
|
|
@@ -199,6 +216,16 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
|
|
|
|
|
|
String[] paperTypes = examTaskDetail.getPaperType().split("/");
|
|
String[] paperTypes = examTaskDetail.getPaperType().split("/");
|
|
|
|
+ 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);
|
|
|
|
+ paperPdfList.add(commonService.getFile(basicAttachment.getPath(), false));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
|
|
basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
|
|
for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
for (ExamCardDetail examCardDetail : examCardDetailList) {
|
|
if (Objects.nonNull(examCardDetail.getAttachmentId())) {
|
|
if (Objects.nonNull(examCardDetail.getAttachmentId())) {
|
|
@@ -207,7 +234,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
for (int i = 0; i < jsonArrayCard.size(); i++) {
|
|
for (int i = 0; i < jsonArrayCard.size(); i++) {
|
|
JSONObject object = (JSONObject) jsonArrayCard.get(i);
|
|
JSONObject object = (JSONObject) jsonArrayCard.get(i);
|
|
if (Objects.nonNull(object.get("attachmentId"))) {
|
|
if (Objects.nonNull(object.get("attachmentId"))) {
|
|
- attachmentIds.add((Long) object.get("attachmentId"));
|
|
|
|
|
|
+ attachmentIds.add(Long.parseLong(String.valueOf(object.get("attachmentId"))));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -232,7 +259,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
|
|
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>";
|
|
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);
|
|
cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
|
|
- BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, sysUser.getId());
|
|
|
|
|
|
+ BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, sysUser.getId(), cardPdfList);
|
|
JSONObject object = new JSONObject();
|
|
JSONObject object = new JSONObject();
|
|
object.put("name", paperType);
|
|
object.put("name", paperType);
|
|
object.put("examTaskDetailId", examTaskDetail.getId());
|
|
object.put("examTaskDetailId", examTaskDetail.getId());
|
|
@@ -248,10 +275,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
|
|
|
|
|
|
for (ExamStudent t : examStudentList) {
|
|
for (ExamStudent t : examStudentList) {
|
|
- if (Objects.nonNull(t.getAttachmentIds())) {
|
|
|
|
- JSONObject json = JSONObject.parseObject(t.getAttachmentIds());
|
|
|
|
- attachmentIds.add((Long) json.get("htmlAttachmentId"));
|
|
|
|
-// attachmentIds.add((Long) json.get("pdfAttachmentId"));
|
|
|
|
|
|
+ if (Objects.nonNull(t.getAttachmentId())) {
|
|
|
|
+ attachmentIds.add(t.getAttachmentId());
|
|
}
|
|
}
|
|
String studentHtml = studentContent;
|
|
String studentHtml = studentContent;
|
|
if (Objects.nonNull(t.getExtendFields())) {
|
|
if (Objects.nonNull(t.getExtendFields())) {
|
|
@@ -274,11 +299,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
|
|
studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
|
|
|
|
|
|
//学生题卡
|
|
//学生题卡
|
|
- BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, sysUser.getId());
|
|
|
|
- JSONObject jsonObjectExamStudent = new JSONObject();
|
|
|
|
- jsonObjectExamStudent.put("htmlAttachmentId", examStudentAttachment.getId());
|
|
|
|
- jsonObjectExamStudent.put("pdfAttachmentId", 123L);
|
|
|
|
- t.setAttachmentIds(jsonObjectExamStudent.toJSONString());
|
|
|
|
|
|
+ BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, sysUser.getId(), studentPdfList);
|
|
|
|
+ t.setAttachmentId(examStudentAttachment.getId());
|
|
basicAttachmentList.add(examStudentAttachment);
|
|
basicAttachmentList.add(examStudentAttachment);
|
|
}
|
|
}
|
|
examStudentService.saveOrUpdateBatch(examStudentList);
|
|
examStudentService.saveOrUpdateBatch(examStudentList);
|
|
@@ -287,6 +309,26 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
examCardDetail.setAttachmentId(jsonObject.toJSONString());
|
|
examCardDetail.setAttachmentId(jsonObject.toJSONString());
|
|
}
|
|
}
|
|
examCardDetailService.saveOrUpdateBatch(examCardDetailList);
|
|
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);
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//最后一步删除附件
|
|
//最后一步删除附件
|