|
@@ -1,5 +1,32 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+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;
|
|
|
+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 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;
|
|
@@ -12,32 +39,17 @@ import cn.com.qmth.examcloud.core.questions.base.enums.PaperStructType;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.QuesTypeNameRepo;
|
|
|
-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.PaperDetailUnitStruct;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStruct;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStructSearchInfo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuesTypeName;
|
|
|
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.bean.dto.QuesNameDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.cache.PaperStructCache;
|
|
|
import cn.com.qmth.examcloud.support.CacheConstants;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
-import com.google.common.cache.Cache;
|
|
|
-import com.google.common.cache.CacheBuilder;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-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 java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by songyue on 16/12/28.
|
|
@@ -47,7 +59,7 @@ public class PaperStructService {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(PaperStructService.class);
|
|
|
|
|
|
- private static Cache<String, PaperStruct> 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;
|
|
|
|
|
@@ -495,24 +507,26 @@ public class PaperStructService {
|
|
|
return new QuesNameDto(name, name);
|
|
|
}
|
|
|
|
|
|
- public PaperStruct getPaperStructCacheById(String paperStructId) {
|
|
|
+ public PaperStructCache getPaperStructCacheById(String paperStructId) {
|
|
|
// 组卷结构 优先从本地缓存中获取
|
|
|
String key = CacheConstants.CACHE_Q_PAPER_STRUCT + paperStructId;
|
|
|
- PaperStruct ps = localPaperStructCache.getIfPresent(key);
|
|
|
+ PaperStructCache ps = localPaperStructCache.getIfPresent(key);
|
|
|
if (ps != null) {
|
|
|
log.warn("从【本地缓存】中获取组卷结构! key:{}", key);
|
|
|
return ps;
|
|
|
}
|
|
|
|
|
|
// 从redis缓存中获取
|
|
|
- ps = redisClient.get(key, PaperStruct.class, cacheTimeOut);
|
|
|
+ ps = redisClient.get(key, PaperStructCache.class, cacheTimeOut);
|
|
|
if (ps != null) {
|
|
|
log.warn("从【Redis缓存】中获取抽卷模板! key:{}", key);
|
|
|
return ps;
|
|
|
}
|
|
|
|
|
|
// 从数据库中获取
|
|
|
- ps = Model.of(paperStructRepo.findById(paperStructId));
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("id").is(new ObjectId(paperStructId)));
|
|
|
+ ps = this.mongoTemplate.findOne(query, PaperStructCache.class);
|
|
|
if (ps == null) {
|
|
|
throw new StatusException("未找到试卷结构:" + paperStructId);
|
|
|
}
|