xiatian 2 年之前
父節點
當前提交
bfaa258183

+ 2 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/RandomPaperService.java

@@ -28,5 +28,7 @@ public interface RandomPaperService {
 
 	boolean existStruct(String id);
 
+	boolean existPaper(Long courseId,String id);
+
 
 }

+ 6 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperServiceImpl.java

@@ -97,6 +97,7 @@ import cn.com.qmth.examcloud.core.questions.service.PaperDetailUnitService;
 import cn.com.qmth.examcloud.core.questions.service.PaperService;
 import cn.com.qmth.examcloud.core.questions.service.QuesService;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperQuestionService;
+import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
 import cn.com.qmth.examcloud.core.questions.service.bean.PaperId;
 import cn.com.qmth.examcloud.core.questions.service.bean.dto.DownloadPaperDto;
 import cn.com.qmth.examcloud.core.questions.service.bean.dto.ObjectiveQuestionStructure;
@@ -189,6 +190,8 @@ public class PaperServiceImpl implements PaperService {
 	private BasePaperCache basePaperCache;
 	@Autowired
 	private RandomPaperQuestionService randomPaperQuestionService;
+	@Autowired
+	private RandomPaperService randomPaperService;
 	
 	@Autowired
 	private QuestionCache questionCache;
@@ -626,6 +629,9 @@ public class PaperServiceImpl implements PaperService {
 				if (paper.getInUse() != null && paper.getInUse() == 1) {
 					throw new StatusException("试卷[" + paper.getName() + "]已调用,不能删除");
 				}
+				if(randomPaperService.existPaper(Long.valueOf(paper.getCourse().getId()),paper.getId())) {
+					throw new StatusException("试卷[" + paper.getName() + "]被抽题模板使用,不能删除");
+				}
 			}
 		}
 		paperDetailService.deletePaperDetailsByPapers(papers);

+ 16 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/RandomPaperServiceImpl.java

@@ -1053,4 +1053,20 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		return rp!=null;
 	}
 
+	@Override
+	public boolean existPaper(Long courseId,String paperId) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("courseId").is(courseId));
+		List<RandomPaper> rps=mongoTemplate.find(query,RandomPaper.class);
+		if(CollectionUtils.isEmpty(rps)) {
+			return false;
+		}
+		for(RandomPaper rp:rps) {
+			if(rp.getPaperIds().contains(paperId)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 }