xiatian 1 éve
szülő
commit
403e4fb091

+ 8 - 12
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/PaperStructService.java

@@ -6,7 +6,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -24,9 +23,6 @@ import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-
 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.commons.exception.StatusException;
@@ -59,7 +55,7 @@ public class PaperStructService {
 
     private static final Logger log = LoggerFactory.getLogger(PaperStructService.class);
 
-    private static Cache<String, PaperStructCache> localPaperStructCache = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build();
+//    private static Cache<String, PaperStructCache> localPaperStructCache = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build();
 
     private static int cacheTimeOut = 2 * 60 * 60;
 
@@ -510,14 +506,14 @@ public class PaperStructService {
     public PaperStructCache getPaperStructCacheById(String paperStructId) {
         // 组卷结构 优先从本地缓存中获取
         String key = CacheConstants.CACHE_Q_PAPER_STRUCT + paperStructId;
-        PaperStructCache ps = localPaperStructCache.getIfPresent(key);
-        if (ps != null) {
-            log.warn("从【本地缓存】中获取组卷结构! key:{}", key);
-            return ps;
-        }
+//        PaperStructCache ps = localPaperStructCache.getIfPresent(key);
+//        if (ps != null) {
+//            log.warn("从【本地缓存】中获取组卷结构! key:{}", key);
+//            return ps;
+//        }
 
         // 从redis缓存中获取
-        ps = redisClient.get(key, PaperStructCache.class, cacheTimeOut);
+        PaperStructCache ps = redisClient.get(key, PaperStructCache.class, cacheTimeOut);
         if (ps != null) {
             log.warn("从【Redis缓存】中获取抽卷模板! key:{}", key);
             return ps;
@@ -533,7 +529,7 @@ public class PaperStructService {
 
         log.warn("从【数据库】中获取抽卷模板! key:{}", key);
         redisClient.set(key, ps, cacheTimeOut);
-        localPaperStructCache.put(key, ps);
+//        localPaperStructCache.put(key, ps);
         return ps;
     }
 

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

@@ -1,5 +1,32 @@
 package cn.com.qmth.examcloud.core.questions.service.impl;
 
+import java.math.BigDecimal;
+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.stream.Collectors;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.bson.types.ObjectId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+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.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.basic.api.UserCloudService;
@@ -17,12 +44,30 @@ import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
 import cn.com.qmth.examcloud.core.questions.dao.PropertyRepo;
 import cn.com.qmth.examcloud.core.questions.dao.RandomPaperQuestionRepo;
 import cn.com.qmth.examcloud.core.questions.dao.RandomPaperRepo;
-import cn.com.qmth.examcloud.core.questions.dao.entity.*;
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailStruct;
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStruct;
+import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
+import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaper;
+import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaperQuestion;
 import cn.com.qmth.examcloud.core.questions.dao.entity.dto.CoursePropertyNumberDto;
 import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStructDto;
 import cn.com.qmth.examcloud.core.questions.service.PaperStructService;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
-import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.*;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.CreateDefaultPaperParam;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailDto;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailUnitDto;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperQuestionViewQuery;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperVo;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.QuestionDto;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperDomain;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperListVo;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperQuery;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperQuestionDto;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructInfo;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionCheckDto;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionCountInfo;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionInfo;
 import cn.com.qmth.examcloud.core.questions.service.cache.PaperDetailStructCache;
 import cn.com.qmth.examcloud.core.questions.service.cache.PaperStructCache;
 import cn.com.qmth.examcloud.core.questions.service.cache.RandomPaperCache;
@@ -38,36 +83,13 @@ import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.bson.types.ObjectId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-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.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.Resource;
-import java.math.BigDecimal;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 @Service
 public class RandomPaperServiceImpl implements RandomPaperService {
 
     private static final Logger log = LoggerFactory.getLogger(RandomPaperServiceImpl.class);
 
-    private static Cache<String, RandomPaperCache> localRandomPaperCache = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build();
+//    private static Cache<String, RandomPaperCache> localRandomPaperCache = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build();
 
     private static int cacheTimeOut = 2 * 60 * 60;
 
@@ -486,14 +508,14 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         if (us.getNoPublicDifficulty() > 0) {
             cd.setSi(sqinfo.getHardInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.HARD.getName());
+            cd.setDifficulty(QuestionDifficulty.HARD);
             cd.setNeedCount(us.getNoPublicDifficulty());
             setQuestionInfoByExactItem(cd);
         }
         if (us.getPublicDifficulty() > 0) {
             cd.setSi(sqinfo.getHardInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.HARD.getName());
+            cd.setDifficulty(QuestionDifficulty.HARD);
             cd.setNeedCount(us.getPublicDifficulty());
             setQuestionInfoByExactItem(cd);
         }
@@ -501,28 +523,28 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         if (us.getNoPublicMedium() > 0) {
             cd.setSi(sqinfo.getMediumInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.MEDIUM.getName());
+            cd.setDifficulty(QuestionDifficulty.MEDIUM);
             cd.setNeedCount(us.getNoPublicMedium());
             setQuestionInfoByExactItem(cd);
         }
         if (us.getPublicMedium() > 0) {
             cd.setSi(sqinfo.getMediumInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.MEDIUM.getName());
+            cd.setDifficulty(QuestionDifficulty.MEDIUM);
             cd.setNeedCount(us.getPublicMedium());
             setQuestionInfoByExactItem(cd);
         }
         if (us.getNoPublicSimple() > 0) {
             cd.setSi(sqinfo.getEasyInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.EASY.getName());
+            cd.setDifficulty(QuestionDifficulty.EASY);
             cd.setNeedCount(us.getNoPublicSimple());
             setQuestionInfoByExactItem(cd);
         }
         if (us.getPublicSimple() > 0) {
             cd.setSi(sqinfo.getEasyInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.EASY.getName());
+            cd.setDifficulty(QuestionDifficulty.EASY);
             cd.setNeedCount(us.getPublicSimple());
             setQuestionInfoByExactItem(cd);
         }
@@ -533,7 +555,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         RandomPaperQuestionDto rq = new RandomPaperQuestionDto();
         rq.setUnitScore(cd.getUnitScore());
         rq.setDetailNumber(cd.getDetailNumber());
-        rq.setKey(cd.getIndex() + "-" + cd.getPub() + "-" + cd.getDifficulty());
+        rq.setKey(cd.getIndex() + "-" + cd.getPub() + "-" + cd.getDifficulty().name());
         si.getQuestionInfo().add(rq);
         if (CollectionUtils.isNotEmpty(cd.getQuestionList())) {
             Iterator<QuestionDto> it = cd.getQuestionList().iterator();
@@ -564,14 +586,14 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         if (cp.getNoPublicDifficulty() > 0) {
             cd.setSi(sqinfo.getHardInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.HARD.getName());
+            cd.setDifficulty(QuestionDifficulty.HARD);
             cd.setNeedCount(cp.getNoPublicDifficulty());
             setQuestionInfoByBlueProp(cd);
         }
         if (cp.getPublicDifficulty() > 0) {
             cd.setSi(sqinfo.getHardInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.HARD.getName());
+            cd.setDifficulty(QuestionDifficulty.HARD);
             cd.setNeedCount(cp.getPublicDifficulty());
             setQuestionInfoByBlueProp(cd);
         }
@@ -579,28 +601,28 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         if (cp.getNoPublicMedium() > 0) {
             cd.setSi(sqinfo.getMediumInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.MEDIUM.getName());
+            cd.setDifficulty(QuestionDifficulty.MEDIUM);
             cd.setNeedCount(cp.getNoPublicMedium());
             setQuestionInfoByBlueProp(cd);
         }
         if (cp.getPublicMedium() > 0) {
             cd.setSi(sqinfo.getMediumInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.MEDIUM.getName());
+            cd.setDifficulty(QuestionDifficulty.MEDIUM);
             cd.setNeedCount(cp.getPublicMedium());
             setQuestionInfoByBlueProp(cd);
         }
         if (cp.getNoPublicSimple() > 0) {
             cd.setSi(sqinfo.getEasyInfo());
             cd.setPub(false);
-            cd.setDifficulty(QuestionDifficulty.EASY.getName());
+            cd.setDifficulty(QuestionDifficulty.EASY);
             cd.setNeedCount(cp.getNoPublicSimple());
             setQuestionInfoByBlueProp(cd);
         }
         if (cp.getPublicSimple() > 0) {
             cd.setSi(sqinfo.getEasyInfo());
             cd.setPub(true);
-            cd.setDifficulty(QuestionDifficulty.EASY.getName());
+            cd.setDifficulty(QuestionDifficulty.EASY);
             cd.setNeedCount(cp.getPublicSimple());
             setQuestionInfoByBlueProp(cd);
         }
@@ -637,17 +659,17 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         }
     }
 
-    private String getExactErrmsg(Integer index, Integer detailNumber, Boolean pub, String difficulty) {
+    private String getExactErrmsg(Integer index, Integer detailNumber, Boolean pub, QuestionDifficulty difficulty) {
         String pubstr;
         if (pub) {
             pubstr = "公开";
         } else {
             pubstr = "非公开";
         }
-        return "第" + detailNumber + "大题 " + "第" + index + "题型结构 " + pubstr + "-" + difficulty + "题源数量不满足";
+        return "第" + detailNumber + "大题 " + "第" + index + "题型结构 " + pubstr + "-" + difficulty.getName() + "题源数量不满足";
     }
 
-    private String getBlueErrmsg(Integer detailNumber, String pproid, String proid, Boolean pub, String difficulty) {
+    private String getBlueErrmsg(Integer detailNumber, String pproid, String proid, Boolean pub, QuestionDifficulty difficulty) {
         String pubstr;
         if (pub) {
             pubstr = "公开";
@@ -658,20 +680,20 @@ public class RandomPaperServiceImpl implements RandomPaperService {
             // 有一级 和 二级
             Property fp = Model.of(propertyRepo.findById(pproid));
             Property sp = Model.of(propertyRepo.findById(proid));
-            return "第" + detailNumber + "大题 " + fp.getName() + "-" + sp.getName() + "-" + pubstr + "-" + difficulty
+            return "第" + detailNumber + "大题 " + fp.getName() + "-" + sp.getName() + "-" + pubstr + "-" + difficulty.getName()
                     + "题源数量不满足";
         } else {
             // 有一级 无 二级
             Property fp = Model.of(propertyRepo.findById(proid));
-            return "第" + detailNumber + "大题 " + fp.getName() + "-" + pubstr + "-" + difficulty + "题源数量不满足";
+            return "第" + detailNumber + "大题 " + fp.getName() + "-" + pubstr + "-" + difficulty.getName() + "题源数量不满足";
         }
     }
 
-    private boolean checkExactQuesType(List<String> quesNames, QuesStructType st, Boolean pub, String difficulty,
+    private boolean checkExactQuesType(List<String> quesNames, QuesStructType st, Boolean pub, QuestionDifficulty difficulty,
                                        QuestionDto question) {
         if (CollectionUtils.isNotEmpty(quesNames)) {
             if (quesNames.contains(question.getQuesName()) && st.equals(question.getQuestionType())) {
-                if (question.getPublicity().equals(pub) && question.getDifficulty().equals(difficulty)) {
+                if (question.getPublicity().equals(pub) && QuestionDifficulty.getByName(question.getDifficulty()).equals(difficulty)) {
                     return true;
                 }
             }
@@ -708,15 +730,15 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         return units;
     }
 
-    private String bulidPropertyGroupByBlueStruct(String pproid, String proid, Boolean pub, String difficulty) {
+    private String bulidPropertyGroupByBlueStruct(String pproid, String proid, Boolean pub, QuestionDifficulty difficulty) {
         String propertyGroup = null;
         // 获取试题关联的多组属性
         if (StringUtils.isNotBlank(pproid) && !"0".equals(pproid)) {
             // 有一级 和 二级
-            propertyGroup = pproid + "-" + proid + "-" + pub + "-" + difficulty;
+            propertyGroup = pproid + "-" + proid + "-" + pub + "-" + difficulty.name();
         } else {
             // 有一级 无 二级
-            propertyGroup = proid + "-" + pub + "-" + difficulty;
+            propertyGroup = proid + "-" + pub + "-" + difficulty.name();
         }
         return propertyGroup;
     }
@@ -733,17 +755,17 @@ public class RandomPaperServiceImpl implements RandomPaperService {
                     if (quesProperty.getSecondProperty().getId() == null
                             || StringUtils.isBlank(String.valueOf(quesProperty.getSecondProperty().getId()))) {
                         propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
-                                + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
+                                + String.valueOf(question.getPublicity()) + "-" + QuestionDifficulty.getByName(question.getDifficulty()).name();
                     } else {
                         propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
                                 + String.valueOf(quesProperty.getSecondProperty().getId()) + "-"
-                                + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
+                                + String.valueOf(question.getPublicity()) + "-" + QuestionDifficulty.getByName(question.getDifficulty()).name();
                     }
                     propertyGroups.add(propertyGroup);
                 } else {
                     // 有一级 无 二级
                     propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
-                            + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
+                            + String.valueOf(question.getPublicity()) + "-" + QuestionDifficulty.getByName(question.getDifficulty()).name();
                     propertyGroups.add(propertyGroup);
                 }
             }
@@ -810,6 +832,8 @@ public class RandomPaperServiceImpl implements RandomPaperService {
             randomPaperQuestionRepo.saveAll(rqs);
             String key = CacheConstants.CACHE_Q_RANDOM_PAPER + e.getId();
             redisClient.delete(key);
+            String questionKey = CacheConstants.CACHE_Q_RANDOM_PAPER_QUESTION + e.getId();
+            redisClient.delete(questionKey);
         }
         clearQuestionIds(ret);
         return ret;
@@ -1020,14 +1044,14 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         CoursePropertyNumberDto cp = param.getCp();
         if (cp.getNoPublicDifficulty() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), false, QuestionDifficulty.HARD.getName());
+                    cp.getPropertyId(), false, QuestionDifficulty.HARD);
             param.setKey(key);
             param.setUnitCount(cp.getNoPublicDifficulty());
             createUnit(param);
         }
         if (cp.getPublicDifficulty() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), true, QuestionDifficulty.HARD.getName());
+                    cp.getPropertyId(), true, QuestionDifficulty.HARD);
             param.setKey(key);
             param.setUnitCount(cp.getPublicDifficulty());
             createUnit(param);
@@ -1035,39 +1059,48 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 
         if (cp.getNoPublicMedium() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), false, QuestionDifficulty.MEDIUM.getName());
+                    cp.getPropertyId(), false, QuestionDifficulty.MEDIUM);
             param.setKey(key);
             param.setUnitCount(cp.getNoPublicMedium());
             createUnit(param);
         }
         if (cp.getPublicMedium() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), true, QuestionDifficulty.MEDIUM.getName());
+                    cp.getPropertyId(), true, QuestionDifficulty.MEDIUM);
             param.setKey(key);
             param.setUnitCount(cp.getPublicMedium());
             createUnit(param);
         }
         if (cp.getNoPublicSimple() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), false, QuestionDifficulty.EASY.getName());
