|
@@ -31,6 +31,7 @@ import com.qmth.teachcloud.common.service.BasicCourseService;
|
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -94,6 +95,15 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
|
|
|
}
|
|
|
if (examCardParams.getId() == null) {
|
|
|
+ QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
+ .eq(ExamCard::getCourseCode, examCardParams.getCourseCode())
|
|
|
+ .eq(ExamCard::getTitle, examCardParams.getTitle());
|
|
|
+ List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
+ if(!examCardList.isEmpty()){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
examCard = new ExamCard();
|
|
|
examCard.setSchoolId(schoolId);
|
|
|
if (Objects.isNull(examCardParams.getTemplateId())) {
|
|
@@ -128,6 +138,16 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
}
|
|
|
// 修改
|
|
|
else {
|
|
|
+ QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId)
|
|
|
+ .eq(ExamCard::getCourseCode, examCardParams.getCourseCode())
|
|
|
+ .eq(ExamCard::getTitle, examCardParams.getTitle())
|
|
|
+ .ne(ExamCard::getId, examCardParams.getId());
|
|
|
+ List<ExamCard> examCardList = this.list(queryWrapper);
|
|
|
+ if(!examCardList.isEmpty()){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
examCard = this.getById(examCardParams.getId());
|
|
|
examCard.setTitle(examCardParams.getTitle());
|
|
|
if (!examCardParams.getCourseCode().equals(examCard.getCourseCode())) {
|
|
@@ -435,6 +455,57 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
|
|
|
return this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Long copyCard(Long id) {
|
|
|
+ ExamCard examCard = this.getById(id);
|
|
|
+ if (examCard == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡不存在");
|
|
|
+ }
|
|
|
+ // 复制题卡
|
|
|
+ ExamCard copyExamCard = new ExamCard();
|
|
|
+ BeanUtils.copyProperties(examCard, copyExamCard);
|
|
|
+ Long copyExamCardId = SystemConstant.getDbUuid();
|
|
|
+ copyExamCard.setId(copyExamCardId);
|
|
|
+ String title = checkTitle(examCard);
|
|
|
+ copyExamCard.setTitle(title);
|
|
|
+ this.save(copyExamCard);
|
|
|
+
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getByCardId(id);
|
|
|
+ if (examCardDetail == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题卡内容不存在");
|
|
|
+ }
|
|
|
+// 复制题卡内容
|
|
|
+ ExamCardDetail copyExamCardDetail = new ExamCardDetail();
|
|
|
+ BeanUtils.copyProperties(examCardDetail, copyExamCardDetail);
|
|
|
+ copyExamCardDetail.setId(SystemConstant.getDbUuid());
|
|
|
+ copyExamCardDetail.setCardId(copyExamCardId);
|
|
|
+ examCardDetailService.save(copyExamCardDetail);
|
|
|
+
|
|
|
+ return copyExamCardId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成新的title
|
|
|
+ *
|
|
|
+ * @param examCard 题卡对象
|
|
|
+ */
|
|
|
+ private String checkTitle(ExamCard examCard) {
|
|
|
+ QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getSchoolId, examCard.getSchoolId())
|
|
|
+ .eq(ExamCard::getCourseCode, examCard.getCourseCode());
|
|
|
+ String title;
|
|
|
+ int i = 1;
|
|
|
+ ExamCard newExamCard;
|
|
|
+ do {
|
|
|
+ title = examCard.getTitle() + "副本" + i;
|
|
|
+ queryWrapper.lambda().eq(ExamCard::getTitle, title);
|
|
|
+ newExamCard = this.getOne(queryWrapper);
|
|
|
+ i++;
|
|
|
+ } while (newExamCard != null);
|
|
|
+ return title;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 数据验证
|
|
|
*
|