|
@@ -3,6 +3,7 @@ package nju.seec.helper.service.impl;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import nju.seec.helper.dto.LoginUser;
|
|
import nju.seec.helper.dto.LoginUser;
|
|
|
import nju.seec.helper.service.QuestionService;
|
|
import nju.seec.helper.service.QuestionService;
|
|
|
|
|
+import nju.seec.helper.util.BOKUtil;
|
|
|
import nju.seec.helper.util.JsonUtils;
|
|
import nju.seec.helper.util.JsonUtils;
|
|
|
import nju.seec.helper.util.RestRequestUtil;
|
|
import nju.seec.helper.util.RestRequestUtil;
|
|
|
import nju.seec.helper.util.enums.QuestionKindState;
|
|
import nju.seec.helper.util.enums.QuestionKindState;
|
|
@@ -25,54 +26,17 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
@Service
|
|
|
public class QuestionServiceImpl implements QuestionService {
|
|
public class QuestionServiceImpl implements QuestionService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private RestRequestUtil restRequestUtil;
|
|
|
|
|
|
|
+ private BOKUtil bokUtil;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Page<QuestionVO> getQuestionList(LoginUser user, String stem, Pageable pageable) throws JsonProcessingException {
|
|
public Page<QuestionVO> getQuestionList(LoginUser user, String stem, Pageable pageable) throws JsonProcessingException {
|
|
|
List<QuestionVO> Questions = new ArrayList<QuestionVO>();
|
|
List<QuestionVO> Questions = new ArrayList<QuestionVO>();
|
|
|
Map page = new HashMap();
|
|
Map page = new HashMap();
|
|
|
- BokFindByStemLike(stem, Questions,page,pageable);
|
|
|
|
|
|
|
+ bokUtil.BokFindByStemLike(stem, Questions,page,pageable);
|
|
|
Page<QuestionVO> ret =new PageImpl<QuestionVO>(Questions,pageable,Long.valueOf((Integer)page.get("totalElements")));
|
|
Page<QuestionVO> ret =new PageImpl<QuestionVO>(Questions,pageable,Long.valueOf((Integer)page.get("totalElements")));
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
- // 应该做成bok的库
|
|
|
|
|
- private void BokFindByStemLike(String stem,List<QuestionVO> Questions, Map page,Pageable pageable) {
|
|
|
|
|
|
|
|
|
|
- Map<String,String> urlParams=new HashMap<>();
|
|
|
|
|
- urlParams.put("content",stem);
|
|
|
|
|
- urlParams.put("sort",pageable.getSort().toString().replaceAll(" ","").replaceAll(":",","));
|
|
|
|
|
- urlParams.put("size",String.valueOf(pageable.getPageSize()));
|
|
|
|
|
- urlParams.put("page",String.valueOf(1+pageable.getPageNumber()));
|
|
|
|
|
- try {
|
|
|
|
|
- Map ret = (Map)restRequestUtil.sendPostGet(
|
|
|
|
|
- "http://bok.seecoder.cn/api/tq/search/findByStemLike?content={content}&sort={sort}&size={size}&page={page}", urlParams);
|
|
|
|
|
|
|
|
|
|
- List<Map> tqs= ((List)((Map)ret.get("_embedded")).get("choiceQuestions"));
|
|
|
|
|
|
|
|
|
|
- final List collect = tqs.stream().map(q -> {
|
|
|
|
|
- switch ((String) q.get("type")) {
|
|
|
|
|
- case "choice":
|
|
|
|
|
- return ChoiceQuestionVO.builder().stem((String) q.get("stem")).kind(QuestionKindState.CHOICE)
|
|
|
|
|
- .options((Map<String, String>) q.get("options")).answer(((String) q.get("answer")).replaceAll("【答案】", ""))
|
|
|
|
|
- .analysis((String) q.get("analysis")).QuestionId(String.valueOf((Integer) q.get("tq_id"))).build();
|
|
|
|
|
-
|
|
|
|
|
- case "true_false":
|
|
|
|
|
- return TrueOrFalseQuestionVO.builder().stem((String) q.get("stem")).kind(QuestionKindState.CHOICE)
|
|
|
|
|
- .answer((Boolean) (q.get("answer")))
|
|
|
|
|
- .analysis((String) q.get("analysis")).QuestionId(String.valueOf((Integer) q.get("tq_id"))).build();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- return new Exception("unknown type:" + (String) q.get("type"));
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
- try {
|
|
|
|
|
- page.putAll((Map)ret.get("page"));
|
|
|
|
|
- Questions.addAll(collect);
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|