Browse Source

调整类型查询和类型下量表查询

zsf 1 year ago
parent
commit
13250b807d

+ 3 - 0
src/main/java/com/rf/psychological/dao/repository/CategorySubjectRepository.java

@@ -18,6 +18,9 @@ public interface CategorySubjectRepository extends BaseRepository<CategorySubjec
     @Query(value = "select id,ename,flag from t_category_subject where flag=:flag  ", nativeQuery = true)
     List<CategorySubjectEntity> findByFlag(@Param("flag") String flag);
 
+    @Query(value = "select flag from t_category_subject where ename=:ename  ", nativeQuery = true)
+    List<String> findByEname(String ename);
+
     @Transactional
     @Modifying
     @Query(value = "delete from t_category_subject where flag=:flag  ", nativeQuery = true)

+ 2 - 5
src/main/java/com/rf/psychological/rest/ServerController.java

@@ -603,14 +603,11 @@ public class ServerController extends BaseController {
         } else {
             if (categoryEname.equals("ALL")) {
                 Page<SubjectEntity> userAuth = userService.findUserAuth(uId, pageNum, pageSize, scaleName);
-//            subjectEntityList = this.subjectService.getSubjectListByAuth(pageNum, pageSize, scaleName, institutionNo);
-//            System.out.println(subjectEntityList.size());
-//            num = this.subjectService.allNumByAuth(scaleName, "", institutionNo);
+
                 subjectEntityList = userAuth.getContent();
                 num = userAuth.getTotalElements();
             } else {
-//            subjectEntityList = this.subjectService.getSubjectListByAuthAndCategory(pageNum, pageSize, scaleName, categoryEname, institutionNo);
-//            num = (long) this.subjectService.allNumByAuth(scaleName, categoryEname, institutionNo);
+
                 Page<SubjectEntity> userAuthAndCateEName = this.subjectService.findUserAuthAndCateEName(uId, scaleName, categoryEname, pageNum, pageSize);
                 subjectEntityList = userAuthAndCateEName.getContent();
                 num = userAuthAndCateEName.getTotalElements();

+ 7 - 28
src/main/java/com/rf/psychological/scale/rest/CategoryController.java

@@ -36,8 +36,7 @@ public class CategoryController extends BaseController {
     @Autowired
     private CategoryService categoryService;
 
-    @Autowired
-    private GroupInfoService groupInfoService;
+
 
     /**
      * 添加量表类别信息
@@ -75,35 +74,15 @@ public class CategoryController extends BaseController {
     @SafetyProcess
     @GetMapping("/getCategoryList")
     @ApiOperation(value = "量表查询所有类别信息")
-    public Result getCategoryList(String institutionNo, String gId) {
-        //游客用户无gid,数据库配置特定用户
-        if (StringUtils.isEmpty(gId)){
-            GroupEntity group = groupInfoService.findGroupByInstitutionNoAndName(institutionNo, Constant.DEFAULT_GROUP_NAME);
-            if (group != null){
-                gId = group.getId();
-            }
+    public Result getCategoryList() {
+        try {
+            return success(this.categoryService.findAll(Constant.DEFAULT_VALUE_ZERO));
+        }catch (Exception e){
+            return fail();
         }
-        return success(this.categoryService.findALLCategorySubject(institutionNo, gId));
     }
 
-    /**
-     * 认知任务查询所有类别信息
-     *
-     * @return
-     */
-    @SafetyProcess
-    @GetMapping("/getCognizeCategoryList")
-    @ApiOperation(value = "认知任务查询所有类别信息")
-    public Result getCognizeCategoryList(String institutionNo, String gId) {
-        //游客用户无id,数据库配置特定用户
-        if (StringUtils.isEmpty(gId)){
-            GroupEntity group = groupInfoService.findGroupByInstitutionNoAndName(institutionNo, Constant.DEFAULT_GROUP_NAME);
-            if (group != null){
-                gId = group.getId();
-            }
-        }
-        return success(this.categoryService.findAllCT(institutionNo, gId));
-    }
+
 
     /**
      * 全量查询所有类别信息-不加密,后台维护管理使用

+ 35 - 0
src/main/java/com/rf/psychological/scale/rest/SubjectController.java

@@ -2,16 +2,28 @@ package com.rf.psychological.scale.rest;
 
 import com.rf.psychological.base.rest.BaseController;
 import com.rf.psychological.dao.model.*;
+import com.rf.psychological.institution.model.InstitutionEntity;
+import com.rf.psychological.scale.dao.model.SubjectEntity;
+import com.rf.psychological.scale.service.CategorySubjectService;
 import com.rf.psychological.scale.service.ScaleService;
+import com.rf.psychological.scale.service.SubjectService;
 import com.rf.psychological.service.*;
+import com.rf.psychological.user.dao.model.UserEntity;
 import com.rf.psychological.utils.Constant;
+import com.rf.psychological.utils.PageRequestUtil;
 import com.rf.psychological.utils.Result;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.web.bind.annotation.*;
 
+import javax.persistence.criteria.Predicate;
+import java.util.ArrayList;
 import java.util.List;
 
 
@@ -40,6 +52,12 @@ public class SubjectController extends BaseController {
     @Autowired
     private CattellService cattellService;
 
+    @Autowired
+    private CategorySubjectService categorySubjectService;
+
+    @Autowired
+    private SubjectService subjectService;
+
 
  /**
      * 查询全量检测列表
@@ -68,4 +86,21 @@ public class SubjectController extends BaseController {
 
     }
 
+    @GetMapping("/getSubjectByCategory")
+    @ApiOperation("根据类型获取")
+    public Result getSubjectByCategory(int pageNum,int pageSize, String category){
+        try {
+            //先获取到该类型下量表FLAG
+            List<String> listFlag = categorySubjectService.findByEName(category);
+            if (CollectionUtils.isEmpty(listFlag)){
+                return success(null);
+            }
+            return success( subjectService.findSubjectByPage(pageNum,pageSize,listFlag));
+        }catch (Exception e){
+            log.error(e.getMessage());
+            return fail();
+        }
+    }
+
+
 }

+ 1 - 0
src/main/java/com/rf/psychological/scale/service/CategorySubjectService.java

@@ -19,6 +19,7 @@ public interface CategorySubjectService {
     void save(CategorySubjectEntity categorySubjectEntity);
 
     List<CategorySubjectEntity> findByFlag(String flag);
+    List<String> findByEName(String ename);
 
     void deleteCategorySubjectByFlag(String flag);
 

+ 2 - 0
src/main/java/com/rf/psychological/scale/service/SubjectService.java

@@ -209,4 +209,6 @@ public interface SubjectService {
     int institutionByTCNum(String institutionNo);
 
     void deleteSubjectByFlag(String flag);
+
+    Page findSubjectByPage(int pageNum,int pageSize,List<String> flags);
 }

+ 1 - 8
src/main/java/com/rf/psychological/scale/service/impl/CategoryServiceImpl.java

@@ -119,12 +119,5 @@ public class CategoryServiceImpl implements CategoryService {
         }
     }
 
-    /**
-     * 根据id查询类别详细信息
-     * @return
-     */
-    /*@Override
-    public CategoryEntity getone(String id) {
-        return this.categoryRepository.getOne(id);
-    }*/
+
 }

+ 5 - 0
src/main/java/com/rf/psychological/scale/service/impl/CategorySubjectServiceImpl.java

@@ -35,6 +35,11 @@ public class CategorySubjectServiceImpl implements CategorySubjectService {
         return this.categorySubjectRepository.findByFlag(flag);
     }
 
+    @Override
+    public List<String> findByEName(String ename) {
+        return categorySubjectRepository.findByEname(ename);
+    }
+
     @Override
     public void deleteCategorySubjectByFlag(String flag) {
         this.categorySubjectRepository.deleteCategorySubjectByFlag(flag);

+ 21 - 0
src/main/java/com/rf/psychological/scale/service/impl/SubjectServiceImpl.java

@@ -1,13 +1,18 @@
 package com.rf.psychological.scale.service.impl;
 
+import com.rf.psychological.institution.model.InstitutionEntity;
 import com.rf.psychological.scale.dao.model.SubjectEntity;
 import com.rf.psychological.scale.dao.repository.SubjectRepository;
 import com.rf.psychological.scale.service.SubjectService;
+import com.rf.psychological.utils.PageRequestUtil;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
+
+import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.Predicate;
 import java.util.ArrayList;
 import java.util.List;
@@ -329,6 +334,22 @@ public class SubjectServiceImpl implements SubjectService {
         this.subjectRepository.deleteSubjectByFlag(flag);
     }
 
+    @Override
+    public Page findSubjectByPage(int pageNum, int pageSize, List<String> flags) {
+        Specification specification = (Specification<SubjectEntity>) (root, query, cb) -> {
+            List<Predicate> list = new ArrayList<>();
+            List<Predicate> predicateListFlag = new ArrayList<>();
+            CriteriaBuilder.In<String> cbFlag = cb.in(root.get("flag"));
+            flags.forEach(cbFlag::value);
+            predicateListFlag.add(cbFlag);
+            list.add(cb.and(predicateListFlag.toArray(new Predicate[0])));
+            query.where(cb.and(list.toArray(new Predicate[list.size()])));
+            return query.getRestriction();
+        };
+        Page<InstitutionEntity> page = subjectRepository.findAll(specification, PageRequestUtil.of(pageNum , pageSize));
+        return page;
+    }
+
 
     ////解密量表list
     //private List<SubjectEntity> decryptList(List<SubjectEntity> before) {

+ 0 - 3
src/main/java/com/rf/psychological/utils/Constant.java

@@ -349,7 +349,6 @@ public class Constant {
      **/
     public static final String SHEET_NAME_RIVEN = "瑞文智力测试";
     public static final String SHEET_NAME_GO_NO_GO = "GO-NO-GO反应抑制测试";
-    public static final String SHEET_NAME_LIFE = "生活事件量表";
     public static final String SHEET_NAME_ALERTNESS = "精神运动警觉度测试";
     public static final String SHEET_NAME_ALERTNESS_YATAI = "游戏4";
     public static final String SHEET_NAME_ADDITION = "连续加法测试";
@@ -468,8 +467,6 @@ public class Constant {
      * Beck自杀意念量表
      **/
     public static final String QUEST_FLAG_BSSI = "20210617013827";
-/** 儿童行为问卷 **/
-//public static final String QUEST_FLAG_CBQ = "20210617014033";
     /**
      * 人际信任量表
      **/