|
|
@@ -14,7 +14,6 @@ import nju.seec.helper.exception.HelperException;
|
|
|
import nju.seec.helper.util.Consts;
|
|
|
import nju.seec.helper.util.RestRequestUtil;
|
|
|
import nju.seec.helper.util.cache.GuavaCacheUtils;
|
|
|
-import nju.seec.helper.vo.question.BokQuestionVO;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
@@ -48,7 +47,7 @@ public class QuestionApi {
|
|
|
this.cacheUtils = cacheUtils;
|
|
|
}
|
|
|
|
|
|
- public Page<BokQuestionVO> bokFindByStemLike(String stem, Pageable pageable) {
|
|
|
+ public Page<QuestionVO> bokFindByStemLike(String stem, Pageable pageable) {
|
|
|
Map<String, String> urlParams = ImmutableMap.of(
|
|
|
"content", stem,
|
|
|
"page", String.valueOf(1 + pageable.getPageNumber()),
|
|
|
@@ -56,18 +55,18 @@ public class QuestionApi {
|
|
|
);
|
|
|
BokSearchResult result = restRequestUtil.sendGetRequest(tqStemSearchUrl, BokSearchResult.class, urlParams);
|
|
|
|
|
|
- List<BokQuestionVO> bokQuestionVOList = result.getEmbedded().getQuestions();
|
|
|
- cacheUtils.setAll(BOK_QUESTION_CACHE_NAME, bokQuestionVOList.parallelStream().collect(Collectors.toMap(BokQuestionVO::getId, bokQuestion -> bokQuestion)));
|
|
|
- return new PageImpl<>(bokQuestionVOList, pageable, result.getPage().getTotalElements());
|
|
|
+ List<QuestionVO> questionVOList = result.getEmbedded().getQuestions();
|
|
|
+ cacheUtils.setAll(BOK_QUESTION_CACHE_NAME, questionVOList.parallelStream().collect(Collectors.toMap(QuestionVO::getId, bokQuestion -> bokQuestion)));
|
|
|
+ return new PageImpl<>(questionVOList, pageable, result.getPage().getTotalElements());
|
|
|
}
|
|
|
|
|
|
private static final String BOK_QUESTION_CACHE_NAME = Consts.SYS_NAME + "_bok_question";
|
|
|
|
|
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
|
- public List<BokQuestionVO> bokFindByIdIn(final List<String> ids) {
|
|
|
- Map<String, BokQuestionVO> bokQuestionsMap = Maps.newHashMapWithExpectedSize(ids.size());
|
|
|
+ public List<QuestionVO> bokFindByIdIn(final List<String> ids) {
|
|
|
+ Map<String, QuestionVO> bokQuestionsMap = Maps.newHashMapWithExpectedSize(ids.size());
|
|
|
|
|
|
- final Map<String, BokQuestionVO> cacheBokQuestionsMap = (Map) cacheUtils.multiGet(BOK_QUESTION_CACHE_NAME, ids);
|
|
|
+ final Map<String, QuestionVO> cacheBokQuestionsMap = (Map) cacheUtils.multiGet(BOK_QUESTION_CACHE_NAME, ids);
|
|
|
bokQuestionsMap.putAll(cacheBokQuestionsMap);
|
|
|
|
|
|
List<String> requestIds = Lists.newArrayList(ids);
|
|
|
@@ -77,9 +76,9 @@ public class QuestionApi {
|
|
|
Map<String, String> urlParams = ImmutableMap.of("id", requestIds.stream().reduce((a, b) -> a + "," + b).orElse(""));
|
|
|
|
|
|
BokSearchResult result = restRequestUtil.sendGetRequest(tqIdSearchUrl, BokSearchResult.class, urlParams);
|
|
|
- List<BokQuestionVO> bokQuestionVOList = result.getEmbedded().getQuestions();
|
|
|
+ List<QuestionVO> questionVOList = result.getEmbedded().getQuestions();
|
|
|
|
|
|
- Map<String, BokQuestionVO> remoteBokQuestionsMap = bokQuestionVOList.parallelStream().collect(Collectors.toMap(BokQuestionVO::getId, bokQuestion -> bokQuestion));
|
|
|
+ Map<String, QuestionVO> remoteBokQuestionsMap = questionVOList.parallelStream().collect(Collectors.toMap(QuestionVO::getId, bokQuestion -> bokQuestion));
|
|
|
|
|
|
bokQuestionsMap.putAll(remoteBokQuestionsMap);
|
|
|
cacheUtils.setAll(BOK_QUESTION_CACHE_NAME, (Map) remoteBokQuestionsMap);
|
|
|
@@ -90,27 +89,27 @@ public class QuestionApi {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- public BokQuestionVO bokFindById(String questionId) {
|
|
|
+ public QuestionVO bokFindById(String questionId) {
|
|
|
Object cachedBokQuestion = cacheUtils.get(BOK_QUESTION_CACHE_NAME, questionId);
|
|
|
- if (cachedBokQuestion instanceof BokQuestionVO) {
|
|
|
- return (BokQuestionVO) cachedBokQuestion;
|
|
|
+ if (cachedBokQuestion instanceof QuestionVO) {
|
|
|
+ return (QuestionVO) cachedBokQuestion;
|
|
|
}
|
|
|
- BokQuestionVO bokQuestionVO = restRequestUtil.sendGetRequest(tqUrl + "/" + questionId, BokQuestionVO.class, Collections.emptyMap());
|
|
|
- cacheUtils.set(BOK_QUESTION_CACHE_NAME, bokQuestionVO.getId(), bokQuestionVO);
|
|
|
- return bokQuestionVO;
|
|
|
+ QuestionVO questionVO = restRequestUtil.sendGetRequest(tqUrl + "/" + questionId, QuestionVO.class, Collections.emptyMap());
|
|
|
+ cacheUtils.set(BOK_QUESTION_CACHE_NAME, questionVO.getId(), questionVO);
|
|
|
+ return questionVO;
|
|
|
}
|
|
|
|
|
|
- public BokQuestionVO createQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
|
|
|
- BokQuestionVO bokQuestionVO = getQuestion(baseQuestionDTO);
|
|
|
- bokQuestionVO.setId(questionId);
|
|
|
- bokQuestionVO = restRequestUtil.sendPostRequest(tqUrl, bokQuestionVO, BokQuestionVO.class);
|
|
|
- return bokQuestionVO;
|
|
|
+ public QuestionVO createQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
|
|
|
+ QuestionVO questionVO = getQuestion(baseQuestionDTO);
|
|
|
+ questionVO.setId(questionId);
|
|
|
+ questionVO = restRequestUtil.sendPostRequest(tqUrl, questionVO, QuestionVO.class);
|
|
|
+ return questionVO;
|
|
|
}
|
|
|
|
|
|
- public BokQuestionVO modifyQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
|
|
|
- BokQuestionVO bokQuestionVO = getQuestion(baseQuestionDTO);
|
|
|
- bokQuestionVO.setId(questionId);
|
|
|
- restRequestUtil.sendPutRequest(tqUrl + "/" + questionId, bokQuestionVO);
|
|
|
+ public QuestionVO modifyQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
|
|
|
+ QuestionVO questionVO = getQuestion(baseQuestionDTO);
|
|
|
+ questionVO.setId(questionId);
|
|
|
+ restRequestUtil.sendPutRequest(tqUrl + "/" + questionId, questionVO);
|
|
|
return bokFindById(questionId);
|
|
|
}
|
|
|
|
|
|
@@ -122,31 +121,31 @@ public class QuestionApi {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private BokQuestionVO getQuestion(BaseQuestionDTO baseQuestionDTO) {
|
|
|
- BokQuestionVO bokQuestionVO = new BokQuestionVO();
|
|
|
- bokQuestionVO.setType(baseQuestionDTO.getType());
|
|
|
- bokQuestionVO.setStem(baseQuestionDTO.getStem());
|
|
|
- bokQuestionVO.setKeyPoints(baseQuestionDTO.getKeyPoints());
|
|
|
- bokQuestionVO.setTags(baseQuestionDTO.getTags());
|
|
|
- bokQuestionVO.setKnowledgeId(baseQuestionDTO.getKnowledgeId());
|
|
|
+ private QuestionVO getQuestion(BaseQuestionDTO baseQuestionDTO) {
|
|
|
+ QuestionVO questionVO = new QuestionVO();
|
|
|
+ questionVO.setType(baseQuestionDTO.getType());
|
|
|
+ questionVO.setStem(baseQuestionDTO.getStem());
|
|
|
+ questionVO.setKeyPoints(baseQuestionDTO.getKeyPoints());
|
|
|
+ questionVO.setTags(baseQuestionDTO.getTags());
|
|
|
+ questionVO.setKnowledgeId(baseQuestionDTO.getKnowledgeId());
|
|
|
|
|
|
final QuestionType questionType = QuestionType.getQuestionType(baseQuestionDTO.getType());
|
|
|
switch (Objects.requireNonNull(questionType)) {
|
|
|
case CHOICE:
|
|
|
ChoiceQuestionDTO choiceQuestionDTO = (ChoiceQuestionDTO) baseQuestionDTO;
|
|
|
- bokQuestionVO.setOptions(choiceQuestionDTO.getOptions());
|
|
|
- bokQuestionVO.setAnswer(choiceQuestionDTO.getAnswer());
|
|
|
- bokQuestionVO.setAnalysis(choiceQuestionDTO.getAnalysis());
|
|
|
+ questionVO.setOptions(choiceQuestionDTO.getOptions());
|
|
|
+ questionVO.setAnswer(choiceQuestionDTO.getAnswer());
|
|
|
+ questionVO.setAnalysis(choiceQuestionDTO.getAnalysis());
|
|
|
break;
|
|
|
case TRUE_FALSE:
|
|
|
TrueOrFalseQuestionDTO trueOrFalseQuestionDTO = (TrueOrFalseQuestionDTO) baseQuestionDTO;
|
|
|
- bokQuestionVO.setAnswer(String.valueOf(trueOrFalseQuestionDTO.getAnswer()));
|
|
|
- bokQuestionVO.setAnalysis(trueOrFalseQuestionDTO.getAnalysis());
|
|
|
+ questionVO.setAnswer(String.valueOf(trueOrFalseQuestionDTO.getAnswer()));
|
|
|
+ questionVO.setAnalysis(trueOrFalseQuestionDTO.getAnalysis());
|
|
|
break;
|
|
|
default:
|
|
|
throw HelperException.of(ExceptionType.ERROR, "不支持的题目类型");
|
|
|
}
|
|
|
- return bokQuestionVO;
|
|
|
+ return questionVO;
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
@@ -157,7 +156,7 @@ public class QuestionApi {
|
|
|
|
|
|
@Data
|
|
|
private static class Embedded {
|
|
|
- private List<BokQuestionVO> questions = Collections.emptyList();
|
|
|
+ private List<QuestionVO> questions = Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
@Data
|