|
@@ -5,19 +5,23 @@ import cn.com.qmth.examcloud.core.questions.dao.QuesRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionSearchCondition;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuesService;
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.cache.QuestionCache;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import com.google.gson.Gson;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.CACHE_PREFIX_QUESTION;
|
|
|
+
|
|
|
/**
|
|
|
* Created by songyue on 16/12/28.
|
|
|
*/
|
|
@@ -25,7 +29,7 @@ import java.util.stream.Stream;
|
|
|
@RequestMapping("${api_cqb}/")
|
|
|
public class QuesController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
- QuestionCache questionCache;
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
QuesService quesService;
|
|
@@ -77,7 +81,7 @@ public class QuesController extends ControllerSupport {
|
|
|
quesService.saveQues(question);
|
|
|
|
|
|
//清除缓存
|
|
|
- //questionCache.remove(question.getId());
|
|
|
+ this.clearQuestionCache(question.getId());
|
|
|
return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
@@ -105,7 +109,7 @@ public class QuesController extends ControllerSupport {
|
|
|
quesRepo.deleteById(id);
|
|
|
|
|
|
//清除缓存
|
|
|
- //questionCache.remove(id);
|
|
|
+ this.clearQuestionCache(id);
|
|
|
return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
@@ -153,4 +157,14 @@ public class QuesController extends ControllerSupport {
|
|
|
quesService.updateProByCourse(courseCode, difficultyDegree, publicity, orgId);
|
|
|
return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|