xiatian 1 tahun lalu
induk
melakukan
47d1c0a820

+ 8 - 0
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/ExtractConfigController.java

@@ -95,6 +95,7 @@ public class ExtractConfigController extends ControllerSupport {
 		extractConfig.setOrgId(user.getRootOrgId() + "");
 		extractConfig.setOrgName(user.getRootOrgName());
 		if (!CallType.RANDOM_PAPER.equals(extractConfig.getCallType())) {
+			extractConfig.setRandomPaperId(null);
 			extractConfigFileService.saveExtractConfigAndBuildPaperFile(extractConfig, isBuildFile, user, seqMode);
 		} else {
 			if (extractConfig.getRandomPaperId() == null) {
@@ -103,6 +104,7 @@ public class ExtractConfigController extends ControllerSupport {
 			if (extractConfig.getPlayTime() == null) {
 				throw new StatusException("请填写音频播放次数");
 			}
+			extractConfig.setExamPaperList(null);
 			extractConfigService.saveExtractConfigForRandomPaper(extractConfig);
 		}
 
@@ -158,6 +160,12 @@ public class ExtractConfigController extends ControllerSupport {
 	}
 
 	private boolean paperChange(ExtractConfig old, ExtractConfig now) {
+		if (old.getExamPaperList() ==null&& now.getExamPaperList()!=null) {
+			return true;
+		}
+		if (old.getExamPaperList() !=null&& now.getExamPaperList()==null) {
+			return true;
+		}
 		if (old.getExamPaperList().size() != now.getExamPaperList().size()) {
 			return true;
 		}

+ 31 - 17
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigServiceImpl.java

@@ -14,6 +14,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.bson.types.ObjectId;
 import org.nlpcn.commons.lang.util.StringUtil;
@@ -32,7 +33,6 @@ import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
 
 import cn.com.qmth.examcloud.api.commons.enums.CallType;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
@@ -185,6 +185,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
         query.addCriteria(Criteria.where("examId").is(condition.getExamId()));
         query.addCriteria(Criteria.where("courseCode").is(condition.getCourseCode()));
         ExtractConfig tempConfig = this.mongoTemplate.findOne(query, ExtractConfig.class);
+        if(tempConfig!=null&&tempConfig.getCallType()==null) {
+        	tempConfig.setCallType(CallType.WHOLE_SET);
+        }
         return tempConfig;
     }
 
@@ -238,6 +241,12 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     @Transactional
     @Override
     public void saveExtractConfigForRandomPaper(ExtractConfig extractConfig) {
+    	GetExamReq examReq=new GetExamReq();
+    	examReq.setId(extractConfig.getExamId());
+    	GetExamResp examRes=examCloudService.getExam(examReq);
+    	if(ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
+    		throw new StatusException("离线考试不能随机抽题");
+    	}
         Course course = courseService.getCourse(Long.valueOf(extractConfig.getOrgId()), extractConfig.getCourseCode());
         extractConfig.setCourse(course);
         extractConfig.setCourseName(course.getName());
@@ -261,6 +270,7 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 				tempConfig.setPlayTime(extractConfig.getPlayTime());
 				tempConfig.setCourseName(course.getName());
 				tempConfig.setCourse(course);
+				tempConfig.setCallType(extractConfig.getCallType());
 				extractConfig=tempConfig;
 			}
 		}else {
@@ -269,8 +279,13 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 			tempConfig.setPlayTime(extractConfig.getPlayTime());
 			tempConfig.setCourseName(course.getName());
 			tempConfig.setCourse(course);
+			tempConfig.setCallType(extractConfig.getCallType());
 			extractConfig=tempConfig;
 		}
+		if (StringUtils.isNotBlank(extractConfig.getId())) {
+            disposeOldPaper(extractConfig.getId());
+        }
+		extractConfig.setExamPaperList(null);
         extractConfigRepo.save(extractConfig);
     }
 
@@ -281,6 +296,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
      */
     private void disposeOldPaper(String extractConfigId) {
         ExtractConfig ec = Model.of(extractConfigRepo.findById(extractConfigId));
+        if(CollectionUtils.isEmpty(ec.getExamPaperList())) {
+        	return;
+        }
         for (ExamPaper paper : ec.getExamPaperList()) {
             if (inExam(paper.getPaper().getId())) {//如果有考试记录
                 updatePaperInUse(paper.getPaper().getId(), 1);
@@ -1407,8 +1425,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     	examReq.setName(param.getExamName());
     	examReq.setCode(param.getExamCode());
     	GetExamResp examRes=examCloudService.getExam(examReq);
-    	if(!CallType.RANDOM_PAPER.equals(examRes.getExamBean().getCallType())) {
-    		throw new StatusException("只能对随机抽题的考试创建调卷规则");
+    	if(ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
+    		throw new StatusException("不能对离线考试创建调卷规则");
     	}
     	// 从考务查询改考试下的所有课程
         List<ExamCourseRelationBean> courseInfoList = new ArrayList<>();
@@ -1442,21 +1460,19 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     		throw new StatusException("存在多个启用的随机抽题模板");
     	}
     	ExtractConfig extractConfig=findConfig(examBean.getId(), course.getCourseCode());
-    	if(extractConfig!=null) {
-    		extractConfig.setRandomPaperId(rps.get(0).getId());
-    	}else {
+    	if(extractConfig==null) {
 	    	extractConfig=new ExtractConfig();
 	    	extractConfig.setExamId(examBean.getId());
-	    	extractConfig.setCallType(CallType.RANDOM_PAPER);
 	    	extractConfig.setOrgId(rootOrgId.toString());
 	    	extractConfig.setExamName(examBean.getName());
 	    	extractConfig.setExamType(examBean.getExamType());
 	    	extractConfig.setCourseCode(course.getCourseCode());
 	        extractConfig.setCourse(of(course,rootOrgId));
 	        extractConfig.setCourseName(course.getCourseName());
-			extractConfig.setRandomPaperId(rps.get(0).getId());
-			extractConfig.setPlayTime(1);
     	}
+    	extractConfig.setRandomPaperId(rps.get(0).getId());
+    	extractConfig.setCallType(CallType.RANDOM_PAPER);
+		extractConfig.setPlayTime(1);
         extractConfigRepo.save(extractConfig);
      // 清除缓存
  		extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());
@@ -1497,8 +1513,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     	examReq.setName(req.getExamName());
     	examReq.setCode(req.getExamCode());
     	GetExamResp examRes=examCloudService.getExam(examReq);
-    	if(!CallType.RANDOM_PAPER.equals(examRes.getExamBean().getCallType())) {
-    		throw new StatusException("只能对随机抽题的考试创建调卷规则");
+    	if(ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
+    		throw new StatusException("不能对离线考试创建调卷规则");
     	}
     	Course course = courseService.getCourse(rootOrgId, req.getCourseCode());
     	GetExamCourseReq settingReq = new GetExamCourseReq();
@@ -1516,21 +1532,19 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     		throw new StatusException("存在多个启用的随机抽题模板");
     	}
     	ExtractConfig extractConfig=findConfig(examRes.getExamBean().getId(), req.getCourseCode());
-    	if(extractConfig!=null) {
-    		extractConfig.setRandomPaperId(rps.get(0).getId());
-    	}else {
+    	if(extractConfig==null) {
 	    	extractConfig=new ExtractConfig();
 	    	extractConfig.setExamId(examRes.getExamBean().getId());
-	    	extractConfig.setCallType(CallType.RANDOM_PAPER);
 	    	extractConfig.setOrgId(rootOrgId.toString());
 	    	extractConfig.setExamName(examRes.getExamBean().getName());
 	    	extractConfig.setExamType(examRes.getExamBean().getExamType());
 	    	extractConfig.setCourseCode(course.getCode());
 	        extractConfig.setCourse(course);
 	        extractConfig.setCourseName(course.getName());
-			extractConfig.setRandomPaperId(rps.get(0).getId());
-			extractConfig.setPlayTime(1);
     	}
+    	extractConfig.setCallType(CallType.RANDOM_PAPER);
+    	extractConfig.setRandomPaperId(rps.get(0).getId());
+		extractConfig.setPlayTime(1);
         extractConfigRepo.save(extractConfig);
      // 清除缓存
  		extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());