|
@@ -14,6 +14,7 @@ import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuesService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.bson.types.ObjectId;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -23,11 +24,15 @@ import org.springframework.data.domain.Sort.Order;
|
|
|
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.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.CACHE_PREFIX_QUESTION;
|
|
|
|
|
|
/**
|
|
|
* @author chenken
|
|
@@ -50,6 +55,9 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
@Autowired
|
|
|
MongoTemplate mongoTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
RedisClient redisClient;
|
|
|
|
|
@@ -87,7 +95,8 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
if (baseUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
if (updateQuestion.getId().equals(baseQuestion.getId())) {
|
|
|
// 更新对象为套题本身
|
|
|
- baseUnit.setQuestion(quesService.saveQues(updateQuestion));
|
|
|
+ quesService.saveQues(updateQuestion);
|
|
|
+ baseUnit.setQuestion(updateQuestion);
|
|
|
} else {
|
|
|
List<Double> subScoreList = baseUnit.getSubScoreList();
|
|
|
int size = baseQuestion.getSubQuestions().size();
|
|
@@ -134,14 +143,16 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
}
|
|
|
|
|
|
if (match) {
|
|
|
- baseUnit.setQuestion(quesService.saveQues(baseQuestion));
|
|
|
+ quesService.saveQues(baseQuestion);
|
|
|
+ baseUnit.setQuestion(baseQuestion);
|
|
|
}
|
|
|
|
|
|
// 更新套题unit当前总分与子题分数
|
|
|
baseUnit.setSubScoreList(subScoreList);
|
|
|
}
|
|
|
} else {
|
|
|
- baseUnit.setQuestion(quesService.saveQues(updateQuestion));
|
|
|
+ quesService.saveQues(updateQuestion);
|
|
|
+ baseUnit.setQuestion(updateQuestion);
|
|
|
baseUnit.setScore(updateUnit.getScore());
|
|
|
}
|
|
|
|
|
@@ -151,6 +162,11 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
Paper paper = baseUnit.getPaper();
|
|
|
paperService.formatPaper(paper, user);
|
|
|
|
|
|
+ if (baseUnit.getQuestion() != null) {
|
|
|
+ //清除缓存
|
|
|
+ this.clearQuestionCache(baseUnit.getQuestion().getId());
|
|
|
+ }
|
|
|
+
|
|
|
return baseUnit;
|
|
|
}
|
|
|
|
|
@@ -161,7 +177,8 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
* @return
|
|
|
*/
|
|
|
public void deletePaperDetailUnit(String id, User user) {
|
|
|
- Paper paper = Model.of(paperDetailUnitRepo.findById(id)).getPaper();
|
|
|
+ PaperDetailUnit detailUnit = Model.of(paperDetailUnitRepo.findById(id));
|
|
|
+ Paper paper = detailUnit.getPaper();
|
|
|
paperDetailUnitRepo.deleteById(id);
|
|
|
|
|
|
//清除缓存
|
|
@@ -169,6 +186,10 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
redisClient.delete(redisPaperPrefix + ":" + paper.getId());
|
|
|
}
|
|
|
|
|
|
+ if (detailUnit.getQuestion() != null) {
|
|
|
+ this.clearQuestionCache(detailUnit.getQuestion().getId());
|
|
|
+ }
|
|
|
+
|
|
|
paperService.formatPaper(paper, user);
|
|
|
}
|
|
|
|
|
@@ -320,5 +341,14 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
List<PaperDetailUnit> paperDetailUnits = mongoTemplate.find(query, PaperDetailUnit.class);
|
|
|
return paperDetailUnits;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ private void clearQuestionCache(String questionId) {
|
|
|
+ //清理与当前试题相关的缓存
|
|
|
+ final String patternKey = CACHE_PREFIX_QUESTION + "*" + questionId;
|
|
|
+ Set<String> keys = redisTemplate.keys(patternKey);
|
|
|
+ if (CollectionUtils.isNotEmpty(keys)) {
|
|
|
+ redisTemplate.delete(keys);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|