فهرست منبع

fix : 更正test,逐步重构api

XuShengTao 6 سال پیش
والد
کامیت
9f8a1da6ab
24فایلهای تغییر یافته به همراه429 افزوده شده و 61 حذف شده
  1. 1 1
      src/main/java/com/seec/bok/back/controller/V2QuestionController.java
  2. 1 1
      src/main/java/com/seec/bok/back/controller/WebRestfulController.java
  3. 1 0
      src/main/java/com/seec/bok/back/domainobject/QuestionDO.java
  4. 0 24
      src/main/java/com/seec/bok/back/domainobject/QuestionType.java
  5. 7 1
      src/main/java/com/seec/bok/back/repository/QuestionRepository.java
  6. 17 0
      src/main/java/com/seec/bok/back/repository/QuestionRepositoryImp.java
  7. 14 1
      src/main/java/com/seec/bok/back/utils/Util.java
  8. 4 11
      src/main/java/com/seec/bok/proxy/ProxyController.java
  9. 28 0
      src/main/java/com/seec/bok/service/KnowledgeGraphService.java
  10. 74 0
      src/main/java/com/seec/bok/service/QuestionService.java
  11. 23 0
      src/main/java/com/seec/bok/service/exception/ApiExceptionHandler.java
  12. 22 0
      src/main/java/com/seec/bok/service/exception/Asserts.java
  13. 11 0
      src/main/java/com/seec/bok/service/exception/EntityNotAvailableException.java
  14. 15 0
      src/main/java/com/seec/bok/service/exception/EntityNotFoundException.java
  15. 17 0
      src/main/java/com/seec/bok/service/exception/ErrorResponse.java
  16. 36 0
      src/main/java/com/seec/bok/service/exception/ServiceException.java
  17. 14 4
      src/main/java/com/seec/bok/web/controller/KnowledgeController.java
  18. 16 7
      src/main/java/com/seec/bok/web/controller/QuestionController.java
  19. 38 0
      src/main/java/com/seec/bok/web/dto/PageDTO.java
  20. 3 2
      src/main/java/com/seec/bok/web/util/FakeQuestionData.java
  21. 16 0
      src/main/java/com/seec/bok/web/vo/KnowledgeNodeVO.java
  22. 1 1
      src/main/java/com/seec/bok/web/vo/PageVO.java
  23. 67 5
      src/main/java/com/seec/bok/web/vo/QuestionVO.java
  24. 3 3
      src/test/java/com/seec/bok/QuestionTests.java

+ 1 - 1
src/main/java/com/seec/bok/back/controller/QuestionController.java → src/main/java/com/seec/bok/back/controller/V2QuestionController.java

@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.*;
  **/
 @RepositoryRestController
 @RequestMapping("/v2/question")
