소스 검색

检查试卷是否正在用于考试

yangfeng 1 년 전
부모
커밋
47f698ad43

+ 10 - 0
web/src/main/java/com/ynfy/buss/exam/paper/service/impl/PaperServiceImpl.java

@@ -23,12 +23,14 @@ import com.ynfy.buss.exam.question.enums.QuestionType;
 import com.ynfy.buss.exam.question.service.IQuestionService;
 import com.ynfy.buss.exam.questionanswer.entity.QuestionAnswer;
 import com.ynfy.buss.exam.repository.service.IRepositoryService;
+import com.ynfy.buss.exam.userexam.service.IUserExamService;
 import com.ynfy.common.utils.ThreadPoolUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.exception.JeecgBootException;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -67,9 +69,17 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
     @Autowired
     private IRepositoryService repositoryService;
 
+    @Lazy
+    @Autowired
+    private IUserExamService userExamService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void save(PaperDTO paperDTO) {
+        //检查试卷是否正在用于考试
+        if (StringUtils.isNotBlank(paperDTO.getId()) && userExamService.checkPaperInExam(paperDTO.getId())) {
+            throw new JeecgBootException("该试卷有正在进行中的考试,不允许修改!");
+        }
         //校验数据
         checkData(paperDTO);
         //校验分数

+ 8 - 0
web/src/main/java/com/ynfy/buss/exam/userexam/service/IUserExamService.java

@@ -31,6 +31,14 @@ public interface IUserExamService extends IService<UserExam> {
      */
     UserExam listExamIn(String userId);
 
+    /**
+     * 检查试卷是否正在用于考试
+     *
+     * @param paperId
+     * @return
+     */
+    boolean checkPaperInExam(String paperId);
+
 
     /**
      * 统计用户某次考试参加的次数

+ 14 - 0
web/src/main/java/com/ynfy/buss/exam/userexam/service/impl/UserExamServiceImpl.java

@@ -53,6 +53,20 @@ public class UserExamServiceImpl extends ServiceImpl<UserExamMapper, UserExam> i
         return !CollectionUtils.isEmpty(list) ? list.get(0) : null;
     }
 
+    /**
+     * 检查试卷是否正在用于考试
+     *
+     * @param paperId
+     * @return
+     */
+    @Override
+    public boolean checkPaperInExam(String paperId) {
+        LambdaQueryWrapper<UserExam> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(UserExam::getPaperId, paperId).eq(UserExam::getState, PaperState.ING);
+        List<UserExam> list = this.list(wrapper);
+        return !CollectionUtils.isEmpty(list);
+    }
+
     /**
      * 统计用户某次考试参加的次数
      *