|
@@ -21,6 +21,7 @@ import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseListReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseListResp;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseListResp;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
|
|
|
|
+import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.nlpcn.commons.lang.util.StringUtil;
|
|
import org.nlpcn.commons.lang.util.StringUtil;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -34,7 +35,6 @@ import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -44,6 +44,8 @@ import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.CACHE_PREFIX_FOR_PAPER;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author chenken
|
|
* @author chenken
|
|
* @date 2017年4月14日 下午6:07:55
|
|
* @date 2017年4月14日 下午6:07:55
|
|
@@ -112,9 +114,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
@Autowired
|
|
@Autowired
|
|
private SubQuestionDtoAssembler subQuestionDtoAssembler;
|
|
private SubQuestionDtoAssembler subQuestionDtoAssembler;
|
|
|
|
|
|
- @SuppressWarnings("rawtypes")
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private RedisTemplate redisTemplate;
|
|
|
|
|
|
+ private RedisClient redisClient;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private PaperDetailUnitNativeRepo detailUnitNativeRepo;
|
|
private PaperDetailUnitNativeRepo detailUnitNativeRepo;
|
|
@@ -249,12 +250,10 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean checkIsAllQbjectiveQuestion(String paperId) {
|
|
public boolean checkIsAllQbjectiveQuestion(String paperId) {
|
|
-
|
|
|
|
//优先从redis中获取缓存dto
|
|
//优先从redis中获取缓存dto
|
|
- Object cacheDto = redisTemplate.opsForValue().get(paperId);
|
|
|
|
- if (cacheDto != null && cacheDto.getClass().equals(PaperDto.class)) {
|
|
|
|
- PaperDto paperDto = (PaperDto) cacheDto;
|
|
|
|
- return paperDto.isAllQbjectiveQuestion();
|
|
|
|
|
|
+ PaperDto cachePaperDto = redisClient.get(CACHE_PREFIX_FOR_PAPER + paperId, PaperDto.class, 10 * 60);
|
|
|
|
+ if (cachePaperDto != null) {
|
|
|
|
+ return cachePaperDto.isAllQbjectiveQuestion();
|
|
}
|
|
}
|
|
|
|
|
|
Paper paper = Model.of(paperRepo.findById(paperId));
|
|
Paper paper = Model.of(paperRepo.findById(paperId));
|
|
@@ -302,7 +301,7 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, String> makePaperByConfig(ExtractConfig extractConfig) {
|
|
public Map<String, String> makePaperByConfig(ExtractConfig extractConfig) {
|
|
- Map<String, String> finishedPaperIdMap = new HashMap<String, String>();
|
|
|
|
|
|
+ Map<String, String> finishedPaperIdMap = new HashMap<>();
|
|
if (extractConfig == null) {
|
|
if (extractConfig == null) {
|
|
throw new RuntimeException("调卷规则不存在");
|
|
throw new RuntimeException("调卷规则不存在");
|
|
}
|
|
}
|
|
@@ -315,9 +314,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
String key = entry.getKey();
|
|
String key = entry.getKey();
|
|
//根据原有试卷重新组卷得到新试卷
|
|
//根据原有试卷重新组卷得到新试卷
|
|
/*Paper newPaper = this.recombinationPaper(entry.getValue(),
|
|
/*Paper newPaper = this.recombinationPaper(entry.getValue(),
|
|
- PaperType.PREVIEW,
|
|
|
|
- extractConfig.getScrambling_the_question_order(),
|
|
|
|
- extractConfig.getScrambling_the_option_order());*/
|
|
|
|
|
|
+ PaperType.PREVIEW,
|
|
|
|
+ extractConfig.getScrambling_the_question_order(),
|
|
|
|
+ extractConfig.getScrambling_the_option_order());*/
|
|
finishedPaperIdMap.put(key, entry.getValue().getId());
|
|
finishedPaperIdMap.put(key, entry.getValue().getId());
|
|
}
|
|
}
|
|
return finishedPaperIdMap;
|
|
return finishedPaperIdMap;
|
|
@@ -543,13 +542,6 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
*/
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
private PaperDto getPaperDtoByPaper(Paper paper, String basePaperId) {
|
|
private PaperDto getPaperDtoByPaper(Paper paper, String basePaperId) {
|
|
-
|
|
|
|
- //优先从redis中获取缓存dto
|
|
|
|
- /*Object cacheDto = redisTemplate.opsForValue().get(paper.getId());
|
|
|
|
- if(cacheDto != null && cacheDto.getClass().equals(PaperDto.class)){
|
|
|
|
- return (PaperDto)cacheDto;
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
long beginTime = System.currentTimeMillis();
|
|
long beginTime = System.currentTimeMillis();
|
|
//没有则重新组装
|
|
//没有则重新组装
|
|
PaperDto paperDto = paperDtoAssembler.toDto(paper);
|
|
PaperDto paperDto = paperDtoAssembler.toDto(paper);
|
|
@@ -636,8 +628,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
}
|
|
}
|
|
long paperDetailUnitDtoEndTime = System.currentTimeMillis();
|
|
long paperDetailUnitDtoEndTime = System.currentTimeMillis();
|
|
logger.info("单独组装paperDetailUnitDto耗时:" + (paperDetailUnitDtoEndTime - paperDetailDtoEndTime) + "ms");
|
|
logger.info("单独组装paperDetailUnitDto耗时:" + (paperDetailUnitDtoEndTime - paperDetailDtoEndTime) + "ms");
|
|
|
|
+
|
|
//将重新组装的dto放进缓存
|
|
//将重新组装的dto放进缓存
|
|
- redisTemplate.opsForValue().set(paperDto.getId(), paperDto);
|
|
|
|
|
|
+ redisClient.set(CACHE_PREFIX_FOR_PAPER + paperDto.getId(), paperDto, 10 * 60);
|
|
return paperDto;
|
|
return paperDto;
|
|
}
|
|
}
|
|
|
|
|