|
@@ -1,26 +1,32 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.api;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
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.PaperDetailUnitService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuesService;
|
|
|
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_KEY_QUESTION;
|
|
|
|
|
|
/**
|
|
|
* Created by songyue on 16/12/28.
|
|
@@ -28,8 +34,6 @@ import static cn.com.qmth.examcloud.core.questions.service.cache.Constants.CACHE
|
|
|
@RestController
|
|
|
@RequestMapping("${api_cqb}/")
|
|
|
public class QuesController extends ControllerSupport {
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
QuesService quesService;
|
|
@@ -39,6 +43,9 @@ public class QuesController extends ControllerSupport {
|
|
|
|
|
|
@Autowired
|
|
|
Gson gson;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperDetailUnitService paperDetailUnitService;
|
|
|
|
|
|
/**
|
|
|
* 获取试题
|
|
@@ -81,7 +88,7 @@ public class QuesController extends ControllerSupport {
|
|
|
quesService.saveQues(question);
|
|
|
|
|
|
//清除缓存
|
|
|
- this.clearQuestionCache(question.getId());
|
|
|
+ paperDetailUnitService.clearQuestionCache(question.getId());
|
|
|
|
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
|
}
|
|
@@ -110,7 +117,7 @@ public class QuesController extends ControllerSupport {
|
|
|
quesRepo.deleteById(id);
|
|
|
|
|
|
//清除缓存
|
|
|
- this.clearQuestionCache(id);
|
|
|
+ paperDetailUnitService.clearQuestionCache(id);
|
|
|
|
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
|
}
|
|
@@ -130,7 +137,7 @@ public class QuesController extends ControllerSupport {
|
|
|
quesRepo.save(question);
|
|
|
|
|
|
//清除缓存
|
|
|
- this.clearQuestionCache(id);
|
|
|
+ paperDetailUnitService.clearQuestionCache(id);
|
|
|
|
|
|
return new ResponseEntity<>(question, HttpStatus.OK);
|
|
|
}
|
|
@@ -165,13 +172,13 @@ public class QuesController extends ControllerSupport {
|
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
- private void clearQuestionCache(String questionId) {
|
|
|
- //清理与当前试题相关的缓存
|
|
|
- final String patternKey = CACHE_KEY_QUESTION + "*" + questionId;
|
|
|
- Set<String> keys = redisTemplate.keys(patternKey);
|
|
|
- if (CollectionUtils.isNotEmpty(keys)) {
|
|
|
- redisTemplate.delete(keys);
|
|
|
- }
|
|
|
- }
|
|
|
+// private void clearQuestionCache(String questionId) {
|
|
|
+// //清理与当前试题相关的缓存
|
|
|
+// final String patternKey = CACHE_KEY_QUESTION + "*" + questionId;
|
|
|
+// Set<String> keys = redisTemplate.keys(patternKey);
|
|
|
+// if (CollectionUtils.isNotEmpty(keys)) {
|
|
|
+// redisTemplate.delete(keys);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
}
|