+                    cp.getPropertyId(), false, QuestionDifficulty.EASY);
             param.setKey(key);
             param.setUnitCount(cp.getNoPublicSimple());
             createUnit(param);
         }
         if (cp.getPublicSimple() > 0) {
             String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
-                    cp.getPropertyId(), true, QuestionDifficulty.EASY.getName());
+                    cp.getPropertyId(), true, QuestionDifficulty.EASY);
             param.setKey(key);
             param.setUnitCount(cp.getPublicSimple());
             createUnit(param);
         }
     }
+    
+    private List<Integer> getIndexList(Integer count){
+    	List<Integer> ret=new ArrayList<>();
+    	for (int i = 0; i < count; i++) {
+    		ret.add(count);
+    	}
+    	return ret;
+    }
 
     private void createUnit(CreateDefaultPaperParam param) {
-        List<RandomPaperQuestion> rpqs = param.getRp().getQuestionMap().get(param.getKey());
-        Collections.shuffle(rpqs);
+        Integer count = param.getRp().getQuestionMap().get(param.getKey());
+        List<Integer> list=getIndexList(count);
+        Collections.shuffle(list);
         for (int i = 0; i < param.getUnitCount(); i++) {
-            RandomPaperQuestion rpq = rpqs.get(i);
+            RandomPaperQuestion rpq = getRandomPaperQuestionCacheById(param.getRp().getId(), param.getKey(), list.get(i));
             DefaultQuestionStructureWrapper qw = new DefaultQuestionStructureWrapper();
             param.getUnits().add(qw);
             qw.setLimitedPlayTimes(param.getPlayTime());
@@ -1135,15 +1168,17 @@ public class RandomPaperServiceImpl implements RandomPaperService {
     private RandomPaperCache getRandomPaperTemplateCacheById(String randomPaperId) {
         // 抽卷模板 优先从本地缓存中获取
         String key = CacheConstants.CACHE_Q_RANDOM_PAPER + randomPaperId;
-        RandomPaperCache rp = localRandomPaperCache.getIfPresent(key);
-        if (rp != null) {
-            log.warn("从【本地缓存】中获取抽卷模板! key:{}", key);
-            return rp;
-        }
+//        RandomPaperCache rp = localRandomPaperCache.getIfPresent(key);
+//        if (rp != null) {
+//            log.warn("从【本地缓存】中获取抽卷模板! key:{}", key);
+//            return rp;
+//        }
 
         // 从redis缓存中获取
-        rp = redisClient.get(key, RandomPaperCache.class, cacheTimeOut);
+        RandomPaperCache rp = redisClient.get(key, RandomPaperCache.class, cacheTimeOut);
         if (rp != null) {
+        	String questionKey = CacheConstants.CACHE_Q_RANDOM_PAPER_QUESTION + randomPaperId;
+        	redisClient.expire(questionKey, cacheTimeOut);
             log.warn("从【Redis缓存】中获取抽卷模板! key:{}", key);
             return rp;
         }
@@ -1161,22 +1196,60 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 
         log.warn("从【数据库】中获取抽卷模板! key:{}", key);
         rp = new RandomPaperCache();
+        rp.setId(entity.getId());
         rp.setName(entity.getName());
         rp.setPaperStructId(entity.getPaperStructId());
 
-        Map<String, List<RandomPaperQuestion>> map = new HashMap<>();
+        Map<String, Integer> map = new HashMap<>();
+        String questionKey = CacheConstants.CACHE_Q_RANDOM_PAPER_QUESTION + randomPaperId;
         for (RandomPaperQuestion rpq : rpQuestions) {
-            List<RandomPaperQuestion> list = map.get(rpq.getKey());
-            if (list == null) {
-                list = new ArrayList<>();
-                map.put(rpq.getKey(), list);
+        	Integer count = map.get(rpq.getKey());
+            if (count == null) {
+            	count = 0;
             }
-            list.add(rpq);
+            map.put(rpq.getKey(), count+1);
+            redisClient.set(questionKey,rpq.getKey()+"_"+count, rpq, cacheTimeOut);
         }
         rp.setQuestionMap(map);
 
         redisClient.set(key, rp, cacheTimeOut);
-        localRandomPaperCache.put(key, rp);
+//        localRandomPaperCache.put(key, rp);
+        return rp;
+    }
+    
+    private RandomPaperQuestion getRandomPaperQuestionCacheById(String randomPaperId,String ckey,Integer index) {
+    	String questionKey = CacheConstants.CACHE_Q_RANDOM_PAPER_QUESTION + randomPaperId;
+    	String subKey=ckey+"_"+index;
+        // 从redis缓存中获取
+    	RandomPaperQuestion rp = redisClient.get(questionKey,subKey, RandomPaperQuestion.class);
+        if (rp != null) {
+            log.warn("从【Redis缓存】中获取抽卷小题! key:{},subKey:{}", questionKey,subKey);
+            return rp;
+        }
+
+        // 从数据库中获取
+        List<RandomPaperQuestion> rpQuestions = randomPaperQuestionRepo.findByRandomPaperId(randomPaperId);
+        if (CollectionUtils.isEmpty(rpQuestions)) {
+            throw new StatusException("随机模板试题库为空:" + randomPaperId);
+        }
+
+        log.warn("从【数据库】中获取抽卷小题! key:{}", questionKey);
+
+        Map<String, Integer> map = new HashMap<>();
+        for (RandomPaperQuestion rpq : rpQuestions) {
+        	Integer count = map.get(rpq.getKey());
+            if (count == null) {
+            	count = 0;
+            }
+            map.put(rpq.getKey(), count+1);
+            redisClient.set(questionKey,rpq.getKey()+"_"+count, rpq, cacheTimeOut);
+            if(subKey.equals(rpq.getKey()+"_"+count)) {
+            	rp=rpq;
+            }
+        }
+        if (rp == null) {
+        	throw new StatusException("随机模板试题库信息异常,未找到小题信息. key:"+questionKey+",subKey:"+subKey);
+        }
         return rp;
     }