package com.rf.psychological.scale.dao.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.group.dao.dto.GroupAuthSubjectNameDto;
import com.rf.psychological.scale.dao.model.SubjectEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zzf
 * @description:
 * @date 2021/5/17 9:46
 */
public interface SubjectRepository extends BaseRepository<SubjectEntity, String> {

    /**
     * 查询
     *
     * @param type 0：量表   1：认知任务
     * @return
     */
    @Query(value = "select * from t_subject_info where type = :type", nativeQuery = true)
    List<SubjectEntity> findAll(@Param("type") String type);

    @Query(value = "select * from  t_subject_info where flag in (?1)", nativeQuery = true)
    List<SubjectEntity> findAllByFlag(List<String> flag);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "delete from t_subject_info", nativeQuery = true)
    void deleteAll();

    /**
     * 查询热门量表
     *
     * @return
     */
    @Query(value = "select * from t_subject_info where type = '0' and is_hot = '1' ", nativeQuery = true)
    List<SubjectEntity> findHotScale();

    /**
     * 查询最新测试
     *
     * @return
     */
    @Query(value = "select * from t_subject_info where type = '0' and is_new = '1' ", nativeQuery = true)
    List<SubjectEntity> findNewScale();

    /**
     * 检索，根据中文名、英文名或录入人
     *
     * @param pageNum
     * @param pageSize
     * @param searchName
     * @return
     */
    @Query(value = "select * from t_subject_info tsi where name like %:searchName% or ename like %:searchName%  order by flag desc  limit :pageNum ,:pageSize ", nativeQuery = true)
    List<SubjectEntity> findByNameOrUploader(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("searchName") String searchName);

    /**
     * 根据名称模糊查询或上传人精确拆线呢总条数
     *
     * @param searchName
     * @return
     */
    @Query(value = "select count(1) from t_subject_info where name like %:searchName% or ename like %:searchName%   ", nativeQuery = true)
    int allNumByNameOrUploader(@Param("searchName") String searchName);

    /**
     * 查询  分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Query(value = "select * from t_subject_info order by status,flag desc  limit :pageNum ,:pageSize ", nativeQuery = true)
    List<SubjectEntity> findAll(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize);

    /**
     * 总条数
     *
     * @return
     */
    @Query(value = "select count(1) from t_subject_info", nativeQuery = true)
    int allNum();

    /**
     * 根据名称模糊查询  分页
     *
     * @param pageNum
     * @param pageSize
     * @param searchStr
     * @return
     */
    @Query(value = "select * from t_subject_info where name like %:searchStr% or ename like %:searchStr% order by status,flag desc  limit :pageNum ,:pageSize ", nativeQuery = true)
    List<SubjectEntity> getSubjectListByName(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("searchStr") String searchStr);

    /**
     * 根据名称模糊查询总条数
     *
     * @param searchStr
     * @return
     */
    @Query(value = "select count(1) from t_subject_info where name like %:searchStr% or ename like %:searchStr%   ", nativeQuery = true)
    int allNumByName(@Param("searchStr") String searchStr);

    /**
     * 根据flag查询
     *
     * @return
     */
    @Query(value = "select * from t_subject_info where flag = :flag ", nativeQuery = true)
    List<SubjectEntity> getSubjectByFlag(@Param("flag") String flag);

    /**
     * 根据flag记录测试数
     *
     * @return
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE t_subject_info SET test_num = test_num+1 WHERE flag = :flag ", nativeQuery = true)
    void addTestNum(@Param("flag") String flag);

    /**
     * 修改量表测试结果效验状态
     *
     * @return
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE t_subject_info SET status = :status WHERE flag = :flag ", nativeQuery = true)
    void updateScaleStatus(@Param("flag") String flag, @Param("status") String status);

    /**
     * 根据量表中文名查询
     *
     * @return
     */
    @Query(value = "select * from t_subject_info where name = :name ", nativeQuery = true)
    SubjectEntity getSubjectByname(@Param("name") String name);

    /**
     * 根据id修改量表
     *
     * @return
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE t_subject_info SET scoring_principle = :scoringPrinciple WHERE id = :id ", nativeQuery = true)
    void updateById(@Param("id") String id, @Param("scoringPrinciple") String scoringPrinciple);

    /**
     * 某类别下根据名称模糊查询列表
     *
     * @return
     */
    @Query(value = "select b.* " +
            "from t_subject_info b where b.flag in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname) " +
            "and b.name like %:scaleName% or b.ename like %:scaleName% order by b.status,b.flag desc limit :pageNum ,:pageSize    ", nativeQuery = true)
    List<SubjectEntity> getSubjectListByNameCategory(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("scaleName") String scaleName, @Param("categoryEname") String categoryEname);

    /**
     * 某类别下根据名称模糊查询总条数
     *
     * @param scaleName,categoryEname
     * @return
     */
    @Query(value = "select count(1) from t_subject_info b where b.flag in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname) and b.name like %:scaleName% or b.ename like %:scaleName%   ", nativeQuery = true)
    int allNumByNameCategory(@Param("scaleName") String scaleName, @Param("categoryEname") String categoryEname);

    /**
     * 某类别下查询总条数
     *
     * @return
     */
    @Query(value = "select count(1) from t_subject_info b where b.flag in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname)", nativeQuery = true)
    int allNumCategory(@Param("categoryEname") String categoryEname);

    /**
     * 某类别下所有信息列表
     *
     * @return
     */
    @Query(value = "select b.* from t_subject_info b where b.flag in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname) order by b.status,b.flag desc limit :pageNum ,:pageSize    ", nativeQuery = true)
    List<SubjectEntity> findAllCategory(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("categoryEname") String categoryEname);

    @Query(value = "select DISTINCT(id),description,'' as ename, flag, image_url, is_hot, is_new, name, no, test_num, type, uploader, file_name, scoring_principle, status, scale_limit,men,icon_info,report_version,reference,report_reference,report_keyboarder " +
            "from v_subject_auth where institution_no = :institutionNo and if(:scaleName is not null and :scaleName!='',name like %:scaleName% ,1=1) limit :pageNum ,:pageSize", nativeQuery = true)
    List<SubjectEntity> getSubjectListByAuth(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("scaleName") String scaleName, @Param("institutionNo") String institutionNo);

    @Query(value = "select id,description,ename ,flag, image_url, is_hot, is_new, name, no, test_num, type, uploader, file_name, scoring_principle, status, scale_limit,men,icon_info,report_version,reference,report_reference,report_keyboarder " +
            "from v_subject_auth " +
            "where institution_no = :institutionNo and   if(:scaleName is not null and :scaleName!='',name like %:scaleName% ,1=1) " +
            "and  if(:categoryEname is not null and :categoryEname!='',ename like %:categoryEname% ,1=1) order by test_num desc limit :pageNum ,:pageSize    ", nativeQuery = true)
    List<SubjectEntity> getSubjectListByAuthAndType(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("scaleName") String scaleName, @Param("categoryEname") String categoryEname, @Param("institutionNo") String institutionNo);

    /**
     * 某类别下查询总条数
     *
     * @return
     */
    @Query(value = "select count(DISTINCT(id)) from v_subject_auth where institution_no = :institutionNo and if(:scaleName is not null and :scaleName!='',name like %:scaleName% ,1=1) and  if(:categoryEname is not null and :categoryEname!='',ename like %:categoryEname% ,1=1)", nativeQuery = true)
    int allNumByAuth(@Param("scaleName") String scaleName, @Param("categoryEname") String categoryEname, @Param("institutionNo") String institutionNo);


    /**
     * # 查询组量表的权限
     *
     * @param groupId
     * @param pageable
     * @return
     */
    @Query(value = "select  tga.id, b_id bid, group_id groupId, group_name groupName, institution_no institutionNo,  description, ename, flag, image_url imageUrl, is_hot isHot, is_new isNew, name, no, test_num testNum, tsi.type, uploader, " +
            "file_name fileName, scoring_principle scoringPrinciple, status, scale_limit scaleLimit " +
            "from  t_group_auth tga \n" +
            "    join t_group_info tgi \n" +
            "    join t_subject_info tsi on tgi.id = group_id and b_id = tsi.id\n" +
            "where group_id = ?1 and if(?2 is not null and ?2 !='',name like CONCAT('%',?2,'%') ,1=1)",
            countQuery = "select count(*)  " +
                    "from t_group_info tgi\n" +
                    "         join t_subject_info tsi\n" +
                    "         join t_group_auth tga on tgi.id = group_id and b_id = tsi.id\n" +
                    "where group_id = ?1 and if(?2 is not null and ?2 !='',name like CONCAT('%',?2,'%') ,1=1)",
            nativeQuery = true)
    Page<GroupAuthSubjectNameDto> findGroupAuth(String groupId, String name, Pageable pageable);

    /**
     * 查询某个用户的量表权限
     *
     * @param uId
     * @param pageable
     * @return
     */
    @Query(value = "select g_auth.id, description, ename, flag, image_url, is_hot, is_new, name, no, test_num, type, uploader, file_name, scoring_principle, status, scale_limit ,men,icon_info,report_version,reference,report_reference,report_keyboarder " +
            "from (   " +
            "         select tgi.group_name        ,   " +
            "                tgi.institution_no    ,   " +
            "                tsi.id,   " +
            "                tsi.description,   " +
            "                tsi.ename,   " +
            "                tsi.flag,   " +
            "                tsi.image_url         ,   " +
            "                tsi.is_hot            ,   " +
            "                tsi.is_new            ,   " +
            "                tsi.name              ,   " +
            "                tsi.no                ,   " +
            "                tsi.test_num          ,   " +
            "                tsi.type              ,   " +
            "                tsi.uploader          ,   " +
            "                tsi.file_name         ,   " +
            "                tsi.scoring_principle ,   " +
            "                tsi.status            ,   " +
            "                tsi.scale_limit       ,   " +
            "                tga.id            groupAuId    ,   " +
            "                tga.group_id          groupId  ,men,icon_info,report_version,reference,report_reference,report_keyboarder " +
            "         from t_group_info tgi   " +
            "                  join t_subject_info tsi   " +
            "                  join t_group_auth tga on tgi.id = group_id and b_id = tsi.id   order by tsi.test_num desc " +
            "     ) g_auth   " +
            "         join t_user_info tui on tui.g_id = g_auth.groupId where tui.id= ?1 and if(?2 is not null and ?2 !='',name like %?2%  ,1=1) order by test_num desc ",
            countQuery = "select count(g_auth.id)" +
                    "from (    " +
                    "         select tgi.group_name        groupName,    " +
                    "                tgi.institution_no    institutionNo,    " +
                    "                tsi.id,    " +
                    "                tsi.description,    " +
                    "                tsi.ename,    " +
                    "                tsi.flag,    " +
                    "                tsi.image_url         imageUrl,    " +
                    "                tsi.is_hot            isHot,    " +
                    "                tsi.is_new            isNew,    " +
                    "                tsi.name              name,    " +
                    "                tsi.no                no,    " +
                    "                tsi.test_num          testNum,    " +
                    "                tsi.type              type,    " +
                    "                tsi.uploader          uploader,    " +
                    "                tsi.file_name         fileName,    " +
                    "                tsi.scoring_principle scoringPrinciple,    " +
                    "                tsi.status            status,    " +
                    "                tsi.scale_limit       scaleLimit,    " +
                    "                tga.id                groupAuId,    " +
                    "                tga.group_id          groupId  ,men,icon_info  " +
                    "         from t_group_info tgi    " +
                    "                  join t_subject_info tsi    " +
                    "                  join t_group_auth tga on tgi.id = group_id and b_id = tsi.id  order by tsi.test_num desc   " +
                    "     ) g_auth    " +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId where tui.id= ?1 and if(?2 is not null and ?2 !='',name like %?2%  ,1=1) ",
            nativeQuery = true)
    Page<SubjectEntity> findUserAuth(String uId, String scaleName, Pageable pageable);


    /**
     * 查询用户量表权限，包含类别
     */
    @Query(value = "select g_auth.id,\n" +
            "       description,\n" +
            "       ename,\n" +
            "       flag,\n" +
            "       image_url,\n" +
            "       is_hot,\n" +
            "       is_new,\n" +
            "       name,\n" +
            "       no,\n" +
            "       test_num,\n" +
            "       type,\n" +
            "       uploader,\n" +
            "       file_name,\n" +
            "       scoring_principle,\n" +
            "       status,\n" +
            "       scale_limit,men,icon_info,report_version,reference,report_reference,report_keyboarder \n" +
            "from (\n" +
            "         select tgi.group_name,\n" +
            "                tgi.institution_no,\n" +
            "                tsi.id,\n" +
            "                tsi.description,\n" +
            "                tsi.ename,\n" +
            "                tsi.flag,\n" +
            "                tsi.image_url,\n" +
            "                tsi.is_hot,\n" +
            "                tsi.is_new,\n" +
            "                tsi.name,\n" +
            "                tsi.no,\n" +
            "                tsi.test_num,\n" +
            "                tsi.type,\n" +
            "                tsi.uploader,\n" +
            "                tsi.file_name,\n" +
            "                tsi.scoring_principle,\n" +
            "                tsi.status,\n" +
            "                tsi.scale_limit,\n" +
            "                tga.id       groupAuId,\n" +
            "                tga.group_id groupId,\n" +
            "                tcs.ename cateEname,men,icon_info,report_version,reference,report_reference,report_keyboarder " +
            "         from t_group_info tgi\n" +
            "                  join t_subject_info tsi\n" +
            "                  join t_group_auth tga join t_category_subject tcs on tsi.flag = tcs.flag and tgi.id = group_id and b_id = tsi.id\n  order by tsi.test_num desc" +
            "     ) g_auth\n" +
            "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
            "\n" +
            "where tui.id = ?1 and cateEname= ?3 and if(?2 is not null and ?2 !='',name like %?2%  ,1=1) order by test_num desc",
            countQuery = "select count(g_auth.id) " +
                    "from (\n" +
                    "         select tgi.group_name,\n" +
                    "                tgi.institution_no,\n" +
                    "                tsi.id,\n" +
                    "                tsi.description,\n" +
                    "                tsi.ename,\n" +
                    "                tsi.flag,\n" +
                    "                tsi.image_url,\n" +
                    "                tsi.is_hot,\n" +
                    "                tsi.is_new,\n" +
                    "                tsi.name,\n" +
                    "                tsi.no,\n" +
                    "                tsi.test_num,\n" +
                    "                tsi.type,\n" +
                    "                tsi.uploader,\n" +
                    "                tsi.file_name,\n" +
                    "                tsi.scoring_principle,\n" +
                    "                tsi.status,\n" +
                    "                tsi.scale_limit,\n" +
                    "                tga.id       groupAuId,\n" +
                    "                tga.group_id groupId,\n" +
                    "                tcs.ename cateEname\n" +
                    "         from t_group_info tgi\n" +
                    "                  join t_subject_info tsi\n" +
                    "                  join t_group_auth tga join t_category_subject tcs on tsi.flag = tcs.flag and tgi.id = group_id and b_id = tsi.id\n   order by tsi.test_num desc " +
                    "     ) g_auth\n" +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
                    "\n" +
                    "where tui.id = ?1 and cateEname=?3 and if(?2 is not null and ?2 !='',name like %?2%  ,1=1)  ",
            nativeQuery = true)
    Page<SubjectEntity> findUserAuthAndCateEName(String uId, String scaleName, String cateEName, Pageable pageable);


    /**
     * 查找机构没有的量表权限
     *
     * @param institutionNo
     * @param searchKey
     * @param pageable
     * @return
     */
    @Query(value = "select id,\n" +
            "       description,\n" +
            "       ename,\n" +
            "       flag,\n" +
            "       image_url       ,\n" +
            "       is_hot          ,\n" +
            "       is_new            ,\n" +
            "       name,\n" +
            "       test_num          ,\n" +
            "       tsi.type,\n" +
            "       uploader,\n" +
            "       file_name        ,\n" +
            "       scoring_principle ,\n" +
            "       status,\n" +
            "       scale_limit,      \n" +
            "       men,no,icon_info,report_version,reference,report_reference,report_keyboarder \n" +
            "from t_subject_info tsi\n" +
            "where if( ?2 is not null and  ?2 != '', (tsi.name like CONCAT('%',  ?2, '%')), 1 = 1) " +
            "and id not in (select b_id from t_institution_auth where institution_no=?1 and t_institution_auth.type='0')",
            countQuery = "select count(id)\n" +
                    "from t_subject_info tsi\n" +
                    "where  if( ?2 is not null and  ?2 != '', (tsi.name like CONCAT('%',  ?2, '%')), 1 = 1)  and\n" +
                    " id not in (select b_id from t_institution_auth where institution_no=?1 and t_institution_auth.type='0')", nativeQuery = true)
    Page<SubjectEntity> findInstitutionNoSubAuthList(String institutionNo, String searchKey, Pageable pageable);

    /**
     * 根据id修改指定字段
     *
     * @return
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE t_subject_info SET description = :description WHERE id = :id ", nativeQuery = true)
    void updateSubject(@Param("description") String description, @Param("id") String id);

    @Query(value = "select * from t_subject_info tsi where flag=:flag ", nativeQuery = true)
    SubjectEntity getSubjectEntityByFlag(@Param("flag") String flag);

    @Query(value = "select * from t_subject_info tsi " +
            "where flag in(SELECT flag FROM t_category_subject WHERE ename = 'TC') AND id in(SELECT b_id FROM t_institution_auth WHERE institution_no = :institutionNo) order by flag desc  limit :pageNum ,:pageSize ", nativeQuery = true)
    List<SubjectEntity> institutionByTC(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("institutionNo") String institutionNo);

    @Query(value = "select count(1) from t_subject_info " +
            "where flag in(SELECT flag FROM t_category_subject WHERE ename = 'TC') AND id in(SELECT b_id FROM t_institution_auth WHERE  if(?1 !='10006',institution_no = ?1 ,1=1) )", nativeQuery = true)
    int institutionByTCNum(String institutionNo);

    @Transactional
    @Modifying
    @Query(value = "delete from t_subject_info where flag=:flag  ", nativeQuery = true)
    void deleteSubjectByFlag(@Param("flag") String flag);

    @Query(value = "select tsi.id,description,ename,tsi.flag,image_url,is_hot,is_new,name,test_num,type,uploader,file_name,scoring_principle,status" +
            ",scale_limit,no,icon_info,report_version,reference,report_reference,report_keyboarder" +
            ",(SELECT\n" +
            "(\n" +
            "CASE\n" +
            "WHEN count(*) > 0 THEN\n" +
            "1\n" +
            "ELSE\n" +
            "0\n" +
            "END\n" +
            ")\n" +
            "FROM\n" +
            "t_warn_info twi\n" +
            "WHERE\n" +
            "twi.flag = tsi.flag\n" +
            "AND twi.institution_no = :institutionNo\n" +
            ") as men  FROM t_subject_info tsi" +
            " WHERE if( :scaleType is not null and  :scaleType != '' and :scaleType <> 'ALL', (tsi.flag in (SELECT flag FROM t_category_subject WHERE ename = :scaleType)), 1 = 1) " +
            " AND if( :scaleName is not null and  :scaleName != '', (tsi.name like CONCAT('%',  :scaleName, '%')), 1 = 1)" +
            "AND tsi.id IN(SELECT b_id FROM t_institution_auth WHERE institution_no =  :institutionNo) " +
            "AND tsi.flag IN (SELECT flag FROM t_dimension_org WHERE institution_no =:institutionNo) ORDER BY men desc limit :pageNum ,:pageSize ", nativeQuery = true)
    List<SubjectEntity> getSubjectListByAuthSeted(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("scaleName") String scaleName, @Param("institutionNo") String institutionNo,@Param("scaleType") String scaleType);

    @Query(value = "select count(1)  FROM t_subject_info" +
            " WHERE if( :scaleType is not null and  :scaleType != '' and :scaleType <> 'ALL', (flag in (SELECT flag FROM t_category_subject WHERE ename = :scaleType)), 1 = 1) " +
            " AND if( :scaleName is not null and  :scaleName != '', (name like CONCAT('%',  :scaleName, '%')), 1 = 1)" +
            "AND id IN(SELECT b_id FROM t_institution_auth WHERE institution_no =  :institutionNo) " +
            "AND flag IN (SELECT flag FROM t_dimension_info WHERE id IN(SELECT dimension_id FROM t_dimension_org WHERE institution_no =:institutionNo)) ", nativeQuery = true)
    int getSubjectListByAuthSeted(String scaleName, String institutionNo, String scaleType);

    @Query(value = "SELECT * FROM t_subject_info WHERE flag != :flag AND " +
            "flag in(SELECT flag FROM t_category_subject WHERE " +
            "ename in(SELECT ename FROM t_category_subject WHERE flag = :flag)) ORDER BY test_num DESC LIMIT 10", nativeQuery = true)
    List<SubjectEntity> getRelevantEvaluation(String flag);

    @Query(value = "(SELECT * FROM t_subject_info ORDER BY test_num DESC LIMIT :numberFifteen) " +
            "UNION (SELECT * FROM t_subject_info WHERE flag NOT in(" +
            "SELECT * FROM (SELECT flag FROM t_subject_info ORDER BY test_num DESC LIMIT :numberFifteen) t1) ORDER BY flag DESC LIMIT :numberFifteen) ", nativeQuery = true)
    List<SubjectEntity> getTrendingSearches(int numberFifteen);

    @Query(value = "select * from t_subject_info tsi " +
            "where 1=1 AND if( ?1 is not null and  ?1 != '', (tsi.name like CONCAT('%',  ?1, '%')), 1 = 1) " +
            "AND if( ?2 is not null and  ?2 != '', (tsi.flag in(SELECT tcs.flag FROM t_category_subject tcs WHERE tcs.ename = ?2)), 1 = 1) " +
            "AND if( ?3 is not null and  ?3 != '', ((tsi.men like CONCAT('',  ?3, ',%') or tsi.men like CONCAT('%,',  ?3, '') or tsi.men like CONCAT('%,',  ?3, ',%') or tsi.men = ?3)), 1 = 1) " +
            "AND if( ?4 is not null and  ?4 != '', (tsi.scale_limit = ?4), 1 = 1) ORDER BY tsi.men",
            countQuery = "select count(id) from t_subject_info tsi " +
                    "where 1=1 AND if( ?1 is not null and  ?1 != '', (tsi.name like CONCAT('%',  ?1, '%')), 1 = 1) " +
                    "AND if( ?2 is not null and  ?2 != '', (tsi.flag in(SELECT tcs.flag FROM t_category_subject tcs WHERE tcs.ename = ?2)), 1 = 1) " +
                    "AND if( ?3 is not null and  ?3 != '', ((tsi.men like CONCAT('',  ?3, ',%') or tsi.men like CONCAT('%,',  ?3, '') or tsi.men like CONCAT('%,',  ?3, ',%') or tsi.men = ?3)), 1 = 1) " +
                    "AND if( ?4 is not null and  ?4 != '', (tsi.scale_limit = ?4), 1 = 1) ", nativeQuery = true)
    Page<SubjectEntity> getsubjectListMultiCondition(String name, String scaleCate, String people, String currentLimit, PageRequest pageable);
}
