deason 1 年之前
父节点
当前提交
97276ee2bf

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

@@ -1,39 +1,5 @@
 package cn.com.qmth.examcloud.core.questions.service.impl;
 package cn.com.qmth.examcloud.core.questions.service.impl;
 
 
-import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.DEFAULT_TIME_OUT;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-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;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.data.mongodb.core.query.Query;
-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 cn.com.qmth.examcloud.api.commons.enums.CallType;
 import cn.com.qmth.examcloud.api.commons.enums.CallType;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.api.commons.security.bean.UserDataRule;
 import cn.com.qmth.examcloud.api.commons.security.bean.UserDataRule;
@@ -48,39 +14,15 @@ import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
 import cn.com.qmth.examcloud.core.questions.base.Model;
 import cn.com.qmth.examcloud.core.questions.base.Model;
 import cn.com.qmth.examcloud.core.questions.base.em.enums.ExamType;
 import cn.com.qmth.examcloud.core.questions.base.em.enums.ExamType;
 import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
 import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
-import cn.com.qmth.examcloud.core.questions.base.question.PaperDetailDto;
-import cn.com.qmth.examcloud.core.questions.base.question.PaperDetailUnitDto;
-import cn.com.qmth.examcloud.core.questions.base.question.PaperDto;
-import cn.com.qmth.examcloud.core.questions.base.question.QuesOptionDto;
-import cn.com.qmth.examcloud.core.questions.base.question.QuestionDto;
-import cn.com.qmth.examcloud.core.questions.base.question.SubQuestionDto;
+import cn.com.qmth.examcloud.core.questions.base.question.*;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
-import cn.com.qmth.examcloud.core.questions.dao.AudioTimeConfigRepo;
-import cn.com.qmth.examcloud.core.questions.dao.ExtractConfigRepo;
-import cn.com.qmth.examcloud.core.questions.dao.PaperDetailRepo;
-import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
-import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
-import cn.com.qmth.examcloud.core.questions.dao.RandomPaperRepo;
-import cn.com.qmth.examcloud.core.questions.dao.entity.AudioTimeConfig;
-import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
-import cn.com.qmth.examcloud.core.questions.dao.entity.ExamPaper;
-import cn.com.qmth.examcloud.core.questions.dao.entity.ExtractConfig;
-import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
-import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionAudio;
-import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaper;
+import cn.com.qmth.examcloud.core.questions.dao.*;
+import cn.com.qmth.examcloud.core.questions.dao.entity.*;
 import cn.com.qmth.examcloud.core.questions.service.ExtractConfigService;
 import cn.com.qmth.examcloud.core.questions.service.ExtractConfigService;
 import cn.com.qmth.examcloud.core.questions.service.QuesService;
 import cn.com.qmth.examcloud.core.questions.service.QuesService;
 import cn.com.qmth.examcloud.core.questions.service.QuestionAudioService;
 import cn.com.qmth.examcloud.core.questions.service.QuestionAudioService;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
-import cn.com.qmth.examcloud.core.questions.service.bean.CouresInfo;
-import cn.com.qmth.examcloud.core.questions.service.bean.PaperDetailDtoAssembler;
-import cn.com.qmth.examcloud.core.questions.service.bean.PaperDetailUnitDtoAssembler;
-import cn.com.qmth.examcloud.core.questions.service.bean.PaperDtoAssembler;
-import cn.com.qmth.examcloud.core.questions.service.bean.SubQuestionDtoAssembler;
+import cn.com.qmth.examcloud.core.questions.service.bean.*;
 import cn.com.qmth.examcloud.core.questions.service.bean.extract.SaveRandomPaperExtractConfigForToolDomain;
 import cn.com.qmth.examcloud.core.questions.service.bean.extract.SaveRandomPaperExtractConfigForToolDomain;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperListVo;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperListVo;
 import cn.com.qmth.examcloud.core.questions.service.cache.ExtractConfigCache;
 import cn.com.qmth.examcloud.core.questions.service.cache.ExtractConfigCache;
@@ -96,6 +38,32 @@ import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
 import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
 import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.bson.types.ObjectId;
