Browse Source

组卷结构缓存精简

xiatian 1 năm trước cách đây
mục cha
commit
43e4d4bc1a

+ 40 - 26
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/PaperStructService.java

@@ -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);
         }

+ 192 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/cache/PaperDetailStructCache.java

@@ -0,0 +1,192 @@
+package cn.com.qmth.examcloud.core.questions.service.cache;
+
+import java.util.List;
+import java.util.Map;
+
+import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
+import cn.com.qmth.examcloud.core.questions.dao.entity.dto.CoursePropertyNumberDto;
+import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStructDto;
+
+public class PaperDetailStructCache{
+    private Integer number;//大题序号
+
+    private String name;//大题名称
+
+    private List<PaperDetailUnitStructDto> unitStructs;//题目类型统计
+
+    private Double totalScore;//大题总分
+
+    @SuppressWarnings("rawtypes")
+    private Map params;//大题参数
+
+    private String remark;
+
+    private Integer detailCount; //小题总数
+
+    /**
+     * 蓝图结构字段
+     */
+    private QuesStructType questionType; //题型
+
+    private Double score; //小题分数
+
+    private List<String> quesNames;//来源大题
+
+    private Integer publicSimpleCount; //公开简单总数
+
+    private Integer publicMediumCount; //公开中等总数
+
+    private Integer publicDifficultyCount; //公开困难总数
+
+    private Integer noPublicSimpleCount; //非公开简单总数
+
+    private Integer noPublicMediumCount; //非公开中等总数
+
+    private Integer noPublicDifficultyCount; //非公开困难总数  coursePropertyNumberDtos
+
+    private List<CoursePropertyNumberDto> coursePropertyNumberDtos;
+
+    public Integer getNumber() {
+        return number;
+    }
+
+    public void setNumber(Integer number) {
+        this.number = number;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    public List<PaperDetailUnitStructDto> getUnitStructs() {
+        return unitStructs;
+    }
+
+    public void setUnitStructs(List<PaperDetailUnitStructDto> unitStructs) {
+        this.unitStructs = unitStructs;
+    }
+
+    public Double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(Double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    @SuppressWarnings("rawtypes")
+    public Map getParams() {
+        return params;
+    }
+
+    @SuppressWarnings("rawtypes")
+    public void setParams(Map params) {
+        this.params = params;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public Integer getDetailCount() {
+        return detailCount;
+    }
+
+    public void setDetailCount(Integer detailCount) {
+        this.detailCount = detailCount;
+    }
+
+    public PaperDetailStructCache() {
+    }
+
+    public QuesStructType getQuestionType() {
+        return questionType;
+    }
+
+    public void setQuestionType(QuesStructType questionType) {
+        this.questionType = questionType;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public List<String> getQuesNames() {
+        return quesNames;
+    }
+
+    public void setQuesNames(List<String> quesNames) {
+        this.quesNames = quesNames;
+    }
+
+    public Integer getPublicSimpleCount() {
+        return publicSimpleCount;
+    }
+
+    public void setPublicSimpleCount(Integer publicSimpleCount) {
+        this.publicSimpleCount = publicSimpleCount;
+    }
+
+    public Integer getPublicMediumCount() {
+        return publicMediumCount;
+    }
+
+    public void setPublicMediumCount(Integer publicMediumCount) {
+        this.publicMediumCount = publicMediumCount;
+    }
+
+    public Integer getPublicDifficultyCount() {
+        return publicDifficultyCount;
+    }
+
+    public void setPublicDifficultyCount(Integer publicDifficultyCount) {
+        this.publicDifficultyCount = publicDifficultyCount;
+    }
+
+    public Integer getNoPublicSimpleCount() {
+        return noPublicSimpleCount;
+    }
+
+    public void setNoPublicSimpleCount(Integer noPublicSimpleCount) {
+        this.noPublicSimpleCount = noPublicSimpleCount;
+    }
+
+    public Integer getNoPublicMediumCount() {
+        return noPublicMediumCount;
+    }
+
+    public void setNoPublicMediumCount(Integer noPublicMediumCount) {
+        this.noPublicMediumCount = noPublicMediumCount;
+    }
+
+    public Integer getNoPublicDifficultyCount() {
+        return noPublicDifficultyCount;
+    }
+
+    public void setNoPublicDifficultyCount(Integer noPublicDifficultyCount) {
+        this.noPublicDifficultyCount = noPublicDifficultyCount;
+    }
+
+    public List<CoursePropertyNumberDto> getCoursePropertyNumberDtos() {
+        return coursePropertyNumberDtos;
+    }
+
+    public void setCoursePropertyNumberDtos(
+            List<CoursePropertyNumberDto> coursePropertyNumberDtos) {
+        this.coursePropertyNumberDtos = coursePropertyNumberDtos;
+    }
+
+}

+ 216 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/cache/PaperStructCache.java

@@ -0,0 +1,216 @@
+package cn.com.qmth.examcloud.core.questions.service.cache;
+
+import java.util.List;
+import java.util.Map;
+
+import cn.com.qmth.examcloud.core.questions.base.enums.GenPaperType;
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperStructType;
+
+
+public class PaperStructCache {
+	
+	private String id;
+
+    private String name;// 试卷结构名称
+
+    private Double totalScore;// 总分
+
+    private Integer detailCount;// 大题数量
+
+    private Integer detailUnitCount;//小题数量
+
+    @SuppressWarnings("rawtypes")
+    private Map params;
+
+    private List<PaperDetailStructCache> paperDetailStructs;// 大题
+
+    private String creator;// 创建人id
+
+    private String createTime;// 创建时间
+
+    private String orgId;// 机构ID
+
+    private Long courseId;
+    
+    private String courseNo;
+
+    private String courseName;
+
+    /**
+     * 试卷结构类型  :  精确组卷    蓝图组卷
+     */
+    private PaperStructType paperStrucType;
+
+    private String type;
+
+    /**
+     * 组卷类型     : 精细组卷      宏观组卷
+     */
+    private GenPaperType genPaperType;
+
+    private String coursePropertyId; //课程属性id
+
+    private Double difficulty; //难度
+
+    private String examRemark;//考试说明
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(Double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public Integer getDetailCount() {
+        return detailCount;
+    }
+
+    public void setDetailCount(Integer detailCount) {
+        this.detailCount = detailCount;
+    }
+
+    @SuppressWarnings("rawtypes")
+    public Map getParams() {
+        return params;
+    }
+
+    @SuppressWarnings("rawtypes")
+    public void setParams(Map params) {
+        this.params = params;
+    }
+
+
+    public String getCreator() {
+        return creator;
+    }
+
+    public void setCreator(String creator) {
+        this.creator = creator;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+
+    public PaperStructCache() {
+    }
+
+    public String getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(String orgId) {
+        this.orgId = orgId;
+    }
+
+    public String getCourseNo() {
+        return courseNo;
+    }
+
+    public void setCourseNo(String courseNo) {
+        this.courseNo = courseNo;
+    }
+
+    public Integer getDetailUnitCount() {
+        return detailUnitCount;
+    }
+
+    public void setDetailUnitCount(Integer detailUnitCount) {
+        this.detailUnitCount = detailUnitCount;
+    }
+
+    public GenPaperType getGenPaperType() {
+        return genPaperType;
+    }
+
+    public void setGenPaperType(GenPaperType genPaperType) {
+        this.genPaperType = genPaperType;
+    }
+
+    public PaperStructType getPaperStrucType() {
+        return paperStrucType;
+    }
+
+    public void setPaperStrucType(PaperStructType paperStrucType) {
+        this.paperStrucType = paperStrucType;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getCoursePropertyId() {
+        return coursePropertyId;
+    }
+
+    public void setCoursePropertyId(String coursePropertyId) {
+        this.coursePropertyId = coursePropertyId;
+    }
+
+    public Double getDifficulty() {
+        return difficulty;
+    }
+
+    public void setDifficulty(Double difficulty) {
+        this.difficulty = difficulty;
+    }
+
+    public String getExamRemark() {
+        return examRemark;
+    }
+
+    public void setExamRemark(String examRemark) {
+        this.examRemark = examRemark;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public List<PaperDetailStructCache> getPaperDetailStructs() {
+		return paperDetailStructs;
+	}
+
+	public void setPaperDetailStructs(List<PaperDetailStructCache> paperDetailStructs) {
+		this.paperDetailStructs = paperDetailStructs;
+	}
+
+    
+}

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

@@ -23,6 +23,8 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStruct
 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.cache.PaperDetailStructCache;
+import cn.com.qmth.examcloud.core.questions.service.cache.PaperStructCache;
 import cn.com.qmth.examcloud.core.questions.service.cache.RandomPaperCache;
 import cn.com.qmth.examcloud.core.questions.service.util.BatchGetDataUtil;
 import cn.com.qmth.examcloud.core.questions.service.util.BatchSetDataUtil;
@@ -905,7 +907,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         long start2 = System.currentTimeMillis();
         log.warn("获取抽卷模板! 耗时:{}ms ID:{} 题数量:{}", start2 - start, randomPaperId, rp.getQuestionMap().size());
 
-        PaperStruct ps = paperStructService.getPaperStructCacheById(rp.getPaperStructId());
+        PaperStructCache ps = paperStructService.getPaperStructCacheById(rp.getPaperStructId());
         log.warn("获取组卷结构! 耗时:{}ms 结构类型:{} ID:{}", System.currentTimeMillis() - start2, ps.getPaperStrucType(), rp.getPaperStructId());
 
         CreateDefaultPaperParam param = new CreateDefaultPaperParam();
@@ -920,7 +922,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
             if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
                 int detailNumber = 0;
-                for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
+                for (PaperDetailStructCache ds : ps.getPaperDetailStructs()) {
                     DefaultQuestionGroup detail = new DefaultQuestionGroup();
                     details.add(detail);
                     detail.setGroupName(ds.getName());
@@ -941,7 +943,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
         } else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
             if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
                 int detailNumber = 0;
-                for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
+                for (PaperDetailStructCache ds : ps.getPaperDetailStructs()) {
                     DefaultQuestionGroup detail = new DefaultQuestionGroup();
                     details.add(detail);
                     detail.setGroupName(ds.getName());