|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
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.core.concurrent.service.ConcurrentService;
|
|
import com.qmth.distributed.print.business.bean.params.ExamCardParams;
|
|
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.*;
|
|
@@ -37,6 +39,7 @@ import com.qmth.teachcloud.common.util.ExamTaskUtil;
|
|
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.service.ScanAnswerCardService;
|
|
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -88,6 +91,8 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
private ScanAnswerCardService scanAnswerCardService;
|
|
private ScanAnswerCardService scanAnswerCardService;
|
|
@Resource
|
|
@Resource
|
|
private BasicPrintConfigService basicPrintConfigService;
|
|
private BasicPrintConfigService basicPrintConfigService;
|
|
|
|
+ @Resource
|
|
|
|
+ private ConcurrentService concurrentService;
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
@@ -95,78 +100,86 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
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();
|
|
// 新增
|
|
// 新增
|
|
ExamCard examCard;
|
|
ExamCard examCard;
|
|
- if (examCardParams.getTitle().getBytes().length > 80) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
|
|
|
|
- }
|
|
|
|
- if (examCardParams.getId() == null) {
|
|
|
|
- validateCardData(examCardParams);
|
|
|
|
|
|
+ try {
|
|
|
|
+ if (examCardParams.getTitle().getBytes().length > 80) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
|
|
|
|
+ }
|
|
|
|
+ if (examCardParams.getId() == null) {
|
|
|
|
+ validateCardData(examCardParams);
|
|
|
|
+
|
|
|
|
+ String title = examCardParams.getPaperId() != null ? examCardParams.getTitle() + SystemConstant.generateRandomNumber(4) : examCardParams.getTitle();
|
|
|
|
+
|
|
|
|
+ QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
+ .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
+ .eq(ExamCard::getTitle, title);
|
|
|
|
+ List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
|
+ if (!examCardList.isEmpty()) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程下已存在相同的题卡名称[" + title + "]");
|
|
|
|
+ }
|
|
|
|
|
|
- String title = examCardParams.getPaperId() != null ? examCardParams.getTitle() + SystemConstant.generateRandomNumber(4) : examCardParams.getTitle();
|
|
|
|
|
|
+ examCard = new ExamCard();
|
|
|
|
+ examCard.setSchoolId(schoolId);
|
|
|
|
+ // if (Objects.isNull(examCardParams.getTemplateId())) {
|
|
|
|
+ // examCard.setOrgId(basicCourseService.getOrgIdBySchoolIdAndCourseCode(schoolId, examCardParams.getCourseCode()));
|
|
|
|
+ // } else {
|
|
|
|
+ // examCard.setOrgId(user.getOrgId());
|
|
|
|
+ // }
|
|
|
|
+ examCard.setCourseId(examCardParams.getCourseId());
|
|
|
|
+ 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.insertInfo(user.getId());
|
|
|
|
+ }
|
|
|
|
+ // 修改
|
|
|
|
+ else {
|
|
|
|
+ String title = examCardParams.getTitle();
|
|
|
|
+ QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
+ .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
+ .eq(ExamCard::getTitle, title)
|
|
|
|
+ .ne(ExamCard::getId, examCardParams.getId());
|
|
|
|
+ List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
|
+ if (!examCardList.isEmpty()) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
|
|
+ }
|
|
|
|
|
|
- QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
- .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
- .eq(ExamCard::getTitle, title);
|
|
|
|
- List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
|
- if (!examCardList.isEmpty()) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("课程下已存在相同的题卡名称[" + title + "]");
|
|
|
|
|
|
+ examCard = this.getById(examCardParams.getId());
|
|
|
|
+ examCard.setTitle(title);
|
|
|
|
+ examCard.setStatus(examCardParams.getStatus());
|
|
|
|
+ examCard.setUpdateId(user.getId());
|
|
|
|
+ examCard.setUpdateTime(System.currentTimeMillis());
|
|
}
|
|
}
|
|
|
|
|
|
- examCard = new ExamCard();
|
|
|
|
- examCard.setSchoolId(schoolId);
|
|
|
|
-// if (Objects.isNull(examCardParams.getTemplateId())) {
|
|
|
|
-// examCard.setOrgId(basicCourseService.getOrgIdBySchoolIdAndCourseCode(schoolId, examCardParams.getCourseCode()));
|
|
|
|
-// } else {
|
|
|
|
-// examCard.setOrgId(user.getOrgId());
|
|
|
|
-// }
|
|
|
|
- examCard.setCourseId(examCardParams.getCourseId());
|
|
|
|
- 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.insertInfo(user.getId());
|
|
|
|
- }
|
|
|
|
- // 修改
|
|
|
|
- else {
|
|
|
|
- String title = examCardParams.getTitle();
|
|
|
|
- QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
- .eq(ExamCard::getCourseId, examCardParams.getCourseId())
|
|
|
|
- .eq(ExamCard::getTitle, title)
|
|
|
|
- .ne(ExamCard::getId, examCardParams.getId());
|
|
|
|
- List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
|
- if (!examCardList.isEmpty()) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
|
|
|
|
+ // 自动保存
|
|
|
|
+ if (ExamCardStatusEnum.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);
|
|
|
|
|
|
- examCard = this.getById(examCardParams.getId());
|
|
|
|
- examCard.setTitle(title);
|
|
|
|
- examCard.setStatus(examCardParams.getStatus());
|
|
|
|
- examCard.setUpdateId(user.getId());
|
|
|
|
- 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());
|
|
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ map.put("id", String.valueOf(examCard.getId()));
|
|
|
|
+ map.put("title", examCard.getTitle());
|
|
|
|
+ return map;
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + examCardParams.getCourseId() + examCardParams.getTitle()).writeLock().unlock();
|
|
}
|
|
}
|
|
- this.saveOrUpdate(examCard);
|
|
|
|
-
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
|
- map.put("id", String.valueOf(examCard.getId()));
|
|
|
|
- map.put("title", examCard.getTitle());
|
|
|
|
- return map;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -233,125 +246,135 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
|
|
- QueryWrapper<ExamCard> checkTitleQueryWrapper = new QueryWrapper<>();
|
|
|
|
- checkTitleQueryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
- .eq(ExamCard::getType, CardTypeEnum.GENERIC)
|
|
|
|
- .eq(ExamCard::getTitle, params.getTitle().trim());
|
|
|
|
- ExamCard checkTitleExamCardList = this.getOne(checkTitleQueryWrapper);
|
|
|
|
-
|
|
|
|
- ExamCard examCard = new ExamCard();
|
|
|
|
- // 新增
|
|
|
|
- if (Objects.isNull(params.getId())) {
|
|
|
|
- if (checkTitleExamCardList != null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("题卡名称已使用");
|
|
|
|
- }
|
|
|
|
- // 保存题卡
|
|
|
|
- examCard.setId(SystemConstant.getDbUuid());
|
|
|
|
- examCard.setSchoolId(schoolId);
|
|
|
|
- examCard.setOrgId(sysUser.getOrgId());
|
|
|
|
-
|
|
|
|
- examCard.setTitle(params.getTitle());
|
|
|
|
- examCard.setMakeMethod(MakeMethodEnum.SELECT); // 默认值
|
|
|
|
- // 上传题卡,状态为提交
|
|
|
|
- examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : ExamCardStatusEnum.valueOf(params.getStatus()));
|
|
|
|
- examCard.setType(CardTypeEnum.GENERIC); // 默认值
|
|
|
|
- examCard.setCreateMethod(params.getCreateMethod());
|
|
|
|
- examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
- examCard.setEnable(true); // 默认值
|
|
|
|
- examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
- examCard.setRemark(params.getRemark());
|
|
|
|
- examCard.setPageSize(params.getPageSize());
|
|
|
|
- examCard.setCreateId(sysUser.getId());
|
|
|
|
- examCard.setCreateTime(System.currentTimeMillis());
|
|
|
|
- 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文件");
|
|
|
|
|
|
+ ExamCard examCard;
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + schoolId + CardTypeEnum.GENERIC + params.getTitle()).writeLock().tryLock();
|
|
|
|
+ try {
|
|
|
|
+ QueryWrapper<ExamCard> checkTitleQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ checkTitleQueryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
|
+ .eq(ExamCard::getType, CardTypeEnum.GENERIC)
|
|
|
|
+ .eq(ExamCard::getTitle, params.getTitle().trim());
|
|
|
|
+ ExamCard checkTitleExamCardList = this.getOne(checkTitleQueryWrapper);
|
|
|
|
+
|
|
|
|
+ // 新增
|
|
|
|
+ if (Objects.isNull(params.getId())) {
|
|
|
|
+ if (checkTitleExamCardList != null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称已使用");
|
|
}
|
|
}
|
|
- 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 = new ExamCard();
|
|
|
|
+ // 保存题卡
|
|
|
|
+ examCard.setId(SystemConstant.getDbUuid());
|
|
|
|
+ examCard.setSchoolId(schoolId);
|
|
|
|
+ examCard.setOrgId(sysUser.getOrgId());
|
|
|
|
+
|
|
|
|
+ examCard.setTitle(params.getTitle());
|
|
|
|
+ examCard.setMakeMethod(MakeMethodEnum.SELECT); // 默认值
|
|
|
|
+ // 上传题卡,状态为提交
|
|
|
|
+ examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : ExamCardStatusEnum.valueOf(params.getStatus()));
|
|
|
|
+ examCard.setType(CardTypeEnum.GENERIC); // 默认值
|
|
|
|
+ examCard.setCreateMethod(params.getCreateMethod());
|
|
|
|
+ examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
+ examCard.setEnable(true); // 默认值
|
|
|
|
+ examCard.setCardRuleId(params.getCardRuleId());
|
|
|
|
+ examCard.setRemark(params.getRemark());
|
|
|
|
+ examCard.setPageSize(params.getPageSize());
|
|
|
|
+ examCard.setCreateId(sysUser.getId());
|
|
|
|
+ examCard.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ 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);
|
|
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 {
|
|
} else {
|
|
- examCard.setStageContent(params.getContent());
|
|
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 修改
|
|
|
|
- else {
|
|
|
|
- examCard = this.getById(params.getId());
|
|
|
|
- if (checkTitleExamCardList != null && !Objects.equals(params.getId(), examCard.getId())) {
|
|
|
|
- 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.setUpdateId(sysUser.getId());
|
|
|
|
- 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文件");
|
|
|
|
|
|
+ // 修改
|
|
|
|
+ else {
|
|
|
|
+ examCard = this.getById(params.getId());
|
|
|
|
+ if (checkTitleExamCardList != null && !Objects.equals(params.getId(), examCard.getId())) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
|
|
}
|
|
}
|
|
- htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
|
|
|
|
- examCard.setHtmlContent(htmlContent);
|
|
|
|
|
|
+ examCard.setTitle(params.getTitle());
|
|
|
|
+ examCard.setAttachmentId(params.getAttachmentId());
|
|
|
|
+ examCard.setCardRuleId(params.getCardRuleId());
|
|
// 上传题卡,状态为提交
|
|
// 上传题卡,状态为提交
|
|
- examCard.setStatus(ExamCardStatusEnum.SUBMIT);
|
|
|
|
- }
|
|
|
|
- // 方式为自定义
|
|
|
|
- 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.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? ExamCardStatusEnum.SUBMIT : ExamCardStatusEnum.valueOf(params.getStatus()));
|
|
|
|
+ examCard.setRemark(params.getRemark());
|
|
|
|
+ examCard.setUpdateId(sysUser.getId());
|
|
|
|
+ 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文件");
|
|
|
|
+ }
|
|
|
|
+ htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
|
|
examCard.setHtmlContent(htmlContent);
|
|
examCard.setHtmlContent(htmlContent);
|
|
|
|
+ // 上传题卡,状态为提交
|
|
|
|
+ examCard.setStatus(ExamCardStatusEnum.SUBMIT);
|
|
|
|
+ }
|
|
|
|
+ // 方式为自定义
|
|
|
|
+ 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 {
|
|
} else {
|
|
- examCard.setStageContent(params.getContent());
|
|
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不存在的题卡创建方式");
|
|
|
|
}
|
|
}
|
|
|
|
+ if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
|
|
+ // 生成题卡图片
|
|
|
|
+ createJpgImage(examCard);
|
|
|
|
+ }
|
|
|
|
+ this.saveOrUpdate(examCard);
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ map.put("id", String.valueOf(examCard.getId()));
|
|
|
|
+ map.put("title", examCard.getTitle());
|
|
|
|
+ return map;
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CUSTOM_CARD_SAVE + "-" + schoolId + CardTypeEnum.GENERIC + params.getTitle()).writeLock().unlock();
|
|
}
|
|
}
|
|
- if (ExamCardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
|
|
|
|
- // 生成题卡图片
|
|
|
|
- createJpgImage(examCard);
|
|
|
|
- }
|
|
|
|
- this.saveOrUpdate(examCard);
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
|
- map.put("id", String.valueOf(examCard.getId()));
|
|
|
|
- map.put("title", examCard.getTitle());
|
|
|
|
- return map;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|