+import org.nlpcn.commons.lang.util.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+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 java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.DEFAULT_TIME_OUT;
 
 
 /**
 /**
  * @author chenken
  * @author chenken
@@ -152,11 +120,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 
 
     @Autowired
     @Autowired
     private RedisClient redisClient;
     private RedisClient redisClient;
+
     @Autowired
     @Autowired
     private ExtractConfigCache extractConfigCache;
     private ExtractConfigCache extractConfigCache;
-    /*
-     * @Autowired private PaperDetailUnitNativeRepo detailUnitNativeRepo;
-     */
 
 
     @Autowired
     @Autowired
     private ExamCloudService examCloudService;
     private ExamCloudService examCloudService;
@@ -166,29 +132,32 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 
 
     @Autowired
     @Autowired
     private ExamRecordDataCloudService studentExamRecordCloudService;
     private ExamRecordDataCloudService studentExamRecordCloudService;
-    
+
     @Autowired
     @Autowired
     private RandomPaperService randomPaperService;
     private RandomPaperService randomPaperService;
-    
+
     @Override
     @Override
     public ExtractConfig findConfig(ExtractConfig condition) {
     public ExtractConfig findConfig(ExtractConfig condition) {
         if (condition.getExamId() == null) {
         if (condition.getExamId() == null) {
             return null;
             return null;
         }
         }
+
         if (StringUtils.isBlank(condition.getCourseCode())) {
         if (StringUtils.isBlank(condition.getCourseCode())) {
             return null;
             return null;
         }
         }
+
         Query query = new Query();
         Query query = new Query();
-        if (!StringUtils.isBlank(condition.getOrgId())) {
-            query.addCriteria(Criteria.where("orgId").is(condition.getOrgId()));
-        }
         query.addCriteria(Criteria.where("examId").is(condition.getExamId()));
         query.addCriteria(Criteria.where("examId").is(condition.getExamId()));
         query.addCriteria(Criteria.where("courseCode").is(condition.getCourseCode()));
         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);
+        if (StringUtils.isNotBlank(condition.getOrgId())) {
+            query.addCriteria(Criteria.where("orgId").is(condition.getOrgId()));
         }
         }
-        return tempConfig;
+
+        ExtractConfig extractConfig = this.mongoTemplate.findOne(query, ExtractConfig.class);
+        if (extractConfig != null && extractConfig.getCallType() == null) {
+            extractConfig.setCallType(CallType.WHOLE_SET);
+        }
+        return extractConfig;
     }
     }
 
 
     @Override
     @Override
