|
@@ -19,7 +19,12 @@ import com.qmth.distributed.print.business.mapper.ExamCardMapper;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
|
|
|
-import com.qmth.teachcloud.common.util.HtmlToPdfUtil;
|
|
|
+import com.qmth.distributed.print.business.util.PdfUtil;
|
|
|
+import com.qmth.distributed.print.business.util.pdf.CreatePdfNewUtil;
|
|
|
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
|
|
|
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
+import com.qmth.teachcloud.common.service.*;
|
|
|
+import com.qmth.teachcloud.common.util.*;
|
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
|
import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
@@ -29,13 +34,6 @@ import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
|
-import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
|
-import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
-import com.qmth.teachcloud.common.service.BasicRoleDataPermissionService;
|
|
|
-import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
-import com.qmth.teachcloud.common.util.ConvertUtil;
|
|
|
-import com.qmth.teachcloud.common.util.ExamTaskUtil;
|
|
|
-import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -82,15 +80,16 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
|
|
|
@Resource
|
|
|
BasicCourseService basicCourseService;
|
|
|
-
|
|
|
@Resource
|
|
|
HtmlToJpgUtil htmlToJpgUtil;
|
|
|
-
|
|
|
@Resource
|
|
|
CreatePdfUtil createPdfUtil;
|
|
|
-
|
|
|
@Resource
|
|
|
BasicRoleDataPermissionService basicRoleDataPermissionService;
|
|
|
+ @Resource
|
|
|
+ CreatePdfNewUtil createPdfNewUtil;
|
|
|
+ @Resource
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
@@ -131,21 +130,6 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
examCard.setAttachmentId(examCardParams.getAttachmentId());
|
|
|
examCard.setCardRuleId(examCardParams.getCardRuleId());
|
|
|
examCard.insertInfo(user.getId());
|
|
|
-
|
|
|
- // 自动保存
|
|
|
- if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
|
|
|
- examCard.setContent(examCardParams.getContent());
|
|
|
- examCard.setStageContent(null);
|
|
|
- String htmlContent = examCardParams.getHtmlContent();
|
|
|
- List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), htmlContent, PageSizeEnum.A3);
|
|
|
- if (convertJpgStorageList.size() > 0) {
|
|
|
- examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
- }
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
- } else {
|
|
|
- examCard.setStageContent(examCardParams.getContent());
|
|
|
- }
|
|
|
- this.save(examCard);
|
|
|
}
|
|
|
// 修改
|
|
|
else {
|
|
@@ -164,20 +148,18 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
examCard.setStatus(examCardParams.getStatus());
|
|
|
examCard.setUpdateId(user.getId());
|
|
|
examCard.setUpdateTime(System.currentTimeMillis());
|
|
|
- if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
|
|
|
- examCard.setContent(examCardParams.getContent());
|
|
|
- examCard.setStageContent(null);
|
|
|
- String htmlContent = examCardParams.getHtmlContent();
|
|
|
- List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), htmlContent, PageSizeEnum.A3);
|
|
|
- if (convertJpgStorageList.size() > 0) {
|
|
|
- examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
- }
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
- } else {
|
|
|
- examCard.setStageContent(examCardParams.getContent());
|
|
|
- }
|
|
|
- this.updateById(examCard);
|
|
|
}
|
|
|
+
|
|
|
+ // 自动保存
|
|
|
+ if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
|
|
|
+ examCard.setContent(examCardParams.getContent());
|
|
|
+ examCard.setStageContent(null);
|
|
|
+ examCard.setHtmlContent(examCardParams.getHtmlContent());
|
|
|
+ createJpgImage(examCard);
|
|
|
+ } else {
|
|
|
+ examCard.setStageContent(examCardParams.getContent());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(examCard);
|
|
|
return String.valueOf(examCard.getId());
|
|
|
}
|
|
|
|
|
@@ -352,10 +334,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
}
|
|
|
if (CardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
|
// 生成题卡图片
|
|
|
- List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), examCard.getHtmlContent(), PageSizeEnum.A3);
|
|
|
- if (convertJpgStorageList.size() > 0) {
|
|
|
- examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
- }
|
|
|
+ createJpgImage(examCard);
|
|
|
}
|
|
|
this.saveOrUpdate(examCard);
|
|
|
return examCard.getId();
|
|
@@ -401,12 +380,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
copyExamCard.setRemark(String.format("来源题卡:%s(%s)", id, examCard.getTitle()));
|
|
|
copyExamCard.setUsed(false);
|
|
|
// 生成图片
|
|
|
- List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), copyExamCard.getHtmlContent(), PageSizeEnum.A3);
|
|
|
- if (!convertJpgStorageList.isEmpty()) {
|
|
|
- copyExamCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
- } else {
|
|
|
- copyExamCard.setJpgAttachment(null);
|
|
|
- }
|
|
|
+ createJpgImage(copyExamCard);
|
|
|
this.save(copyExamCard);
|
|
|
return copyExamCard.getId();
|
|
|
}
|
|
@@ -414,11 +388,11 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
@Override
|
|
|
public void convertImage(Long id) {
|
|
|
ExamCard examCard = this.getById(id);
|
|
|
- List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), examCard.getHtmlContent(), PageSizeEnum.A3);
|
|
|
- if (convertJpgStorageList.size() > 0) {
|
|
|
- String jpgAttachmentIds = JSON.toJSONString(convertJpgStorageList);
|
|
|
+ createJpgImage(examCard);
|
|
|
+ if (examCard.getJpgAttachment().length() > 0) {
|
|
|
UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(ExamCard::getJpgAttachment, jpgAttachmentIds)
|
|
|
+ updateWrapper.lambda().set(ExamCard::getBlankCardPath, examCard.getBlankCardPath())
|
|
|
+ .set(ExamCard::getJpgAttachment, examCard.getJpgAttachment())
|
|
|
.eq(ExamCard::getId, id);
|
|
|
this.update(updateWrapper);
|
|
|
}
|
|
@@ -622,4 +596,29 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamCard createJpgImage(ExamCard examCard) {
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(examCard.getCardRuleId());
|
|
|
+ String replaceBackupCardHtmlContent = createPdfNewUtil.replaceBackupCardHtmlParam(examCard.getHtmlContent(), null, basicCardRule, null);
|
|
|
+ File pdfFile = PdfUtil.htmlToPdf(replaceBackupCardHtmlContent);
|
|
|
+ try {
|
|
|
+ String fileName = PdfUtil.md5FileName("BLANK" + examCard.getId()) + SystemConstant.PDF_PREFIX;
|
|
|
+ FilePathVo filePathVo = fileUploadService.uploadFile(pdfFile, UploadFileEnum.PDF, fileName);
|
|
|
+ examCard.setBlankCardPath(JSON.toJSONString(filePathVo));
|
|
|
+ List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertPdfToJpg(examCard.getId(), pdfFile, examCard.getCreateId());
|
|
|
+ if (convertJpgStorageList.size() > 0) {
|
|
|
+ examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
+ } else {
|
|
|
+ examCard.setJpgAttachment(null);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ if (pdfFile.exists()) {
|
|
|
+ FileUtil.deleteFile(pdfFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return examCard;
|
|
|
+ }
|
|
|
}
|