package com.nju.edu.eval.thirdparty.thirdpartyImpl; import cn.seecoder.bok.client.SeecoderBokClient; import cn.seecoder.bok.common.vo.KnowledgeNodeVO; import cn.seecoder.bok.common.vo.QuestionVO; import com.nju.edu.eval.model.vo.question.CompleteQuestionVO; import com.nju.edu.eval.model.vo.question.QuestionStemListVO; import com.nju.edu.eval.model.vo.question.QuestionStemVO; import com.nju.edu.eval.thirdparty.QuestionThirdPartyService; import com.nju.edu.eval.util.BeanCopyUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import java.util.Optional; /** * @author mars * 封装调用的题库的第三方服务 */ @Component public class QuestionThirdPartyServiceImpl implements QuestionThirdPartyService { @Value("${seec-bok-client.host}") private String host; private SeecoderBokClient client; @PostConstruct public void init() { //TODO client = new SeecoderBokClient(host); } @Override public Optional getQuestionById(String id) { Optional response = client.getQuestionById(id); CompleteQuestionVO res = new CompleteQuestionVO(); response.ifPresent(questionVO -> BeanUtils.copyProperties(questionVO, res)); return Optional.of(res); } @Override public List getRecommendQuestions(List knowledgeList, int expectedDifficulty) { List questionVO = new ArrayList<>(); return questionVO; } @Override public QuestionStemListVO getQuestionList(String stem, List tags, List knowledgeIds, Pageable pageable) { Page questionVOPageList = client.getQuestionList(stem, tags, knowledgeIds, pageable); return new QuestionStemListVO(BeanCopyUtil.copyListProperties(questionVOPageList.toList(), QuestionStemVO::new), (int) questionVOPageList.getTotalElements()); } @Override public List getKnowledgeNode(String name) { return client.getKnowledgeNode(name); } }