@@ -212,7 +181,7 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 
 
     @Override
     @Override
     public List<ExamPaper> saveExtractConfig(ExtractConfig extractConfig, User user) {
     public List<ExamPaper> saveExtractConfig(ExtractConfig extractConfig, User user) {
-    	Course course = courseService.getCourse(Long.valueOf(extractConfig.getOrgId()), extractConfig.getCourseCode());
+        Course course = courseService.getCourse(Long.valueOf(extractConfig.getOrgId()), extractConfig.getCourseCode());
         extractConfig.setCourse(course);
         extractConfig.setCourse(course);
         extractConfig.setCourseName(course.getName());
         extractConfig.setCourseName(course.getName());
         List<ExamPaper> examPapers = extractConfig.getExamPaperList();
         List<ExamPaper> examPapers = extractConfig.getExamPaperList();
@@ -220,9 +189,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
             ExamPaper examPaper = examPapers.get(i);
             ExamPaper examPaper = examPapers.get(i);
             Paper paper = examPaper.getPaper();
             Paper paper = examPaper.getPaper();
             paper = Model.of(paperRepo.findById(paper.getId()));
             paper = Model.of(paperRepo.findById(paper.getId()));
-            if(!extractConfig.getCourse().getOrgId().equals(paper.getCourse().getOrgId())
-            		||!extractConfig.getCourse().getCode().equals(paper.getCourse().getCode())) {
-            	throw new StatusException("试卷的课程和当前课程不匹配");
+            if (!extractConfig.getCourse().getOrgId().equals(paper.getCourse().getOrgId())
+                    || !extractConfig.getCourse().getCode().equals(paper.getCourse().getCode())) {
+                throw new StatusException("试卷的课程和当前课程不匹配");
             }
             }
             examPaper.setPaper(paper);
             examPaper.setPaper(paper);
             if (ExamType.OFFLINE.name().equals(extractConfig.getExamType())) {
             if (ExamType.OFFLINE.name().equals(extractConfig.getExamType())) {
@@ -237,16 +206,16 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
         disposeNowPaper(extractConfig.getId());
         disposeNowPaper(extractConfig.getId());
         return examPapers;
         return examPapers;
     }
     }
-    
+
     @Transactional
     @Transactional
     @Override
     @Override
     public void saveExtractConfigForRandomPaper(ExtractConfig extractConfig) {
     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("离线考试不能随机抽题");
-    	}
+        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());
         Course course = courseService.getCourse(Long.valueOf(extractConfig.getOrgId()), extractConfig.getCourseCode());
         extractConfig.setCourse(course);
         extractConfig.setCourse(course);
         extractConfig.setCourseName(course.getName());
         extractConfig.setCourseName(course.getName());
@@ -256,36 +225,36 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
         query.setCourseId(Long.parseLong(course.getId()));
         query.setCourseId(Long.parseLong(course.getId()));
         Example<RandomPaper> queryExample = Example.of(query);
         Example<RandomPaper> queryExample = Example.of(query);
         boolean exists = randomPaperRepo.exists(queryExample);
         boolean exists = randomPaperRepo.exists(queryExample);
-        if(!exists){
+        if (!exists) {
             LOG.warn("随机抽题模板选择错误,与当前课程不匹配! courseId:{} randomPaperId:{}", course.getId(), extractConfig.getRandomPaperId());
             LOG.warn("随机抽题模板选择错误,与当前课程不匹配! courseId:{} randomPaperId:{}", course.getId(), extractConfig.getRandomPaperId());
             throw new StatusException("500", "随机抽题模板选择错误,与当前课程不匹配!");
             throw new StatusException("500", "随机抽题模板选择错误,与当前课程不匹配!");
         }
         }
 
 
-		// 新增,id为空
-		if (StringUtils.isBlank(extractConfig.getId())) {
-			// 先查询
-			ExtractConfig tempConfig = this.findConfig(extractConfig);
-			if (tempConfig != null) {
-				tempConfig.setRandomPaperId(extractConfig.getRandomPaperId());
-				tempConfig.setPlayTime(extractConfig.getPlayTime());
-				tempConfig.setCourseName(course.getName());
-				tempConfig.setCourse(course);
-				tempConfig.setCallType(extractConfig.getCallType());
-				extractConfig=tempConfig;
-			}
-		}else {
-			ExtractConfig tempConfig = Model.of(extractConfigRepo.findById(extractConfig.getId()));
-			tempConfig.setRandomPaperId(extractConfig.getRandomPaperId());
-			tempConfig.setPlayTime(extractConfig.getPlayTime());
-			tempConfig.setCourseName(course.getName());
-			tempConfig.setCourse(course);
-			tempConfig.setCallType(extractConfig.getCallType());
-			extractConfig=tempConfig;
-		}
-		if (StringUtils.isNotBlank(extractConfig.getId())) {
+        // 新增,id为空
+        if (StringUtils.isBlank(extractConfig.getId())) {
+            // 先查询
+            ExtractConfig tempConfig = this.findConfig(extractConfig);
+            if (tempConfig != null) {
+                tempConfig.setRandomPaperId(extractConfig.getRandomPaperId());
+                tempConfig.setPlayTime(extractConfig.getPlayTime());
+                tempConfig.setCourseName(course.getName());
+                tempConfig.setCourse(course);
+                tempConfig.setCallType(extractConfig.getCallType());
+                extractConfig = tempConfig;
+            }
+        } else {
+            ExtractConfig tempConfig = Model.of(extractConfigRepo.findById(extractConfig.getId()));
+            tempConfig.setRandomPaperId(extractConfig.getRandomPaperId());
+            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());
             disposeOldPaper(extractConfig.getId());
         }
         }
-		extractConfig.setExamPaperList(null);
+        extractConfig.setExamPaperList(null);
         extractConfigRepo.save(extractConfig);
         extractConfigRepo.save(extractConfig);
     }
     }
 
 
