Jelajahi Sumber

试卷结构增加机构分离

宋悦 8 tahun lalu
induk
melakukan
3dcea9a92c

+ 16 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java

@@ -32,16 +32,14 @@ public class PaperStructService {
     PaperStructRepo paperStructRepo;
 
     /**
-     * 获取所有试卷结构
+     * 获取所有试卷结构(分页)
      * 
      * @param searchInfo
      * @param curPage
      * @param pageSize
      * @return
      */
-    public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize,
-            AccessUser user) {
-        searchInfo.setOrgId(user.getRootOrgId().toString());
+    public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize) {
         formatSearchInfo(searchInfo);
         PaperStruct paperStruct = BeanCopierUtil.copyProperties(searchInfo, PaperStruct.class);
         formatPaperStruct(paperStruct);
@@ -50,6 +48,20 @@ public class PaperStructService {
         return paperStructRepo.findAll(Example.of(paperStruct, matcher), new PageRequest(curPage - 1, pageSize));
     }
 
+    /**
+     * 获取所有试卷结构(分页)
+     * @param searchInfo
+     * @return
+     */
+    public List<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo) {
+        formatSearchInfo(searchInfo);
+        PaperStruct paperStruct = BeanCopierUtil.copyProperties(searchInfo, PaperStruct.class);
+        formatPaperStruct(paperStruct);
+        ExampleMatcher matcher = ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
+                .withIgnoreNullValues();
+        return paperStructRepo.findAll(Example.of(paperStruct, matcher));
+    }
+
     public void formatSearchInfo(PaperStructSearchInfo searchInfo) {
         if (StringUtils.isEmpty(searchInfo.getName())) {
             searchInfo.setName(null);

+ 19 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructController.java

@@ -7,6 +7,7 @@ import java.util.stream.Stream;
 import javax.servlet.http.HttpServletRequest;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -45,31 +46,39 @@ public class PaperStructController {
 
     /**
      * 获取所有试卷结构
-     * 
      * @param
      * @return
      */
     @ApiOperation(value = "获取试卷结构带分页", notes = "获取试卷结构带分页")
     @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
     @GetMapping(value = "/paperStruct/{curPage}/{pageSize}")
-    public ResponseEntity getPaperStructs(HttpServletRequest request, @ModelAttribute PaperStructSearchInfo searchInfo,
-            @PathVariable int curPage, @PathVariable int pageSize) {
-        AccessUser user = (AccessUser) request.getAttribute("accessUser");
-        return new ResponseEntity(paperStructService.getPaperStructs(searchInfo, curPage, pageSize, user),
-                HttpStatus.OK);
+    public ResponseEntity getPaperStructs(HttpServletRequest request,
+                                          @ModelAttribute PaperStructSearchInfo searchInfo,
+                                          @PathVariable int curPage,
+                                          @PathVariable int pageSize) {
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            searchInfo.setOrgId(String.valueOf(accessUser.getRootOrgId()));
+        }
+        Page<PaperStruct> paperStructs= paperStructService.getPaperStructs(searchInfo, curPage, pageSize);
+        return new ResponseEntity(paperStructs, HttpStatus.OK);
     }
 
     /**
      * 获取所有试卷结构
-     * 
      * @param
      * @return
      */
-    @ApiOperation(value = "获取试卷结构", notes = "获取试卷结构")
+    @ApiOperation(value = "获取试卷结构不带分页", notes = "获取试卷结构不带分页")
     @GetMapping(value = "/paperStruct")
     @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
-    public ResponseEntity findAll() {
-        return new ResponseEntity(paperStructRepo.findAll(), HttpStatus.OK);
+    public ResponseEntity getPaperStructs(HttpServletRequest request,@ModelAttribute PaperStructSearchInfo searchInfo) {
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            searchInfo.setOrgId(String.valueOf(accessUser.getRootOrgId()));
+        }
+        List<PaperStruct> paperStructs = paperStructService.getPaperStructs(searchInfo);
+        return new ResponseEntity(paperStructs, HttpStatus.OK);
     }
 
     /**