|
@@ -1,10 +1,42 @@
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
|
|
+import com.qmth.distributed.print.business.bean.params.GenericExamCardModelFourParams;
|
|
|
|
+import com.qmth.distributed.print.business.entity.BasicCardRule;
|
|
import com.qmth.distributed.print.business.entity.ExamCardModelFour;
|
|
import com.qmth.distributed.print.business.entity.ExamCardModelFour;
|
|
|
|
+import com.qmth.distributed.print.business.enums.CardTypeEnum;
|
|
|
|
+import com.qmth.distributed.print.business.enums.ExamCardStatusEnum;
|
|
import com.qmth.distributed.print.business.mapper.ExamCardModelFourMapper;
|
|
import com.qmth.distributed.print.business.mapper.ExamCardModelFourMapper;
|
|
|
|
+import com.qmth.distributed.print.business.service.BasicCardRuleService;
|
|
import com.qmth.distributed.print.business.service.ExamCardModelFourService;
|
|
import com.qmth.distributed.print.business.service.ExamCardModelFourService;
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.PdfUtil;
|
|
|
|
+import com.qmth.teachcloud.common.bean.marking.ConvertJpgStorage;
|
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.teachcloud.common.entity.BasicCourse;
|
|
|
|
+import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
|
+import com.qmth.teachcloud.common.service.FileUploadService;
|
|
|
|
+import com.qmth.teachcloud.common.util.FileUtil;
|
|
|
|
+import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
|
+import com.qmth.teachcloud.mark.enums.LockType;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -17,4 +49,129 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class ExamCardModelFourServiceImpl extends ServiceImpl<ExamCardModelFourMapper, ExamCardModelFour> implements ExamCardModelFourService {
|
|
public class ExamCardModelFourServiceImpl extends ServiceImpl<ExamCardModelFourMapper, ExamCardModelFour> implements ExamCardModelFourService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ ConcurrentService concurrentService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ BasicCardRuleService basicCardRuleService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ BasicCourseService basicCourseService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ CreatePdfUtil createPdfUtil;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ FileUploadService fileUploadService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ HtmlToJpgUtil htmlToJpgUtil;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增/修改模式4题卡
|
|
|
|
+ *
|
|
|
|
+ * @param params
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Map<String, String> saveGeneric(GenericExamCardModelFourParams params) throws Exception {
|
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+
|
|
|
|
+ ExamCardModelFour examCardModelFour = null;
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_MODEL_FOUR_CARD_SAVE + "-" + schoolId + CardTypeEnum.CUSTOM + params.getTitle()).writeLock().tryLock();
|
|
|
|
+ try {
|
|
|
|
+ QueryWrapper<ExamCardModelFour> checkTitleQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ checkTitleQueryWrapper.lambda().eq(ExamCardModelFour::getSchoolId, schoolId)
|
|
|
|
+ .eq(ExamCardModelFour::getTitle, params.getTitle().trim());
|
|
|
|
+ ExamCardModelFour checkTitleExamCardModelFourDb = this.getOne(checkTitleQueryWrapper);
|
|
|
|
+
|
|
|
|
+ // 新增
|
|
|
|
+ if (Objects.isNull(params.getId())) {
|
|
|
|
+ if (Objects.nonNull(checkTitleExamCardModelFourDb)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称已使用");
|
|
|
|
+ }
|
|
|
|
+ examCardModelFour = new ExamCardModelFour(schoolId, sysUser.getId());
|
|
|
|
+ }
|
|
|
|
+ // 修改
|
|
|
|
+ else {
|
|
|
|
+ examCardModelFour = this.getById(params.getId());
|
|
|
|
+ if (Objects.nonNull(checkTitleExamCardModelFourDb) && params.getId().longValue() != examCardModelFour.getId().longValue()) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
|
|
|
|
+ }
|
|
|
|
+ examCardModelFour.updateInfo(sysUser.getId());
|
|
|
|
+ }
|
|
|
|
+ examCardModelFour.updateInformation(params);
|
|
|
|
+ try {
|
|
|
|
+ // content文件
|
|
|
|
+ String contentMd5 = DigestUtils.md5Hex(params.getContentFile().getBytes());
|
|
|
|
+ if (!Objects.equals(contentMd5, params.getContentMd5())) {
|
|
|
|
+ throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
|
+ }
|
|
|
|
+ String content = SystemConstant.readContent(params.getContentFile().getInputStream());
|
|
|
|
+
|
|
|
|
+ if (ExamCardStatusEnum.SUBMIT.equals(params.getStatus())) {
|
|
|
|
+ examCardModelFour.setContent(content);
|
|
|
|
+ examCardModelFour.setStageContent(null);
|
|
|
|
+
|
|
|
|
+ // content文件
|
|
|
|
+ String htmlMd5 = DigestUtils.md5Hex(params.getHtmlContentFile().getBytes());
|
|
|
|
+ if (!Objects.equals(htmlMd5, params.getHtmlContentMd5())) {
|
|
|
|
+ throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
|
+ }
|
|
|
|
+ String htmlContent = SystemConstant.readContent(params.getHtmlContentFile().getInputStream());
|
|
|
|
+ examCardModelFour.setHtmlContent(htmlContent);
|
|
|
|
+ } else {
|
|
|
|
+ examCardModelFour.setStageContent(content);
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡内容文件解析失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ExamCardStatusEnum.SUBMIT.equals(params.getStatus())) {
|
|
|
|
+ // 生成题卡图片
|
|
|
|
+ createJpgImage(examCardModelFour);
|
|
|
|
+ }
|
|
|
|
+ this.saveOrUpdate(examCardModelFour);
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ map.put("id", String.valueOf(examCardModelFour.getId()));
|
|
|
|
+ map.put("title", examCardModelFour.getTitle());
|
|
|
|
+ return map;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_MODEL_FOUR_CARD_SAVE + "-" + schoolId + CardTypeEnum.CUSTOM + params.getTitle()).writeLock().unlock();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建jpg图片
|
|
|
|
+ *
|
|
|
|
+ * @param examCardModelFour
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ExamCardModelFour createJpgImage(ExamCardModelFour examCardModelFour) {
|
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(examCardModelFour.getCardRuleId());
|
|
|
|
+ BasicCourse basicCourse = examCardModelFour.getCourseId() != null ? basicCourseService.getById(examCardModelFour.getCourseId()) : null;
|
|
|
|
+ String replaceBackupCardHtmlContent = createPdfUtil.replaceBackupCardHtmlParam(basicCourse != null ? basicCourse.getCode() : null, examCardModelFour, null, basicCardRule, null);
|
|
|
|
+ File pdfFile = PdfUtil.htmlToPdf(examCardModelFour.getPageSize(), replaceBackupCardHtmlContent);
|
|
|
|
+ try {
|
|
|
|
+ List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertPdfToJpg(examCardModelFour.getId(), pdfFile, examCardModelFour.getCreateId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(convertJpgStorageList) && convertJpgStorageList.size() > 0) {
|
|
|
|
+ examCardModelFour.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
|
|
|
|
+ } else {
|
|
|
|
+ examCardModelFour.setJpgAttachment(null);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (pdfFile.exists()) {
|
|
|
|
+ FileUtil.deleteFile(pdfFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return examCardModelFour;
|
|
|
|
+ }
|
|
}
|
|
}
|