QuestionThirdPartyServiceImpl.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.nju.edu.eval.thirdparty.thirdpartyImpl;
  2. import cn.seecoder.bok.client.SeecoderBokClient;
  3. import cn.seecoder.bok.common.vo.KnowledgeNodeVO;
  4. import cn.seecoder.bok.common.vo.QuestionVO;
  5. import com.nju.edu.eval.model.vo.question.CompleteQuestionVO;
  6. import com.nju.edu.eval.model.vo.question.QuestionStemListVO;
  7. import com.nju.edu.eval.model.vo.question.QuestionStemVO;
  8. import com.nju.edu.eval.thirdparty.QuestionThirdPartyService;
  9. import com.nju.edu.eval.util.BeanCopyUtil;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.data.domain.Page;
  13. import org.springframework.data.domain.Pageable;
  14. import org.springframework.stereotype.Component;
  15. import javax.annotation.PostConstruct;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.Optional;
  19. /**
  20. * @author mars
  21. * 封装调用的题库的第三方服务
  22. */
  23. @Component
  24. public class QuestionThirdPartyServiceImpl implements QuestionThirdPartyService {
  25. @Value("${seec-bok-client.host}")
  26. private String host;
  27. private SeecoderBokClient client;
  28. @PostConstruct
  29. public void init() {
  30. //TODO
  31. client = new SeecoderBokClient(host);
  32. }
  33. @Override
  34. public Optional<CompleteQuestionVO> getQuestionById(String id) {
  35. Optional<QuestionVO> response = client.getQuestionById(id);
  36. CompleteQuestionVO res = new CompleteQuestionVO();
  37. response.ifPresent(questionVO -> BeanUtils.copyProperties(questionVO, res));
  38. return Optional.of(res);
  39. }
  40. @Override
  41. public List<CompleteQuestionVO> getRecommendQuestions(List<String> knowledgeList, int expectedDifficulty) {
  42. List<CompleteQuestionVO> questionVO = new ArrayList<>();
  43. return questionVO;
  44. }
  45. @Override
  46. public QuestionStemListVO getQuestionList(String stem, List<String> tags, List<String> knowledgeIds, Pageable pageable) {
  47. Page<QuestionVO> questionVOPageList = client.getQuestionList(stem, tags, knowledgeIds, pageable);
  48. return new QuestionStemListVO(BeanCopyUtil.copyListProperties(questionVOPageList.toList(), QuestionStemVO::new), (int) questionVOPageList.getTotalElements());
  49. }
  50. @Override
  51. public List<KnowledgeNodeVO> getKnowledgeNode(String name) {
  52. return client.getKnowledgeNode(name);
  53. }
  54. }