Просмотр исходного кода

修改导入试卷时,试卷中的属性不应该跟已经禁用的课程属性进行匹配的bug

weiwenhai 7 лет назад
Родитель
Сommit
c3eb47a174

+ 20 - 11
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -845,8 +845,10 @@ public class ImportPaperService {
 		}
 		//一级属性,二级属性都有值
 		else if(StringUtils.isNotBlank(firstProperty) && StringUtils.isNotBlank(secondProperty)){
+			boolean isFirstEmpty = true;
+			boolean isSecondEmpty = true;
 			//根据课程查询所有课程属性树
-			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
+			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCodeAndEnable(paper.getCourse().getCode(), true);
 			if(courseProperties == null || courseProperties.size()<1){
 				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
 	    		throw new PaperException(importPaperCheck.errorInfo);
@@ -857,12 +859,14 @@ public class ImportPaperService {
 				List<Property> propertieParents = propertyRepo.findAll(Example.of(propertyParent));
 				//存在一级属性
 				if(propertieParents != null || propertieParents.size()>0){
+					isFirstEmpty = false;
 					for(Property proParent:propertieParents){
 						Property propertySon = new Property(secondProperty,proParent.getId(),courseProperty.getId());
 						//查询二级属性
 						List<Property> propertieSons = propertyRepo.findAll(Example.of(propertySon));
 						//存在二级属性
 						if(propertieSons!=null && propertieSons.size()>0){
+							isSecondEmpty = false;
 							for(Property proSon:propertieSons){
 								//保存一级和二级属性
 								QuesProperty quesProperty = new QuesProperty(proParent, proSon,courseProperty);
@@ -870,21 +874,24 @@ public class ImportPaperService {
 								quesProperty.setId(idNumber);
 								quesProperties.add(quesProperty);
 							}
-						}else{
-							importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题二级属性值不存在,请检查");
-				    		throw new PaperException(importPaperCheck.errorInfo);
 						}
 					}
-				}else{
-					importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题一级属性值不存在,请检查");
-		    		throw new PaperException(importPaperCheck.errorInfo);
 				}
 			}
+			if(isFirstEmpty){
+				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题一级属性值不存在,请检查");
+	    		throw new PaperException(importPaperCheck.errorInfo);
+			}
+			if(isSecondEmpty){
+				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题二级属性值不存在,请检查");
+	    		throw new PaperException(importPaperCheck.errorInfo);
+			}
 		}
 		//一级属性有值,二级属性为空
 		else if(StringUtils.isNotBlank(firstProperty) && StringUtils.isBlank(secondProperty)){
+			boolean isEmpty = true;
 			//根据课程查询所有课程属性树
-			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
+			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCodeAndEnable(paper.getCourse().getCode(), true);
 			if(courseProperties == null || courseProperties.size()<1){
 				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
 	    		throw new PaperException(importPaperCheck.errorInfo);
@@ -895,6 +902,7 @@ public class ImportPaperService {
 				List<Property> propertieParents = propertyRepo.findAll(Example.of(propertyParent));
 				//存在一级属性
 				if(propertieParents!=null && propertieParents.size()>0){
+					isEmpty = false;
 					for(Property proParent:propertieParents){
 						//根据一级属性查询二级属性
 						List<Property> proSons = propertyRepo.findByParentIdOrderByNumber(proParent.getId());
@@ -910,11 +918,12 @@ public class ImportPaperService {
 							quesProperties.add(quesProperty);
 						}
 					}
-				}else {
-					importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题一级属性值不存在,请检查");
-		    		throw new PaperException(importPaperCheck.errorInfo);
 				}
 			}
+			if(isEmpty){
+				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,小题一级属性值不存在,请检查");
+	    		throw new PaperException(importPaperCheck.errorInfo);
+			}
 		}//一级,二级都为空
 		else {
 			

+ 3 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/dao/CoursePropertyRepo.java

@@ -24,5 +24,8 @@ public interface CoursePropertyRepo extends JpaRepository<CourseProperty, Long>,
 	List<CourseProperty> findByCourseId(Long courseId);
 	
 	List<CourseProperty> findByCourseCode(String code);
+	
+	//根据课程代码查询已开启的课程属性
+	List<CourseProperty> findByCourseCodeAndEnable(String code,Boolean enable);
 
 }