@@ -296,8 +265,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
      */
      */
     private void disposeOldPaper(String extractConfigId) {
     private void disposeOldPaper(String extractConfigId) {
         ExtractConfig ec = Model.of(extractConfigRepo.findById(extractConfigId));
         ExtractConfig ec = Model.of(extractConfigRepo.findById(extractConfigId));
-        if(CollectionUtils.isEmpty(ec.getExamPaperList())) {
-        	return;
+        if (CollectionUtils.isEmpty(ec.getExamPaperList())) {
+            return;
         }
         }
         for (ExamPaper paper : ec.getExamPaperList()) {
         for (ExamPaper paper : ec.getExamPaperList()) {
             if (inExam(paper.getPaper().getId())) {//如果有考试记录
             if (inExam(paper.getPaper().getId())) {//如果有考试记录
@@ -1413,28 +1382,28 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 
 
         return extractConfigList;
         return extractConfigList;
     }
     }
-    
+
     @Transactional
     @Transactional
     @Override
     @Override
     public void saveExtractConfigForRandomPaperByOuter(SaveRandomPaperExtractConfigReq param) {
     public void saveExtractConfigForRandomPaperByOuter(SaveRandomPaperExtractConfigReq param) {
-    	if(param.getRootOrgId()==null) {
-    		throw new StatusException("rootOrgId不能为空");
-    	}
-    	GetExamReq examReq=new GetExamReq();
-    	examReq.setRootOrgId(param.getRootOrgId());
-    	examReq.setName(param.getExamName());
-    	examReq.setCode(param.getExamCode());
-    	GetExamResp examRes=examCloudService.getExam(examReq);
-    	if(ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
-    		throw new StatusException("不能对离线考试创建调卷规则");
-    	}
-
-    	// 从考务查询改考试下的所有课程
+        if (param.getRootOrgId() == null) {
+            throw new StatusException("rootOrgId不能为空");
+        }
+        GetExamReq examReq = new GetExamReq();
+        examReq.setRootOrgId(param.getRootOrgId());
+        examReq.setName(param.getExamName());
+        examReq.setCode(param.getExamCode());
+        GetExamResp examRes = examCloudService.getExam(examReq);
+        if (ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
+            throw new StatusException("不能对离线考试创建调卷规则");
+        }
+
+        // 从考务查询改考试下的所有课程
         List<ExamCourseRelationBean> courseInfoList = new ArrayList<>();
         List<ExamCourseRelationBean> courseInfoList = new ArrayList<>();
         GetExamCourseListReq req = new GetExamCourseListReq();
         GetExamCourseListReq req = new GetExamCourseListReq();
         req.setExamId(examRes.getExamBean().getId());
         req.setExamId(examRes.getExamBean().getId());
         Long start = 1L;
         Long start = 1L;
-        for(;;) {
+        for (; ; ) {
             req.setStart(start);
             req.setStart(start);
             GetExamCourseListResp resp = examCloudService.getExamCourseList(req);
             GetExamCourseListResp resp = examCloudService.getExamCourseList(req);
             courseInfoList.addAll(resp.getRelationList());
             courseInfoList.addAll(resp.getRelationList());
@@ -1445,57 +1414,59 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
             }
             }
         }
         }
         if (CollectionUtils.isEmpty(courseInfoList)) {
         if (CollectionUtils.isEmpty(courseInfoList)) {
-            LOG.warn("==>当前考试下课程列表为空!rootOrgId:{} examId:{}",examReq.getRootOrgId(),req.getExamId());
-        	throw new StatusException("请先同步考生再创建调卷规则");
+            LOG.warn("==>当前考试下课程列表为空!rootOrgId:{} examId:{}", examReq.getRootOrgId(), req.getExamId());
+            throw new StatusException("请先同步考生再创建调卷规则");
         }
         }
 
 
-        for(ExamCourseRelationBean course:courseInfoList) {
-        	createByCourse(param.getRootOrgId(), examRes.getExamBean(), course);
+        for (ExamCourseRelationBean course : courseInfoList) {
+            createByCourse(param.getRootOrgId(), examRes.getExamBean(), course);
         }
         }
     }
     }
-    
-    private void createByCourse(Long rootOrgId,ExamBean examBean,ExamCourseRelationBean course) {
-    	List<RandomPaperListVo> rps=randomPaperService.getList(rootOrgId,course.getCourseId());
-    	if(CollectionUtils.isEmpty(rps)) {
-            LOG.warn("==>没有启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,examBean.getId(),course.getCourseCode());
-    		throw new StatusException(course.getCourseName()+",没有启用的随机抽题模板");
-    	}
-    	if(rps.size()>1) {
-            LOG.warn("==>存在多个启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,examBean.getId(),course.getCourseCode());
-    		throw new StatusException("存在多个启用的随机抽题模板");
-    	}
-
-    	ExtractConfig extractConfig=findConfig(examBean.getId(), course.getCourseCode());
-    	if(extractConfig==null) {
-	    	extractConfig=new ExtractConfig();
-	    	extractConfig.setExamId(examBean.getId());
-	    	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.setCallType(CallType.RANDOM_PAPER);
-		extractConfig.setPlayTime(1);
+
+    private void createByCourse(Long rootOrgId, ExamBean examBean, ExamCourseRelationBean course) {
+        List<RandomPaperListVo> rps = randomPaperService.getList(rootOrgId, course.getCourseId());
+        if (CollectionUtils.isEmpty(rps)) {
+            LOG.warn("==>没有启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, examBean.getId(), course.getCourseCode());
+            throw new StatusException(course.getCourseName() + ",没有启用的随机抽题模板");
+        }
+        if (rps.size() > 1) {
+            LOG.warn("==>存在多个启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, examBean.getId(), course.getCourseCode());
+            throw new StatusException("存在多个启用的随机抽题模板");
+        }
+
+        ExtractConfig extractConfig = findConfig(examBean.getId(), course.getCourseCode());
+        if (extractConfig == null) {
+            extractConfig = new ExtractConfig();
+            extractConfig.setExamId(examBean.getId());
+            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.setCallType(CallType.RANDOM_PAPER);
+        extractConfig.setPlayTime(1);
         extractConfigRepo.save(extractConfig);
         extractConfigRepo.save(extractConfig);
-        LOG.warn("==>创建随机抽卷调卷规则成功!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,examBean.getId(),course.getCourseCode());
+        LOG.warn("==>创建随机抽卷调卷规则成功!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, examBean.getId(), course.getCourseCode());
 
 
         // 清除缓存
         // 清除缓存
- 		extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());
+        extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());
     }
     }
-    private Course of(ExamCourseRelationBean course,Long rootOrgId) {
-    	Course c=new Course();
-    	c.setCode(course.getCourseCode());
-    	c.setId(course.getCourseId().toString());
-    	c.setEnable(course.getCourseEnable()==null?"false":course.getCourseEnable().toString());
-    	c.setName(course.getCourseName());
-    	c.setLevel(course.getCourseLevel());
-    	c.setOrgId(rootOrgId.toString());
-    	return c;
+
+    private Course of(ExamCourseRelationBean course, Long rootOrgId) {
+        Course c = new Course();
+        c.setCode(course.getCourseCode());
+        c.setId(course.getCourseId().toString());
+        c.setEnable(course.getCourseEnable() == null ? "false" : course.getCourseEnable().toString());
+        c.setName(course.getCourseName());
+        c.setLevel(course.getCourseLevel());
+        c.setOrgId(rootOrgId.toString());
+        return c;
     }
     }
-    private ExtractConfig findConfig(Long examId,String courseCode) {
+
+    private ExtractConfig findConfig(Long examId, String courseCode) {
         if (examId == null) {
         if (examId == null) {
             return null;
             return null;
         }
         }
@@ -1510,56 +1481,57 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
     }
     }
 
 
     @Transactional
     @Transactional
-	@Override
-	public void saveExtractConfigForRandomPaper(SaveRandomPaperExtractConfigForToolDomain req) {
-    	if(req.getExamId()==null) {
-    		throw new StatusException("ExamId不能为空");
-    	}
-    	GetExamReq examReq=new GetExamReq();
-    	examReq.setId(req.getExamId());
-    	GetExamResp examRes=examCloudService.getExam(examReq);
-    	if(ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
-    		throw new StatusException("不能对离线考试创建调卷规则");
-    	}
-    	Long rootOrgId=examRes.getExamBean().getRootOrgId();
-    	Course course = courseService.getCourse(rootOrgId, req.getCourseCode());
-    	GetExamCourseReq settingReq = new GetExamCourseReq();
+    @Override
+    public void saveExtractConfigForRandomPaper(SaveRandomPaperExtractConfigForToolDomain req) {
+        if (req.getExamId() == null) {
+            throw new StatusException("ExamId不能为空");
+        }
+        GetExamReq examReq = new GetExamReq();
+        examReq.setId(req.getExamId());
+        GetExamResp examRes = examCloudService.getExam(examReq);
+        if (ExamType.OFFLINE.name().equals(examRes.getExamBean().getExamType())) {
+            throw new StatusException("不能对离线考试创建调卷规则");
+        }
+        Long rootOrgId = examRes.getExamBean().getRootOrgId();
+        Course course = courseService.getCourse(rootOrgId, req.getCourseCode());
+        GetExamCourseReq settingReq = new GetExamCourseReq();
         settingReq.setExamId(examRes.getExamBean().getId());
         settingReq.setExamId(examRes.getExamBean().getId());
         settingReq.setCourseId(Long.valueOf(course.getId()));
         settingReq.setCourseId(Long.valueOf(course.getId()));
         GetExamCourseResp settingResp = examCloudService.getExamCourseSetting(settingReq);
         GetExamCourseResp settingResp = examCloudService.getExamCourseSetting(settingReq);
 
 
-        if(settingResp.getBean()==null) {
-            LOG.warn("-->当前考试课程不存在!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,req.getExamId(),req.getCourseCode());
-        	throw new StatusException("请先同步考生后再创建相应课程的调卷规则");
-        }
-    	List<RandomPaperListVo> rps=randomPaperService.getList(rootOrgId, Long.valueOf(course.getId()));
-    	if(CollectionUtils.isEmpty(rps)) {
-            LOG.warn("-->没有启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,req.getExamId(),req.getCourseCode());
-    		throw new StatusException("没有启用的随机抽题模板");
-    	}
-    	if(rps.size()>1) {
-            LOG.warn("-->存在多个启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,req.getExamId(),req.getCourseCode());
-    		throw new StatusException("存在多个启用的随机抽题模板");
-    	}
-
-    	ExtractConfig extractConfig=findConfig(examRes.getExamBean().getId(), req.getCourseCode());
-    	if(extractConfig==null) {
-	    	extractConfig=new ExtractConfig();
-	    	extractConfig.setExamId(examRes.getExamBean().getId());
-	    	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.setCallType(CallType.RANDOM_PAPER);
-    	extractConfig.setRandomPaperId(rps.get(0).getId());
-		extractConfig.setPlayTime(1);
+        if (settingResp.getBean() == null) {
+            LOG.warn("-->当前考试课程不存在!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, req.getExamId(), req.getCourseCode());
+            throw new StatusException("请先同步考生后再创建相应课程的调卷规则");
+        }
+        List<RandomPaperListVo> rps = randomPaperService.getList(rootOrgId, Long.valueOf(course.getId()));
+        if (CollectionUtils.isEmpty(rps)) {
+            LOG.warn("-->没有启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, req.getExamId(), req.getCourseCode());
+            throw new StatusException("没有启用的随机抽题模板");
+        }
+        if (rps.size() > 1) {
+            LOG.warn("-->存在多个启用的随机抽题模板!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, req.getExamId(), req.getCourseCode());
+            throw new StatusException("存在多个启用的随机抽题模板");
+        }
+
+        ExtractConfig extractConfig = findConfig(examRes.getExamBean().getId(), req.getCourseCode());
+        if (extractConfig == null) {
+            extractConfig = new ExtractConfig();
+            extractConfig.setExamId(examRes.getExamBean().getId());
+            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.setCallType(CallType.RANDOM_PAPER);
+        extractConfig.setRandomPaperId(rps.get(0).getId());
+        extractConfig.setPlayTime(1);
         extractConfigRepo.save(extractConfig);
         extractConfigRepo.save(extractConfig);
-        LOG.warn("-->创建随机抽卷调卷规则成功!rootOrgId:{} examId:{} courseCode:{}",rootOrgId,req.getExamId(),req.getCourseCode());
+        LOG.warn("-->创建随机抽卷调卷规则成功!rootOrgId:{} examId:{} courseCode:{}", rootOrgId, req.getExamId(), req.getCourseCode());
 
 
         // 清除缓存
         // 清除缓存
- 		extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());
-	}
+        extractConfigCache.remove(extractConfig.getExamId(), extractConfig.getCourseCode());
+    }
+
 }
 }