|
@@ -9,15 +9,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
-import com.qmth.distributed.print.business.bean.params.ExamCardParams;
|
|
|
|
import com.qmth.distributed.print.business.bean.params.GenericExamCardParams;
|
|
import com.qmth.distributed.print.business.bean.params.GenericExamCardParams;
|
|
-import com.qmth.distributed.print.business.entity.*;
|
|
|
|
|
|
+import com.qmth.distributed.print.business.entity.BasicCardRule;
|
|
|
|
+import com.qmth.distributed.print.business.entity.BasicExamRule;
|
|
|
|
+import com.qmth.distributed.print.business.entity.ExamCard;
|
|
|
|
+import com.qmth.distributed.print.business.entity.ExamTaskDetail;
|
|
import com.qmth.distributed.print.business.enums.CardTypeEnum;
|
|
import com.qmth.distributed.print.business.enums.CardTypeEnum;
|
|
import com.qmth.distributed.print.business.enums.ExamCardStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.ExamCardStatusEnum;
|
|
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
|
|
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
|
|
import com.qmth.distributed.print.business.mapper.ExamCardMapper;
|
|
import com.qmth.distributed.print.business.mapper.ExamCardMapper;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.service.*;
|
|
import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
|
+import com.qmth.distributed.print.business.util.ExamTaskUtil;
|
|
import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
|
|
import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
|
|
import com.qmth.distributed.print.business.util.PdfUtil;
|
|
import com.qmth.distributed.print.business.util.PdfUtil;
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
@@ -35,13 +38,13 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
-import com.qmth.distributed.print.business.util.ExamTaskUtil;
|
|
|
|
import com.qmth.teachcloud.common.util.Base64Util;
|
|
import com.qmth.teachcloud.common.util.Base64Util;
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
import com.qmth.teachcloud.common.util.FileUtil;
|
|
import com.qmth.teachcloud.common.util.HtmlToPdfUtil;
|
|
import com.qmth.teachcloud.common.util.HtmlToPdfUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
import com.qmth.teachcloud.mark.enums.LockType;
|
|
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -51,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
@@ -97,25 +101,25 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public Map<String, String> saveExamCard(ExamCardParams examCardParams) {
|
|
|
|
|
|
+ public Map<String, String> saveExamCard(GenericExamCardParams params) {
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
SysUser user = (SysUser) ServletUtil.getRequestUser();
|
|
SysUser user = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
|
|
- concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + examCardParams.getCourseId() + examCardParams.getTitle()).writeLock().lock();
|
|
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + params.getCourseId() + params.getTitle()).writeLock().lock();
|
|
// 新增
|
|
// 新增
|
|
ExamCard examCard;
|
|
ExamCard examCard;
|
|
try {
|
|
try {
|
|
- if (examCardParams.getTitle().getBytes().length > 80) {
|
|
|
|
|
|
+ if (params.getTitle().getBytes().length > 80) {
|
|
throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
|
|
throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
|
|
}
|
|
}
|
|
- if (examCardParams.getId() == null) {
|
|
|
|
- validateCardData(examCardParams);
|
|
|
|
|
|
+ if (params.getId() == null) {
|
|
|
|
+ validateCardData(params);
|
|
|
|
|
|
- String title = examCardParams.getPaperId() != null ? examCardParams.getTitle() + SystemConstant.generateRandomNumber(4) : examCardParams.getTitle();
|
|
|
|
|
|
+ String title = params.getPaperId() != null ? params.getTitle() + SystemConstant.generateRandomNumber(4) : params.getTitle();
|
|
|
|
|
|
QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
- .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
|
|
+ .eq(ExamCard::getCourseId, params.getCourseId())
|
|
.eq(ExamCard::getTitle, title);
|
|
.eq(ExamCard::getTitle, title);
|
|
List<ExamCard> examCardList = this.list(queryWrapper);
|
|
List<ExamCard> examCardList = this.list(queryWrapper);
|
|
if (!examCardList.isEmpty()) {
|
|
if (!examCardList.isEmpty()) {
|
|
@@ -124,50 +128,68 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
|
|
|
examCard = new ExamCard();
|
|
examCard = new ExamCard();
|
|
examCard.setSchoolId(schoolId);
|
|
examCard.setSchoolId(schoolId);
|
|
- examCard.setCourseId(examCardParams.getCourseId());
|
|
|
|
|
|
+ examCard.setCourseId(params.getCourseId());
|
|
examCard.setTitle(title);
|
|
examCard.setTitle(title);
|
|
- examCard.setMakeMethod(examCardParams.getMakeMethod());
|
|
|
|
- examCard.setStatus(examCardParams.getStatus());
|
|
|
|
- examCard.setType(examCardParams.getType());
|
|
|
|
- examCard.setAttachmentId(examCardParams.getAttachmentId());
|
|
|
|
- examCard.setCardRuleId(examCardParams.getCardRuleId());
|
|
|
|
- examCard.setPaperId(examCardParams.getPaperId());
|
|
|
|
- examCard.setPageSize(examCardParams.getPageSize());
|
|
|
|
- examCard.setOpenAb(examCardParams.getOpenAb());
|
|
|
|
|
|
+ examCard.setMakeMethod(params.getMakeMethod());
|
|
|
|
+ examCard.setStatus(params.getStatus());
|
|
|
|
+ examCard.setType(params.getType());
|
|
|
|
+ examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
+ examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
+ examCard.setPaperId(params.getPaperId());
|
|
|
|
+ examCard.setPageSize(params.getPageSize());
|
|
|
|
+ examCard.setOpenAb(params.getOpenAb());
|
|
examCard.insertInfo(user.getId());
|
|
examCard.insertInfo(user.getId());
|
|
}
|
|
}
|
|
// 修改
|
|
// 修改
|
|
else {
|
|
else {
|
|
- String title = examCardParams.getTitle();
|
|
|
|
|
|
+ String title = params.getTitle();
|
|
QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
- .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
|
|
+ .eq(ExamCard::getCourseId, params.getCourseId())
|
|
.eq(ExamCard::getTitle, title)
|
|
.eq(ExamCard::getTitle, title)
|
|
- .ne(ExamCard::getId, examCardParams.getId());
|
|
|
|
|
|
+ .ne(ExamCard::getId, params.getId());
|
|
List<ExamCard> examCardList = this.list(queryWrapper);
|
|
List<ExamCard> examCardList = this.list(queryWrapper);
|
|
if (!examCardList.isEmpty()) {
|
|
if (!examCardList.isEmpty()) {
|
|
throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
}
|
|
}
|
|
|
|
|
|
- examCard = this.getById(examCardParams.getId());
|
|
|
|
|
|
+ examCard = this.getById(params.getId());
|
|
examCard.setTitle(title);
|
|
examCard.setTitle(title);
|
|
- examCard.setStatus(examCardParams.getStatus());
|
|
|
|
- examCard.setOpenAb(examCardParams.getOpenAb());
|
|
|
|
|
|
+ examCard.setStatus(params.getStatus());
|
|
|
|
+ examCard.setOpenAb(params.getOpenAb());
|
|
examCard.setUpdateId(user.getId());
|
|
examCard.setUpdateId(user.getId());
|
|
examCard.setUpdateTime(System.currentTimeMillis());
|
|
examCard.setUpdateTime(System.currentTimeMillis());
|
|
}
|
|
}
|
|
|
|
|
|
- // 自动保存
|
|
|
|
- if (ExamCardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
|
|
|
|
- examCard.setContent(examCardParams.getContent());
|
|
|
|
- examCard.setStageContent(null);
|
|
|
|
- examCard.setHtmlContent(examCardParams.getHtmlContent());
|
|
|
|
- createJpgImage(examCard);
|
|
|
|
- } else {
|
|
|
|
- examCard.setStageContent(examCardParams.getContent());
|
|
|
|
|
|
+ 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())) {
|
|
|
|
+ examCard.setContent(content);
|
|
|
|
+ examCard.setStageContent(null);
|
|
|
|
+
|
|
|
|
+ // htmlContent文件
|
|
|
|
+ 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());
|
|
|
|
+ examCard.setHtmlContent(htmlContent);
|
|
|
|
+ createJpgImage(examCard);
|
|
|
|
+ } else {
|
|
|
|
+ examCard.setStageContent(content);
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡内容文件解析失败");
|
|
}
|
|
}
|
|
- this.saveOrUpdate(examCard);
|
|
|
|
|
|
|
|
|
|
+ this.saveOrUpdate(examCard);
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
Map<String, String> map = new HashMap<>();
|
|
map.put("id", String.valueOf(examCard.getId()));
|
|
map.put("id", String.valueOf(examCard.getId()));
|
|
@@ -176,7 +198,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
} finally {
|
|
} finally {
|
|
- concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + examCardParams.getCourseId() + examCardParams.getTitle()).writeLock().unlock();
|
|
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + params.getCourseId() + params.getTitle()).writeLock().unlock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -263,52 +285,14 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
examCard.setId(SystemConstant.getDbUuid());
|
|
examCard.setId(SystemConstant.getDbUuid());
|
|
examCard.setSchoolId(schoolId);
|
|
examCard.setSchoolId(schoolId);
|
|
examCard.setOrgId(sysUser.getOrgId());
|
|
examCard.setOrgId(sysUser.getOrgId());
|
|
-
|
|
|
|
- examCard.setTitle(params.getTitle());
|
|
|
|
examCard.setMakeMethod(MakeMethodEnum.SELECT); // 默认值
|
|
examCard.setMakeMethod(MakeMethodEnum.SELECT); // 默认值
|
|
// 上传题卡,状态为提交
|
|
// 上传题卡,状态为提交
|
|
- examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : ExamCardStatusEnum.valueOf(params.getStatus()));
|
|
|
|
examCard.setType(CardTypeEnum.GENERIC); // 默认值
|
|
examCard.setType(CardTypeEnum.GENERIC); // 默认值
|
|
examCard.setCreateMethod(params.getCreateMethod());
|
|
examCard.setCreateMethod(params.getCreateMethod());
|
|
- examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
examCard.setEnable(true); // 默认值
|
|
examCard.setEnable(true); // 默认值
|
|
- examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
- examCard.setRemark(params.getRemark());
|
|
|
|
- examCard.setPageSize(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? PageSizeEnum.A3.name() : params.getPageSize());
|
|
|
|
examCard.setCreateId(sysUser.getId());
|
|
examCard.setCreateId(sysUser.getId());
|
|
examCard.setCreateTime(System.currentTimeMillis());
|
|
examCard.setCreateTime(System.currentTimeMillis());
|
|
this.save(examCard);
|
|
this.save(examCard);
|
|
-
|
|
|
|
- // 方式为上传
|
|
|
|
- String htmlContent;
|
|
|
|
- if (CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod())) {
|
|
|
|
- if (params.getAttachmentId() == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("请上传模板文件");
|
|
|
|
- }
|
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(params.getAttachmentId());
|
|
|
|
- if (attachment == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("无模板文件记录,请重新上传");
|
|
|
|
- }
|
|
|
|
- if (!SystemConstant.HTML_PREFIX.equalsIgnoreCase(attachment.getType())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("只能上传后缀为.html文件");
|
|
|
|
- }
|
|
|
|
- htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
|
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
|
- }
|
|
|
|
- // 方式为自定义
|
|
|
|
- else if (CardCreateMethodEnum.STANDARD.equals(params.getCreateMethod())
|
|
|
|
- || CardCreateMethodEnum.FREE.equals(params.getCreateMethod())) {
|
|
|
|
- if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
|
|
- examCard.setContent(params.getContent());
|
|
|
|
- examCard.setStageContent(null);
|
|
|
|
- htmlContent = params.getHtmlContent();
|
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
|
- } else {
|
|
|
|
- examCard.setStageContent(params.getContent());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
// 修改
|
|
// 修改
|
|
else {
|
|
else {
|
|
@@ -316,47 +300,65 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
if (checkTitleExamCardList != null && !Objects.equals(params.getId(), examCard.getId())) {
|
|
if (checkTitleExamCardList != null && !Objects.equals(params.getId(), examCard.getId())) {
|
|
throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
|
|
throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
|
|
}
|
|
}
|
|
- examCard.setTitle(params.getTitle());
|
|
|
|
- examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
- examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
- // 上传题卡,状态为提交
|
|
|
|
- examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : ExamCardStatusEnum.valueOf(params.getStatus()));
|
|
|
|
- examCard.setRemark(params.getRemark());
|
|
|
|
- examCard.setPageSize(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? PageSizeEnum.A3.name() : examCard.getPageSize());
|
|
|
|
examCard.setUpdateId(sysUser.getId());
|
|
examCard.setUpdateId(sysUser.getId());
|
|
examCard.setUpdateTime(System.currentTimeMillis());
|
|
examCard.setUpdateTime(System.currentTimeMillis());
|
|
-
|
|
|
|
- String htmlContent;
|
|
|
|
- // 方式为上传
|
|
|
|
- if (CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod())) {
|
|
|
|
- if (params.getAttachmentId() == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("请上传模板文件");
|
|
|
|
- }
|
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(params.getAttachmentId());
|
|
|
|
- if (attachment == null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("无模板文件记录,请重新上传");
|
|
|
|
- }
|
|
|
|
- if (!SystemConstant.HTML_PREFIX.equalsIgnoreCase(attachment.getType())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("只能上传后缀为.html文件");
|
|
|
|
|
|
+ }
|
|
|
|
+ examCard.setTitle(params.getTitle());
|
|
|
|
+ examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
+ examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
+ // 上传题卡,状态为提交
|
|
|
|
+ examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : params.getStatus());
|
|
|
|
+ examCard.setRemark(params.getRemark());
|
|
|
|
+ examCard.setPageSize(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? PageSizeEnum.A3.name() : examCard.getPageSize());
|
|
|
|
+
|
|
|
|
+ // 方式为上传
|
|
|
|
+
|
|
|
|
+ if (CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod())) {
|
|
|
|
+ if (params.getAttachmentId() == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("请上传模板文件");
|
|
|
|
+ }
|
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(params.getAttachmentId());
|
|
|
|
+ if (attachment == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("无模板文件记录,请重新上传");
|
|
|
|
+ }
|
|
|
|
+ if (!SystemConstant.HTML_PREFIX.equalsIgnoreCase(attachment.getType())) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只能上传后缀为.html文件");
|
|
|
|
+ }
|
|
|
|
+ String htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
|
|
|
|
+ examCard.setHtmlContent(htmlContent);
|
|
|
|
+ }
|
|
|
|
+ // 方式为自定义
|
|
|
|
+ else if (CardCreateMethodEnum.STANDARD.equals(params.getCreateMethod())
|
|
|
|
+ || CardCreateMethodEnum.FREE.equals(params.getCreateMethod())) {
|
|
|
|
+ try {
|
|
|
|
+ // content文件
|
|
|
|
+ String contentMd5 = DigestUtils.md5Hex(params.getContentFile().getBytes());
|
|
|
|
+ if (!Objects.equals(contentMd5, params.getContentMd5())) {
|
|
|
|
+ throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
}
|
|
}
|
|
- htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
|
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
|
|
|
+ String content = SystemConstant.readContent(params.getContentFile().getInputStream());
|
|
|
|
|
|
- }
|
|
|
|
- // 方式为自定义
|
|
|
|
- else if (CardCreateMethodEnum.STANDARD.equals(params.getCreateMethod()) || CardCreateMethodEnum.FREE.equals(params.getCreateMethod())) {
|
|
|
|
if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
- examCard.setContent(params.getContent());
|
|
|
|
|
|
+ examCard.setContent(content);
|
|
examCard.setStageContent(null);
|
|
examCard.setStageContent(null);
|
|
- htmlContent = params.getHtmlContent();
|
|
|
|
|
|
+
|
|
|
|
+ // 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());
|
|
examCard.setHtmlContent(htmlContent);
|
|
examCard.setHtmlContent(htmlContent);
|
|
} else {
|
|
} else {
|
|
- examCard.setStageContent(params.getContent());
|
|
|
|
|
|
+ examCard.setStageContent(content);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡内容文件解析失败");
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
}
|
|
}
|
|
|
|
+
|
|
if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
// 生成题卡图片
|
|
// 生成题卡图片
|
|
createJpgImage(examCard);
|
|
createJpgImage(examCard);
|
|
@@ -559,37 +561,35 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
/**
|
|
/**
|
|
* 数据验证
|
|
* 数据验证
|
|
*
|
|
*
|
|
- * @param examCardParams
|
|
|
|
|
|
+ * @param params
|
|
*/
|
|
*/
|
|
- private void validateCardData(ExamCardParams examCardParams) {
|
|
|
|
|
|
+ private void validateCardData(GenericExamCardParams params) {
|
|
BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
|
|
BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
|
|
if (basicExamRule == null) {
|
|
if (basicExamRule == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("通用规则未设置");
|
|
throw ExceptionResultEnum.ERROR.exception("通用规则未设置");
|
|
}
|
|
}
|
|
|
|
|
|
- if (examCardParams.getStatus() == null) {
|
|
|
|
|
|
+ if (params.getStatus() == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("提交方式不能为空");
|
|
throw ExceptionResultEnum.ERROR.exception("提交方式不能为空");
|
|
}
|
|
}
|
|
- if (CardTypeEnum.CUSTOM.name().equals(examCardParams.getType().name())) {
|
|
|
|
- if (examCardParams.getCourseId() == null) {
|
|
|
|
|
|
+ if (CardTypeEnum.CUSTOM.name().equals(params.getType().name())) {
|
|
|
|
+ if (params.getCourseId() == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("未获取到课程信息");
|
|
throw ExceptionResultEnum.ERROR.exception("未获取到课程信息");
|
|
}
|
|
}
|
|
- if (MakeMethodEnum.SELECT.name().equals(examCardParams.getMakeMethod().name())) {
|
|
|
|
- if (examCardParams.getId() == null) {
|
|
|
|
|
|
+ if (MakeMethodEnum.SELECT.name().equals(params.getMakeMethod().name())) {
|
|
|
|
+ if (params.getId() == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("选择已有题卡时,题卡ID不能为空");
|
|
throw ExceptionResultEnum.ERROR.exception("选择已有题卡时,题卡ID不能为空");
|
|
}
|
|
}
|
|
// 当前选择题卡是否已绑定(不再校验是否使用 2023-06-20)
|
|
// 当前选择题卡是否已绑定(不再校验是否使用 2023-06-20)
|
|
- } else if (MakeMethodEnum.SELF.name().equals(examCardParams.getMakeMethod().name())) {
|
|
|
|
- if (StringUtils.isBlank(examCardParams.getTitle())) {
|
|
|
|
|
|
+ } else if (MakeMethodEnum.SELF.name().equals(params.getMakeMethod().name())) {
|
|
|
|
+ if (StringUtils.isBlank(params.getTitle())) {
|
|
throw ExceptionResultEnum.ERROR.exception("题卡标题不能为空");
|
|
throw ExceptionResultEnum.ERROR.exception("题卡标题不能为空");
|
|
}
|
|
}
|
|
- if (StringUtils.isBlank(examCardParams.getContent())) {
|
|
|
|
|
|
+ if (params.getContentFile() == null || params.getContentFile().getSize() == 0) {
|
|
throw ExceptionResultEnum.ERROR.exception("题卡内容不能为空");
|
|
throw ExceptionResultEnum.ERROR.exception("题卡内容不能为空");
|
|
}
|
|
}
|
|
- if (ExamCardStatusEnum.SUBMIT.name().equals(examCardParams.getStatus().name())) {
|
|
|
|
- if (StringUtils.isBlank(examCardParams.getHtmlContent())) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("提交题卡时,html内容不能为空");
|
|
|
|
- }
|
|
|
|
|
|
+ if (params.getHtmlContentFile() == null || params.getHtmlContentFile().getSize() == 0) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("提交题卡时,html内容不能为空");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
throw ExceptionResultEnum.ERROR.exception("不支持的题卡制作方式");
|
|
throw ExceptionResultEnum.ERROR.exception("不支持的题卡制作方式");
|