-public class QuestionController {
+public class V2QuestionController {
     @Autowired
     @Qualifier("QuestionRepositoryImp") // inject Spring implementation here
     private QuestionRepository questionRepository;

+ 1 - 1
src/main/java/com/seec/bok/back/controller/WebRestfulController.java

@@ -2,12 +2,12 @@ package com.seec.bok.back.controller;
 
 import com.seec.bok.back.domainobject.Pdf;
 import com.seec.bok.back.domainobject.QuestionDO;
-import com.seec.bok.back.domainobject.QuestionType;
 import com.seec.bok.back.entity.ChoiceQuestion;
 import com.seec.bok.back.entity.Question;
 import com.seec.bok.back.repository.QuestionRepository;
 import com.seec.bok.back.repository.TQRepository;
 import com.seec.bok.back.utils.Util;
+import com.seec.bok.web.vo.constant.QuestionType;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;

+ 1 - 0
src/main/java/com/seec/bok/back/domainobject/QuestionDO.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.seec.bok.back.entity.ChoiceQuestion;
 import com.seec.bok.back.entity.Question;
+import com.seec.bok.web.vo.constant.QuestionType;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;

+ 0 - 24
src/main/java/com/seec/bok/back/domainobject/QuestionType.java

@@ -1,24 +0,0 @@
-package com.seec.bok.back.domainobject;
-
-public enum  QuestionType {
-    /**
-     * 选择题
-     */
-    choice,
-    /**
-     * 判断题
-     */
-    true_false,
-    /**
-     * 多选题
-     */
-    multiple_choice,
-    /**
-     * 填空题
-     */
-    blank,
-    /**
-     * 简答题
-     */
-    short_answer
-}

+ 7 - 1
src/main/java/com/seec/bok/back/repository/QuestionRepository.java

@@ -12,9 +12,10 @@ import org.springframework.stereotype.Repository;
 
 import java.util.Collection;
 import java.util.Optional;
+import java.util.Set;
 
 @Repository("QuestionRepository")
-@RepositoryRestResource(path = "v2/question")
+@RepositoryRestResource(path = "questionRepository")
 public interface QuestionRepository extends ElasticsearchRepository<Question,String> {
     @Override
     Page<Question> findAll(Pageable pageable);
@@ -28,6 +29,11 @@ public interface QuestionRepository extends ElasticsearchRepository<Question,Str
     Page<Question> findAllByTagsContaining(String tag, Pageable pageable);
     Page<Question> findAllByTagsNotIn(Collection<String> tags, Pageable pageable);
     Page<Question> findAllByLabelsContaining(String tag, Pageable pageable);
+
+    Page<Question> findByStemLikeAndLabelsContainingAndKnowledgeIdsContaining(String stem, String labels, String knowledgeIds, Pageable pageable);
+    Page<Question> findByStemLikeAndLabelsContaining(String stem, String knowledgeIds, Pageable pageable);
+    Page<Question> findByStemLikeAndKnowledgeIdsContaining(String stem, String knowledgeIds, Pageable pageable);
+
     @Override
     <S extends Question> S save(S s);
 }

+ 17 - 0
src/main/java/com/seec/bok/back/repository/QuestionRepositoryImp.java

@@ -14,12 +14,24 @@ import org.springframework.stereotype.Repository;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Optional;
+import java.util.Set;
+
 @Repository("QuestionRepositoryImp")
 public class QuestionRepositoryImp implements QuestionRepository{
     @Autowired
     @Qualifier("QuestionRepository") // inject Spring implementation here
     private QuestionRepository questionRepository;
 
+    @Override
+    public Page<Question> findByStemLikeAndLabelsContaining(String stem, String knowledgeIds, Pageable pageable) {
+        return questionRepository.findByStemLikeAndLabelsContaining(stem, knowledgeIds, pageable);
+    }
+
+    @Override
+    public Page<Question> findByStemLikeAndKnowledgeIdsContaining(String stem, String knowledgeIds, Pageable pageable) {
+        return questionRepository.findByStemLikeAndKnowledgeIdsContaining(stem, knowledgeIds, pageable);
+    }
+
     @Override
     public Page<Question> findAll(Pageable pageable) {
         return questionRepository.findAll(pageable);
@@ -60,6 +72,11 @@ public class QuestionRepositoryImp implements QuestionRepository{
         return questionRepository.findAllByLabelsContaining(tag,pageable);
     }
 
+    @Override
+    public Page<Question> findByStemLikeAndLabelsContainingAndKnowledgeIdsContaining(String stem, String labels, String knowledgeIds, Pageable pageable) {
+        return questionRepository.findByStemLikeAndLabelsContainingAndKnowledgeIdsContaining(stem,labels,knowledgeIds,pageable);
+    }
+
     @Override
     public <S extends Question> S save(S s) {
         s.setLastModifiedTime(new Date());

+ 14 - 1
src/main/java/com/seec/bok/back/utils/Util.java

@@ -1,11 +1,16 @@
 package com.seec.bok.back.utils;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.http.*;
+import org.springframework.web.client.RestTemplate;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
 public class Util {
     private static ObjectMapper objectMapper=new ObjectMapper();
@@ -23,5 +28,13 @@ public class Util {
         bufferedReader.close();
         return ret.toString();
     }
-
+    public static List sendPostRequest(String url, Map<String, String> params) throws JsonProcessingException {
+        RestTemplate client = new RestTemplate();
+        HttpHeaders headers = new HttpHeaders();
+        HttpMethod method = HttpMethod.POST;
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        HttpEntity<Map> requestEntity = new HttpEntity<>(params, headers);
+        ResponseEntity ret = client.postForEntity(url, requestEntity, List.class);
+        return (List) ret.getBody();
+    }
 }

+ 4 - 11
src/main/java/com/seec/bok/proxy/ProxyController.java

@@ -1,6 +1,7 @@
 package com.seec.bok.proxy;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.seec.bok.back.utils.Util;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.MediaType;
@@ -37,7 +38,7 @@ public class ProxyController {
 
         List ret= null;
         try {
-            ret = sendPostRequest(sklearnAddress+"/predict",body);
+            ret = Util.sendPostRequest(sklearnAddress+"/predict",body);
         } catch (JsonProcessingException e) {
             System.out.println(e.getMessage());
             e.printStackTrace();
@@ -48,7 +49,7 @@ public class ProxyController {
 
         List ret= null;
         try {
-            ret = sendPostRequest(neoAddress+"/api/user/getAll",body);
+                ret = Util.sendPostRequest(neoAddress+"/api/user/getAll",body);
         } catch (JsonProcessingException e) {
             System.out.println(e.getMessage());
             e.printStackTrace();
@@ -56,13 +57,5 @@ public class ProxyController {
         return ret;
     }
 
-    public static List sendPostRequest(String url, Map<String, String> params) throws JsonProcessingException {
-        RestTemplate client = new RestTemplate();
-        HttpHeaders headers = new HttpHeaders();
-        HttpMethod method = HttpMethod.POST;
-        headers.setContentType(MediaType.APPLICATION_JSON);
-        HttpEntity<Map> requestEntity = new HttpEntity<>(params, headers);
-        ResponseEntity ret = client.postForEntity(url, requestEntity, List.class);
-        return (List) ret.getBody();
-    }
+
 }

+ 28 - 0
src/main/java/com/seec/bok/service/KnowledgeGraphService.java

@@ -0,0 +1,28 @@
+package com.seec.bok.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.seec.bok.back.utils.Util;
+import com.seec.bok.web.vo.KnowledgeNodeVO;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+public class KnowledgeGraphService {
+    @Value("${proxy.neo}")
+    protected String neoAddress;
+
+    public Collection<KnowledgeNodeVO> getKnowledgeNode(String name) throws JsonProcessingException {
+        Map<String,String> body = new HashMap<>(2);
+        if(name ==null){name ="";}
+        body.put("name",name);
+        body.put("relation","part of");
+        List<Map> resBody = Util.sendPostRequest(neoAddress+"/api/user/getAll",body);
+        Collection<KnowledgeNodeVO> ret = (Collection<KnowledgeNodeVO>)resBody.stream()
+                .map(KnowledgeNodeVO::of)
+                .collect(Collectors.toList());
+        return ret;
+    }
+}

+ 74 - 0
src/main/java/com/seec/bok/service/QuestionService.java

@@ -0,0 +1,74 @@
+package com.seec.bok.service;
+
+import com.seec.bok.back.entity.Question;
+import com.seec.bok.back.repository.QuestionRepository;
+import com.seec.bok.service.exception.EntityNotFoundException;
+import com.seec.bok.web.util.FakeQuestionData;
+import com.seec.bok.web.vo.PageVO;
+import com.seec.bok.web.vo.PageableQuestionListVO;
+import com.seec.bok.web.vo.QuestionVO;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Service
+public class QuestionService {
+    @Autowired
+    @Qualifier("QuestionRepositoryImp") // inject Spring implementation here
+    private QuestionRepository questionRepository;
+
+    public Page<Question> findByIdIn(Collection<String> id, Pageable pageable) {
+        return questionRepository.findByIdIn(id, pageable);
+    }
+
+    public QuestionVO findOne(String id) {
+        final Question question = questionRepository.findById(id).orElseThrow(EntityNotFoundException::new);
+        return QuestionVO.of(question);
+    }
+    private boolean noValue(String value){
+        return (value==null||"".equals(value));
+    }
+    public PageableQuestionListVO search(String stem, String labels, String knowledgeIds, Pageable pageable) {
+        Page<Question> questionPage=null;
+        if(stem==null){stem="";}
+        if(noValue(knowledgeIds)&&noValue(labels)){
+            questionPage = questionRepository.findByStemLike(stem, pageable);
+        }else if (noValue(knowledgeIds)){
+            questionPage = questionRepository.findByStemLikeAndLabelsContaining(stem,labels, pageable);
+        }else if (noValue(labels)){
+            questionPage = questionRepository.findByStemLikeAndKnowledgeIdsContaining(stem,knowledgeIds, pageable);
+        }else {
+            questionPage = questionRepository.findByStemLikeAndLabelsContainingAndKnowledgeIdsContaining(stem,labels,knowledgeIds, pageable);
+        }
+
+
+        PageableQuestionListVO vos=PageableQuestionListVO.builder()
+                .questions(questionPage.getContent().stream().map(QuestionVO::of).collect(Collectors.toList()))
+                .page(
+                        PageVO.builder()
+                                .size(questionPage.getSize())
+                                .totalPages(questionPage.getTotalPages())
+                                .totalElements(questionPage.getTotalElements())
+                                .number(questionPage.getNumber())
+                                .build())
+                .build();
+        return vos;
+    }
+
+    public QuestionVO updateQuestion(QuestionVO vo) {
+        return QuestionVO.of(questionRepository.save(vo.toEntity()));
+    }
+
+    public Page<Question> search(QueryBuilder query, Pageable pageable) {
+        return questionRepository.search(query, pageable);
+    }
+}

+ 23 - 0
src/main/java/com/seec/bok/service/exception/ApiExceptionHandler.java

@@ -0,0 +1,23 @@
+package com.seec.bok.service.exception;
+
+import org.apache.http.HttpStatus;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.servlet.http.HttpServletResponse;
+
+@RestControllerAdvice({"com.seec.bok.web.controller"})
+public class ApiExceptionHandler {
+	@ExceptionHandler(Exception.class)
+	@ResponseBody
+	public ErrorResponse handle(HttpServletResponse response, Exception exception) {
+		int error = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+		if (exception instanceof ServiceException) {
+			error = ((ServiceException) exception).getError();
+		}
+		response.setStatus(error);
+		exception.printStackTrace();
+		return new ErrorResponse(error, exception.getMessage());
+	}
+}

+ 22 - 0
src/main/java/com/seec/bok/service/exception/Asserts.java

@@ -0,0 +1,22 @@
+package com.seec.bok.service.exception;
+
+public abstract class Asserts {
+	public static void notNull(Object object) throws EntityNotFoundException {
+		if (object == null) {
+			throw new EntityNotFoundException();
+		}
+	}
+
+	public static void notNull(Object object, String message) throws EntityNotFoundException {
+		if (object == null) {
+			throw new EntityNotFoundException(message);
+		}
+	}
+
+//	public static void isNull(Object object, String message) throws EntityConflictException {
+//		if (object != null) {
+//			throw new EntityConflictException(message);
+//		}
+//	}
+
+}

+ 11 - 0
src/main/java/com/seec/bok/service/exception/EntityNotAvailableException.java

@@ -0,0 +1,11 @@
+package com.seec.bok.service.exception;
+
+import org.springframework.http.HttpStatus;
+
+public class EntityNotAvailableException extends ServiceException {
+	private static final HttpStatus HTTP_STATUS = HttpStatus.UNPROCESSABLE_ENTITY;
+
+	public EntityNotAvailableException(String message) {
+		super(HTTP_STATUS.value(), message);
+	}
+}

+ 15 - 0
src/main/java/com/seec/bok/service/exception/EntityNotFoundException.java

@@ -0,0 +1,15 @@
+package com.seec.bok.service.exception;
+
+import org.springframework.http.HttpStatus;
+
+public class EntityNotFoundException extends ServiceException {
+	private static final HttpStatus HTTP_STATUS = HttpStatus.NOT_FOUND;
+
+	public EntityNotFoundException() {
+		this(HTTP_STATUS.getReasonPhrase());
+	}
+
+	public EntityNotFoundException(String message) {
+		super(HTTP_STATUS.value(), message);
+	}
+}

+ 17 - 0
src/main/java/com/seec/bok/service/exception/ErrorResponse.java

@@ -0,0 +1,17 @@
+package com.seec.bok.service.exception;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+public class ErrorResponse  {
+	@JsonProperty("message")
+	private String message;
+    @JsonProperty("code")
+    private int err;
+	public ErrorResponse(int err, String message) {
+	    this.err=err;
+		this.message = message;
+	}
+}

+ 36 - 0
src/main/java/com/seec/bok/service/exception/ServiceException.java

@@ -0,0 +1,36 @@
+package com.seec.bok.service.exception;
+
+import lombok.Getter;
+import lombok.ToString;
+import org.springframework.http.HttpStatus;
+
+@Getter
+@ToString
+public class ServiceException extends RuntimeException {
+	private int error;
+
+	public ServiceException() {
+		this(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
+	}
+
+	public ServiceException(int error) {
+		this(error, message(error));
+	}
+
+	public ServiceException(String message) {
+		this(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
+	}
+
+	public ServiceException(int error, String message) {
+		super(message);
+		this.error = error;
+	}
+
+	private static String message(int error) {
+		try {
+			return HttpStatus.valueOf(error).getReasonPhrase();
+		} catch (IllegalArgumentException e) {
+			return HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase();
+		}
+	}
+}

+ 14 - 4
src/main/java/com/seec/bok/web/controller/KnowledgeController.java

@@ -1,23 +1,33 @@
 package com.seec.bok.web.controller;
 
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.seec.bok.service.KnowledgeGraphService;
 import com.seec.bok.web.vo.KnowledgeNodeVO;
 import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 /** @author Kunduin */
 @RestController
 @RequestMapping("/api/knowledge")
 public class KnowledgeController {
-
+    @Autowired
+    private KnowledgeGraphService knowledgeGraphService;
     @GetMapping("")
     @Operation(description = "获得知识点列表")
-    public List<KnowledgeNodeVO> getKnowledgeNode() {
-        return Collections.emptyList();
+    public List<KnowledgeNodeVO> getKnowledgeNode(
+            @RequestParam(value = "name", required = false)
+            @Parameter(description = "知识点name包含关键词")
+                    String name) throws JsonProcessingException {
+        System.out.println("ss:"+name);
+        return new ArrayList<>(knowledgeGraphService.getKnowledgeNode(name));
     }
 }

+ 16 - 7
src/main/java/com/seec/bok/web/controller/QuestionController.java

@@ -1,34 +1,44 @@
 package com.seec.bok.web.controller;
 
 
+import com.seec.bok.service.QuestionService;
 import com.seec.bok.web.dto.PageDTO;
 import com.seec.bok.web.util.FakeQuestionData;
 import com.seec.bok.web.vo.PageableQuestionListVO;
 import com.seec.bok.web.vo.QuestionVO;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 /** @author Kunduin */
 @RestController
 @RequestMapping("/api/question")
 public class QuestionController {
-
+    @Autowired
+    private QuestionService questionService;
     @GetMapping("")
     @Operation(description = "获得题目列表")
     public PageableQuestionListVO getQuestionList(
             @RequestParam(value = "stem", required = false) @Parameter(description = "模糊查找题目")
                     String stem,
             @RequestParam(value = "tag", required = false) @Parameter(description = "模糊查找题目")
-                    List<String> tag,
+                    String tag,
             @RequestParam(value = "knowledgeId", required = false)
                     @Parameter(description = "模糊查找题目")
-                    List<String> knowledgeId,
+                    String knowledgeId,
             PageDTO pageDTO) {
-        return FakeQuestionData.buildPageableList();
+
+        //生成Pageable变量
+        Pageable pageable = PageRequest.of(pageDTO.getPage() - 1, pageDTO.getSize(),pageDTO.toSort());
+        return questionService.search(stem,tag,knowledgeId,pageable);
     }
 
     @PostMapping("")
@@ -41,7 +51,7 @@ public class QuestionController {
     @GetMapping("/{questionId}")
     @Operation(description = "获得题目详情")
     public QuestionVO getQuestionById(@PathVariable String questionId) {
-        return FakeQuestionData.build(questionId);
+        return questionService.findOne(questionId);
     }
 
     @PutMapping("/{questionId}")
@@ -52,8 +62,7 @@ public class QuestionController {
     }
 
     @DeleteMapping("/{questionId}")
-    @Operation(description = "删除题目")
     public Object deleteQuestionById(@PathVariable String questionId) {
-        return new Object();
+        return null;
     }
 }

+ 38 - 0
src/main/java/com/seec/bok/web/dto/PageDTO.java

@@ -1,7 +1,9 @@
 package com.seec.bok.web.dto;
 
 import lombok.Data;
+import org.springframework.data.domain.Sort;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /** @author Kunduin */
@@ -10,4 +12,40 @@ public class PageDTO {
     Integer size;
     Integer page;
     List<String> sort;
+    public Sort toSort(){
+        List<Sort.Order> orders=new ArrayList<>();
+        String property=null;
+        Sort.Direction direction=null;
+        if(sort==null){
+            return Sort.unsorted();
+        }
+        for(String para:sort){
+            if(Sort.Direction.ASC.toString().toLowerCase().equals(para.toLowerCase())){
+                direction=Sort.Direction.ASC;
+            }else if(Sort.Direction.DESC.toString().toLowerCase().equals(para.toLowerCase())){
+                direction=Sort.Direction.DESC;
+            }else{
+                if(property!=null){
+                    if(direction!=null){
+                        orders.add(new Sort.Order(direction,property));
+                        property=null;
+                        direction=null;
+                    }else{
+                        orders.add(Sort.Order.by(property));
+                        property=null;
+                    }
+                }
+                property=para;
+            }
+
+        }
+        if(property!=null){
+            if(direction!=null){
+                orders.add(new Sort.Order(direction,property));
+            }else{
+                orders.add(Sort.Order.by(property));
+            }
+        }
+        return Sort.by(orders);
+    }
 }

+ 3 - 2
src/main/java/com/seec/bok/web/util/FakeQuestionData.java

@@ -5,6 +5,7 @@ package com.seec.bok.web.util;
 import com.seec.bok.web.vo.PageVO;
 import com.seec.bok.web.vo.PageableQuestionListVO;
 import com.seec.bok.web.vo.QuestionVO;
+import com.seec.bok.web.vo.constant.QuestionType;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -25,7 +26,7 @@ public class FakeQuestionData {
                         PageVO.builder()
                                 .size(5)
                                 .totalPages(205)
-                                .totalElements(1022)
+                                .totalElements(1022L)
                                 .number(1)
                                 .build())
                 .build();
@@ -38,7 +39,7 @@ public class FakeQuestionData {
     public static QuestionVO build(String id) {
         return QuestionVO.builder()
                 .id(id)
-                .type("choice")
+                .type(QuestionType.choice)
                 .stem("海明校验码是在 n 个数据位之外增设上个校验位,从而形成一个 k+n 位的新的码字, 使新的码字的码距比较均匀地拉大。n 与 k 的关系是( )。")
                 .options(
                         new HashMap<String, String>() {

+ 16 - 0
src/main/java/com/seec/bok/web/vo/KnowledgeNodeVO.java

@@ -1,11 +1,17 @@
 package com.seec.bok.web.vo;
 
+import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
 
 /** @author Kunduin */
 @Data
 @Builder
+@AllArgsConstructor
+@NoArgsConstructor
 public class KnowledgeNodeVO {
 
     /** 缩写为实际使用的唯一标识 */
@@ -15,4 +21,14 @@ public class KnowledgeNodeVO {
     private String englishName;
     private String parentId;
     private String parentName;
+    public static KnowledgeNodeVO of(Map<String,String> neo){
+        KnowledgeNodeVO knowledgeNodeVO=new KnowledgeNodeVO();
+        knowledgeNodeVO.abbreviation = neo.get("abbreviation");
+        knowledgeNodeVO.name = neo.get("name");
+        knowledgeNodeVO.englishName = neo.get("name_eng");
+        knowledgeNodeVO.parentId = neo.get("parentId");
+        knowledgeNodeVO.parentName = neo.get("parentName");
+        return knowledgeNodeVO;
+    }
+
 }

+ 1 - 1
src/main/java/com/seec/bok/web/vo/PageVO.java

@@ -8,7 +8,7 @@ import lombok.Data;
 @Builder
 public class PageVO {
     Integer size;
-    Integer totalElements;
+    Long totalElements;
     Integer totalPages;
     Integer number;
 }

+ 67 - 5
src/main/java/com/seec/bok/web/vo/QuestionVO.java

@@ -1,19 +1,26 @@
 package com.seec.bok.web.vo;
 
+import com.seec.bok.back.entity.Question;
+import com.seec.bok.web.vo.constant.QuestionType;
+import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.beans.BeanUtils;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
-/** @author Kunduin */
+/** @author Kunduin, sheen
+ * */
 @Data
 @Builder
+@NoArgsConstructor
+@AllArgsConstructor
 public class QuestionVO {
     String id;
-    String type;
+    QuestionType type;
     String stem;
+
     Map<String, String> options;
 
     /** 填空题 __1__ __2__ */
@@ -22,7 +29,62 @@ public class QuestionVO {
     String answer;
     String keyPoints;
     String analysis;
+
     List<String> tags;
     List<String> knowledgeId;
     Date lastModifiedTime;
+
+    public Question toEntity(){
+        Question question=new Question();
+        question.setId(this.id);
+        question.setType(this.type.toString());
+        question.setStem(this.getStem());
+
+        question.setLabels(new HashSet<>());
+        question.getLabels().addAll(this.tags);
+
+        question.setKnowledgeIds(new HashSet<>());
+        question.getKnowledgeIds().addAll(this.knowledgeId);
+
+        question.setLastModifiedTime(this.lastModifiedTime);
+
+        question.setAnalysis(this.analysis);
+        question.setKeyPoints(this.keyPoints);
+        question.setAnswer(this.answer);
+
+        if(QuestionType.blank.equals(this.type)){
+            question.setOptions(new HashMap<>(Optional.ofNullable(this.blanks).orElse(new HashMap<>(0))));
+        }else{
+            question.setOptions(new HashMap<>(Optional.ofNullable(this.options).orElse(new HashMap<>(0))));
+        }
+        return question;
+    }
+    public static QuestionVO of(Question question){
+        QuestionVO vo =new QuestionVO();
+        vo.id=question.getId();
+        vo.type=QuestionType.valueOf(question.getType());
+        vo.stem=question.getStem();
+
+        vo.tags=new ArrayList<>();
+        if(question.getLabels()!=null&&question.getLabels().size()>0){
+            vo.tags.addAll(question.getLabels());
+        }
+        vo.knowledgeId=new ArrayList<>();
+        if(question.getKnowledgeIds()!=null&&question.getKnowledgeIds().size()>0){
+            vo.knowledgeId.addAll(question.getKnowledgeIds());
+        }
+        vo.lastModifiedTime=question.getLastModifiedTime();
+
+        vo.analysis=question.getAnalysis();
+        vo.keyPoints=question.getKeyPoints();
+        vo.answer=question.getAnswer();
+
+        if(QuestionType.blank.equals(vo.type)){
+            if(question.getOptions()==null){}
+            vo.blanks=new HashMap<>((Map)(Optional.ofNullable(question.getOptions()).orElse(new HashMap<>())));
+        }else{
+            vo.options=new HashMap<>((Map)(Optional.ofNullable(question.getOptions()).orElse(new HashMap<>())));
+        }
+        return vo;
+    }
 }

+ 3 - 3
src/test/java/com/seec/bok/QuestionTests.java

@@ -57,7 +57,7 @@ public class QuestionTests {
 
     @Test
     public void test01_GetQuestionIdsIn() throws Exception {
-        Request request=new Request(HttpMethod.GET,"/api/question/search/findByIdIn?id={id}&page={page}&size={size}&sort={sort}");
+        Request request=new Request(HttpMethod.GET,"/api/questionRepository/search/findByIdIn?id={id}&page={page}&size={size}&sort={sort}");
         request.put("id",new int[]{1001,1002});
         request.put("page",1);
         request.put("size",5);
@@ -136,11 +136,11 @@ public class QuestionTests {
 
     @Test
     public void test06_findByStemLike() throws Exception {
-        Request request=new Request(HttpMethod.GET,"/api/question/search/findByStemLike?content={content}&page={page}&size={size}&sort={sort}");
+        Request request=new Request(HttpMethod.GET,"/api/question?stem={content}&page={page}&size={size}&sort={sort}");
         request.put("content","测试");
         request.put("page",1);
         request.put("size",1);
-        request.put("sort","lastModified,DESC");
+        request.put("sort","id,DESC");
         Map ret = request.execute(Map.class);
         System.out.println(request.OutToString(
                 "findByStemLike:根据题干模糊问题,需要提供stem"