|
@@ -4,6 +4,8 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -43,6 +45,7 @@ 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.PaperDetailUnitDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.QuestionDto;
|
|
@@ -54,18 +57,24 @@ 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.RandomPaperCache;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
|
|
|
+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;
|
|
|
|
|
|
@Service
|
|
|
public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
-
|
|
|
+ private static int cacheTimeOut = 2 * 60 * 60;
|
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
@Autowired
|
|
|
+ private PaperStructService paperStructService;
|
|
|
+ @Autowired
|
|
|
private PaperStructRepo paperStructRepo;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
@Autowired
|
|
|
private PropertyRepo propertyRepo;
|
|
|
@Autowired
|
|
@@ -675,6 +684,8 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
}
|
|
|
}
|
|
|
randomPaperQuestionRepo.saveAll(rqs);
|
|
|
+ String key = CacheConstants.CACHE_Q_RANDOM_PAPER + e.getId();
|
|
|
+ redisClient.delete(key);
|
|
|
}
|
|
|
clearQuestionIds(ret);
|
|
|
return ret;
|
|
@@ -685,8 +696,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
RandomPaperQuestion rq = new RandomPaperQuestion();
|
|
|
rqs.add(rq);
|
|
|
rq.setCourseId(e.getCourseId());
|
|
|
- rq.setDetailNumber(dto.getDetailNumber());
|
|
|
- rq.setKey(dto.getKey());
|
|
|
+ rq.setKey(dto.getDetailNumber() + "-" + dto.getKey());
|
|
|
rq.setQuestionIds(dto.getQuestionIds());
|
|
|
rq.setRandomPaperId(e.getId());
|
|
|
rq.setRootOrgId(e.getRootOrgId());
|
|
@@ -712,8 +722,31 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
|
|
|
@Override
|
|
|
public DefaultPaper getRandomPaper(String randomPaperId) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
+ RandomPaperCache rp=getByCache(randomPaperId);
|
|
|
+ PaperStruct ps=paperStructService.getByCache(rp.getPaperStructId());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private RandomPaperCache getByCache(String id) {
|
|
|
+ String key = CacheConstants.CACHE_Q_RANDOM_PAPER + id;
|
|
|
+ RandomPaperCache rp = redisClient.get(key, RandomPaperCache.class, cacheTimeOut);
|
|
|
+ if (rp == null) {
|
|
|
+ rp = new RandomPaperCache();
|
|
|
+ RandomPaper e = Model.of(randomPaperRepo.findById(id));
|
|
|
+ if (e == null) {
|
|
|
+ throw new StatusException("未找到随机模板:" + id);
|
|
|
+ }
|
|
|
+ rp.setPaperStructId(e.getPaperStructId());
|
|
|
+ List<RandomPaperQuestion> rpqs = randomPaperQuestionRepo.findByRandomPaperId(id);
|
|
|
+ if (CollectionUtils.isEmpty(rpqs)) {
|
|
|
+ throw new StatusException("随机模板试题库为空:" + id);
|
|
|
+ }
|
|
|
+ Map<String, RandomPaperQuestion> map = rpqs.stream()
|
|
|
+ .collect(Collectors.toMap(RandomPaperQuestion::getKey, account -> account, (key1, key2) -> key2));
|
|
|
+ rp.setRpqs(map);
|
|
|
+ redisClient.set(key, rp, cacheTimeOut);
|
|
|
+ }
|
|
|
+ return rp;
|
|
|
+ }
|
|
|
+
|
|
|
}
|