diff --git a/web-app/src/main/java/com/zcloud/edu/command/study/ClassExamPaperAddExe.java b/web-app/src/main/java/com/zcloud/edu/command/study/ClassExamPaperAddExe.java index 07e431e..3d5fe95 100644 --- a/web-app/src/main/java/com/zcloud/edu/command/study/ClassExamPaperAddExe.java +++ b/web-app/src/main/java/com/zcloud/edu/command/study/ClassExamPaperAddExe.java @@ -13,6 +13,7 @@ import com.zcloud.edu.dto.study.ClassExamPaperAddCmd; import com.zcloud.edu.dto.study.ClassExamPaperAutoAddCmd; import com.zcloud.edu.persistence.dataobject.QuestionDO; import com.zcloud.edu.persistence.repository.resource.QuestionRepository; +import com.zcloud.edu.persistence.repository.study.ClassExamPaperRepository; import lombok.AllArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; @@ -36,9 +37,16 @@ public class ClassExamPaperAddExe { private final ClassExamPaperGateway classExamPaperGateway; private final ExamPaperGateway examPaperGateway; private final QuestionRepository questionRepository; + private final ClassExamPaperRepository classExamPaperRepository; @Transactional(rollbackFor = Exception.class) public boolean execute(ClassExamPaperAddCmd cmd) { + Long count = classExamPaperRepository.countByClassId(cmd.getClassId()); + if (count > 0) { + throw new BizException("该班级已存在试卷"); + } + + ClassExamPaperE classExamPaperE = new ClassExamPaperE(); BeanUtils.copyProperties(cmd, classExamPaperE); // 初始化字段,并判断题目分数是否符合要求 @@ -58,6 +66,12 @@ public class ClassExamPaperAddExe { @Transactional(rollbackFor = Exception.class) public boolean executeAutoSave(ClassExamPaperAutoAddCmd cmd) { + + Long count = classExamPaperRepository.countByClassId(cmd.getClassId()); + if (count > 0) { + throw new BizException("该班级已存在试卷"); + } + ClassExamPaperE classExamPaperE = new ClassExamPaperE(); BeanUtils.copyProperties(cmd, classExamPaperE); // 初始化字段,并判断题目分数是否符合要求