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

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.group.dao.dto.GroupAuthConTaskDto;
import com.rf.psychological.dao.model.CognitiveTaskEntity;
import com.rf.psychological.scale.dao.model.SubjectEntity;
import org.springframework.data.domain.Page;
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 zsy
 * @description:Category
 * @date 2021/6/17 15:55
 */
public interface CognitiveTaskRepository extends BaseRepository<CognitiveTaskEntity, String> {

    /**
     * 查询  分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Query(value = "select * from t_cognitive_task where status='0' limit :pageNum ,:pageSize  ", nativeQuery = true)
    List<CognitiveTaskEntity> findAll(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize);


    CognitiveTaskEntity findByTaskCode(String taskCode);

    @Query(value = "select * from  t_cognitive_task where task_code in (?1)", nativeQuery = true)
    List<CognitiveTaskEntity> findAllByTaskCode(List<String> taskCode);

    /**
     * 总条数
     *
     * @return
     */
    @Query(value = "select count(1) from t_cognitive_task  where status='0' ", nativeQuery = true)
    int allNum();

    /**
     * 根据名称模糊查询  分页
     *
     * @param pageNum
     * @param pageSize
     * @param searchStr
     * @return
     */
    @Query(value = "select * from t_cognitive_task where name like %:searchStr%  and status='0' limit :pageNum ,:pageSize ", nativeQuery = true)
    List<CognitiveTaskEntity> getCognizeListByName(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("searchStr") String searchStr);

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

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

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

    /**
     * 某类别下根据名称模糊查询列表
     *
     * @return
     */
    @Query(value = "select b.* from t_cognitive_task b where b.task_code in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname) and b.name like %:scaleName% and status='0' limit :pageNum ,:pageSize    ", nativeQuery = true)
    List<CognitiveTaskEntity> getCognizeListByNameCategory(@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_cognitive_task b where b.task_code in (SELECT a.flag FROM t_category_subject a WHERE a.ename = :categoryEname) and b.name like %:scaleName% and status='0'", nativeQuery = true)
    int allNumByNameCategory(@Param("scaleName") String scaleName, @Param("categoryEname") String categoryEname);

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


    /**
     * # 查询组认知任务的权限
     *
     * @param groupId
     * @param pageable
     * @return
     */
    @Query(value = "select  tga.id, b_id bId, group_id groupId, group_name groupName, tgi.institution_no institutionNo , description, image_name imageName, image_url imageUrl, name, page_url pageUrl, scale_limit scaleLimit, status, task_code taskCode, test_description testDescription, " +
            "test_explain testExplain, test_num testNum, tga.type, no " +
            "from t_group_info tgi \n" +
            "    join t_group_auth tga  \n" +
            "    join t_cognitive_task tct on tgi.id = group_id and b_id = tct.id\n" +
            "where group_id = ?1 and if(?2 is not null and ?2 !='',name like CONCAT('%',?2,'%') ,1=1) and status='0'",
            countQuery = "select count(*)  " +
                    "from t_group_info tgi\n" +
                    "         join t_cognitive_task tct \n" +
                    "         join t_group_auth tga on tgi.id = group_id and b_id = tct.id\n" +
                    "where group_id = ?1 and if(?2 is not null and ?2 !='',name like CONCAT('%',?2,'%') ,1=1) and status='0'",
            nativeQuery = true)
    Page<GroupAuthConTaskDto> findGroupAuth(String groupId, String name, Pageable pageable);


    /**
     * 查询认知任务权限
     *
     * @param uId
     * @param scaleName
     * @param pageable
     * @return
     */
    @Query(value = "select * \n" +
            "from (\n" +
            "         select tgi.group_name     groupName,\n" +
            "                tgi.institution_no institutionNo,\n" +
            "                tct.id,\n" +
            "                tct.description,\n" +
            "                tct.image_name,\n" +
            "                tct.image_url,\n" +
            "                tct.name,\n" +
            "                tct.page_url,\n" +
            "                tct.scale_limit,\n" +
            "                tct.status,\n" +
            "                tct.task_code,\n" +
            "                tct.test_description,\n" +
            "                tct.test_explain,\n" +
            "                tct.test_num,\n" +
            "                tct.type,\n" +
            "                tct.no,\n" +
            "                tga.id   groupAuId,\n" +
            "                tga.group_id  groupId,tct.mobile_description,tct.mobile_page_url ,tct.mobile_test_description ,tct.mobile_status ,tct.report_version,tct.practice,tct.illustrating_picture ,tct.estimated_time ,tct.report_pages,tct.reference \n" +
            "         from t_group_info tgi\n" +
            "                  join t_cognitive_task tct\n" +
            "                  join t_group_auth tga on tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc  " +
            "     ) g_auth\n" +
            "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
            "where tui.id = ?1\n" +
            "  and if(?2 is not null and ?2 != '', name like CONCAT('%',?2,'%'), 1 = 1) and status='0' order by test_num desc ",
            countQuery = "select count(g_auth.id)\n" +
                    "from (\n" +
                    "         select tgi.group_name     groupName,\n" +
                    "                tgi.institution_no institutionNo,\n" +
                    "                tct.id,\n" +
                    "                tct.description,\n" +
                    "                tct.image_name,\n" +
                    "                tct.image_url,\n" +
                    "                tct.name,\n" +
                    "                tct.page_url,\n" +
                    "                tct.scale_limit,\n" +
                    "                tct.status,\n" +
                    "                tct.task_code,\n" +
                    "                tct.test_description,\n" +
                    "                tct.test_explain,\n" +
                    "                tct.test_num,\n" +
                    "                tct.type,\n" +
                    "                tct.no,\n" +
                    "                tga.id             groupAuId,\n" +
                    "                tga.group_id       groupId\n" +
                    "         from t_group_info tgi\n" +
                    "                  join t_cognitive_task tct\n" +
                    "                  join t_group_auth tga on tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc " +
                    "     ) g_auth\n" +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
                    "where tui.id = ?1\n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and status='0' ", nativeQuery = true)
    Page<CognitiveTaskEntity> findUserTaskAuth(String uId, String scaleName, Pageable pageable);


    @Query(value = "select * \n" +
            "from (\n" +
            "         select tgi.group_name     groupName,\n" +
            "                tgi.institution_no institutionNo,\n" +
            "                tct.id,\n" +
            "                tct.description,\n" +
            "                tct.image_name,\n" +
            "                tct.image_url,\n" +
            "                tct.name,\n" +
            "                tct.page_url,\n" +
            "                tct.scale_limit,\n" +
            "                tct.status,\n" +
            "                tct.task_code,\n" +
            "                tct.test_description,\n" +
            "                tct.test_explain,\n" +
            "                tct.test_num,\n" +
            "                tct.type,\n" +
            "                tct.no,\n" +
            "                tga.id   groupAuId,\n" +
            "                tga.group_id  groupId,tct.mobile_description,tct.mobile_page_url ,tct.mobile_test_description ,tct.mobile_status ,tct.report_version, tct.practice,tct.illustrating_picture ,tct.estimated_time ,tct.report_pages,tct.reference \n" +
            "         from t_group_info tgi\n" +
            "                  join t_cognitive_task tct\n" +
            "                  join t_group_auth tga on tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc  " +
            "     ) g_auth\n" +
            "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
            "where tui.id = ?1\n" +
            "  and if(?2 is not null and ?2 != '', name like CONCAT('%',?2,'%'), 1 = 1) and status='0' and mobile_status=?3  order by test_num desc  ",
            countQuery = "select count(g_auth.id)\n" +
                    "from (\n" +
                    "         select tgi.group_name     groupName,\n" +
                    "                tgi.institution_no institutionNo,\n" +
                    "                tct.id,\n" +
                    "                tct.description,\n" +
                    "                tct.image_name,\n" +
                    "                tct.image_url,\n" +
                    "                tct.name,\n" +
                    "                tct.page_url,\n" +
                    "                tct.scale_limit,\n" +
                    "                tct.status,\n" +
                    "                tct.task_code,\n" +
                    "                tct.test_description,\n" +
                    "                tct.test_explain,\n" +
                    "                tct.test_num,\n" +
                    "                tct.type,\n" +
                    "                tct.no,\n" +
                    "                tga.id             groupAuId,\n" +
                    "                tga.group_id       groupId,mobile_status\n" +
                    "         from t_group_info tgi\n" +
                    "                  join t_cognitive_task tct\n" +
                    "                  join t_group_auth tga on tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc  " +
                    "     ) g_auth\n" +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
                    "where tui.id = ?1\n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and status='0' and mobile_status=?3 ", nativeQuery = true)
    Page<CognitiveTaskEntity> pageUserTaskAuthInMobile(String uId, String scaleName, String mobileStatus, Pageable pageable);

    /**
     * 查询认知任务权限,包含类别
     *
     * @param uId
     * @param scaleName
     * @param cateEName
     * @param pageable
     * @return
     */
    @Query(value = "select g_auth.id,\n" +
            "       description,\n" +
            "       image_name,\n" +
            "       image_url,\n" +
            "       name,\n" +
            "       page_url,\n" +
            "       scale_limit,\n" +
            "       status,\n" +
            "       task_code,\n" +
            "       test_description,\n" +
            "       test_explain,\n" +
            "       test_num,\n" +
            "       type,\n" +
            "       no,mobile_description,mobile_test_description,mobile_page_url,mobile_status,report_version, practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "from (\n" +
            "         select tgi.group_name     groupName,\n" +
            "                tgi.institution_no institutionNo,\n" +
            "                tct.id,\n" +
            "                tct.description,\n" +
            "                tct.image_name,\n" +
            "                tct.image_url,\n" +
            "                tct.name,\n" +
            "                tct.page_url,\n" +
            "                tct.scale_limit,\n" +
            "                tct.status,\n" +
            "                tct.task_code,\n" +
            "                tct.test_description,\n" +
            "                tct.test_explain,\n" +
            "                tct.test_num,\n" +
            "                tct.type,\n" +
            "                tct.no,\n" +
            "                tga.id             groupAuId,\n" +
            "                tga.group_id       groupId,\n" +
            "                tcs.flag,\n" +
            "                tcs.ename,mobile_description,mobile_page_url ,mobile_test_description ,mobile_status ,report_version, practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "         from t_group_info tgi\n" +
            "                  join t_cognitive_task tct\n" +
            "                  join t_group_auth tga join t_category_subject tcs on tcs.flag=tct.task_code and tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc " +
            "     ) g_auth\n" +
            "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
            "where tui.id = ?1\n" +
            "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and ename= ?3 and status='0' order by test_num desc ",
            countQuery = "select count(g_auth.id) " +
                    "from (\n" +
                    "         select tgi.group_name     groupName,\n" +
                    "                tgi.institution_no institutionNo,\n" +
                    "                tct.id,\n" +
                    "                tct.description,\n" +
                    "                tct.image_name,\n" +
                    "                tct.image_url,\n" +
                    "                tct.name,\n" +
                    "                tct.page_url,\n" +
                    "                tct.scale_limit,\n" +
                    "                tct.status,\n" +
                    "                tct.task_code,\n" +
                    "                tct.test_description,\n" +
                    "                tct.test_explain,\n" +
                    "                tct.test_num,\n" +
                    "                tct.type,\n" +
                    "                tct.no,\n" +
                    "                tga.id             groupAuId,\n" +
                    "                tga.group_id       groupId,\n" +
                    "                tcs.flag,\n" +
                    "                tcs.ename\n" +
                    "         from t_group_info tgi\n" +
                    "                  join t_cognitive_task tct\n" +
                    "                  join t_group_auth tga join t_category_subject tcs on tcs.flag=tct.task_code and tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc " +
                    "     ) g_auth\n" +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
                    "where tui.id = ?1\n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and ename= ?3 and status='0' ", nativeQuery = true)
    Page<CognitiveTaskEntity> findUserTaskAuthAndCateEName(String uId, String scaleName, String cateEName, Pageable pageable);


    @Query(value = "select g_auth.id,\n" +
            "       description,\n" +
            "       image_name,\n" +
            "       image_url,\n" +
            "       name,\n" +
            "       page_url,\n" +
            "       scale_limit,\n" +
            "       status,\n" +
            "       task_code,\n" +
            "       test_description,\n" +
            "       test_explain,\n" +
            "       test_num,\n" +
            "       type,\n" +
            "       no,mobile_description,mobile_test_description,mobile_page_url,mobile_status,report_version, practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "from (\n" +
            "         select tgi.group_name     groupName,\n" +
            "                tgi.institution_no institutionNo,\n" +
            "                tct.id,\n" +
            "                tct.description,\n" +
            "                tct.image_name,\n" +
            "                tct.image_url,\n" +
            "                tct.name,\n" +
            "                tct.page_url,\n" +
            "                tct.scale_limit,\n" +
            "                tct.status,\n" +
            "                tct.task_code,\n" +
            "                tct.test_description,\n" +
            "                tct.test_explain,\n" +
            "                tct.test_num,\n" +
            "                tct.type,\n" +
            "                tct.no,\n" +
            "                tga.id             groupAuId,\n" +
            "                tga.group_id       groupId,\n" +
            "                tcs.flag,\n" +
            "                tcs.ename,mobile_description,mobile_page_url ,mobile_test_description ,mobile_status ,report_version, practice, illustrating_picture, estimated_time, report_pages, reference  \n" +
            "         from t_group_info tgi\n" +
            "                  join t_cognitive_task tct\n" +
            "                  join t_group_auth tga join t_category_subject tcs on tcs.flag=tct.task_code and tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc " +
            "     ) g_auth\n" +
            "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
            "where tui.id = ?1\n" +
            "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and ename= ?3 and status='0' and mobile_status=?4 order by test_num desc  ",
            countQuery = "select count(g_auth.id) " +
                    "from (\n" +
                    "         select tgi.group_name     groupName,\n" +
                    "                tgi.institution_no institutionNo,\n" +
                    "                tct.id,\n" +
                    "                tct.description,\n" +
                    "                tct.image_name,\n" +
                    "                tct.image_url,\n" +
                    "                tct.name,\n" +
                    "                tct.page_url,\n" +
                    "                tct.scale_limit,\n" +
                    "                tct.status,\n" +
                    "                tct.task_code,\n" +
                    "                tct.test_description,\n" +
                    "                tct.test_explain,\n" +
                    "                tct.test_num,\n" +
                    "                tct.type,\n" +
                    "                tct.no,\n" +
                    "                tga.id             groupAuId,\n" +
                    "                tga.group_id       groupId,\n" +
                    "                tcs.flag,\n" +
                    "                tcs.ename,mobile_status\n" +
                    "         from t_group_info tgi\n" +
                    "                  join t_cognitive_task tct\n" +
                    "                  join t_group_auth tga join t_category_subject tcs on tcs.flag=tct.task_code and tgi.id = group_id and b_id = tct.id\n  order by tct.test_num desc  " +
                    "     ) g_auth\n" +
                    "         join t_user_info tui on tui.g_id = g_auth.groupId\n" +
                    "where tui.id = ?1\n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1) and ename= ?3 and status='0' and mobile_status=?4 ", nativeQuery = true)
    Page<CognitiveTaskEntity> pageUserTaskAuthAndCateENameInMobile(String uId, String scaleName, String cateEName, String mobileStatus, Pageable pageable);

    /**
     * 查询机构认知任务的权限（包含类别）
     *
     * @param institutionNo
     * @param scaleName
     * @param cateEName
     * @param pageable
     * @return
     */
    @Query(value = "select tct.id,\n" +
            "       tct.description,\n" +
            "       tct.image_name,\n" +
            "       tct.image_url,\n" +
            "       tct.name,\n" +
            "       tct.page_url,\n" +
            "       tct.scale_limit,\n" +
            "       tct.status,\n" +
            "       tct.task_code,\n" +
            "       tct.test_description,\n" +
            "       tct.test_explain,\n" +
            "       tct.test_num,\n" +
            "       tct.type,\n" +
            "       tct.no,mobile_description,mobile_page_url ,mobile_test_description ,mobile_status ,report_version, practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "from t_institution_info tii\n" +
            "         join t_cognitive_task tct\n" +
            "         join t_institution_auth tia\n" +
            "         join t_category_subject tcs\n" +
            "              on tcs.flag = tct.task_code and tii.institution_no = tia.institution_no and b_id = tct.id\n order by tct.test_num desc " +
            "where tia.institution_no = ?1 \n" +
            "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1)\n" +
            "  and ename = ?3 and status='0'\n order by tct.test_num desc ",
            countQuery = "select count(tct.id)\n" +
                    "from t_institution_info tii\n" +
                    "         join t_cognitive_task tct\n" +
                    "         join t_institution_auth tia\n" +
                    "         join t_category_subject tcs\n" +
                    "              on tcs.flag = tct.task_code and tii.institution_no = tia.institution_no and b_id = tct.id\n  order by tct.test_num desc " +
                    "where tia.institution_no = ?1 \n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1)\n" +
                    "  and ename = ?3 and status='0'", nativeQuery = true)
    Page<CognitiveTaskEntity> findInstitutionTaskAuthAndCateEName(String institutionNo, String scaleName, String cateEName, Pageable pageable);


    @Query(value = "select tct.id,\n" +
            "       tct.description,\n" +
            "       tct.image_name,\n" +
            "       tct.image_url,\n" +
            "       tct.name,\n" +
            "       tct.page_url,\n" +
            "       tct.scale_limit,\n" +
            "       tct.status,\n" +
            "       tct.task_code,\n" +
            "       tct.test_description,\n" +
            "       tct.test_explain,\n" +
            "       tct.test_num,\n" +
            "       tct.type,\n" +
            "       tct.no,mobile_description,mobile_page_url ,mobile_test_description ,mobile_status,report_version, practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "from t_institution_info tii\n" +
            "         join t_cognitive_task tct\n" +
            "         join t_institution_auth tia\n" +
            "         join t_category_subject tcs\n" +
            "              on tcs.flag = tct.task_code and tii.institution_no = tia.institution_no and b_id = tct.id\n" +
            "where tia.institution_no = ?1 \n" +
            "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1)\n" +
            "  and ename = ?3 and status='0' and mobile_status =?4\n order by tct.test_num desc",
            countQuery = "select count(tct.id)\n" +
                    "from t_institution_info tii\n" +
                    "         join t_cognitive_task tct\n" +
                    "         join t_institution_auth tia\n" +
                    "         join t_category_subject tcs\n" +
                    "              on tcs.flag = tct.task_code and tii.institution_no = tia.institution_no and b_id = tct.id\n" +
                    "where tia.institution_no = ?1 \n" +
                    "  and if(?2 is not null and ?2 != '', name like %?2%, 1 = 1)\n" +
                    "  and ename = ?3 and status='0' and mobile_status =?4 order by tct.test_num desc", nativeQuery = true)
    Page<CognitiveTaskEntity> pageInstitutionTaskAuthAndCateEName(String institutionNo, String scaleName, String cateEName, String mobileStatus, Pageable pageable);

    /**
     * 查找机构没有的认知任务权限
     *
     * @param institutionNo
     * @param searchKey
     * @param pageable
     * @return
     */
    @Query(value = "select id,\n" +
            "       description,\n" +
            "       image_name,\n" +
            "       image_url,\n" +
            "       name,\n" +
            "       page_url,\n" +
            "       scale_limit,\n" +
            "       status,\n" +
            "       task_code,\n" +
            "       test_description,\n" +
            "       test_explain,\n" +
            "       test_num,\n" +
            "       type,\n" +
            "       no,mobile_description ,mobile_page_url ,mobile_test_description ,mobile_status,report_version,practice, illustrating_picture, estimated_time, report_pages, reference \n" +
            "from t_cognitive_task tct\n" +
            "where if( ?2 is not null and  ?2 != '', (tct.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 = '1') and status='0'",
            countQuery = "select count(id)\n" +
                    "    from t_cognitive_task tct\n" +
                    "where if( ?2 is not null and  ?2 != '', (tct.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 = '1') and status='0'", nativeQuery = true)
    Page<CognitiveTaskEntity> findInstitutionNoCTAuthList(String institutionNo, String searchKey, Pageable pageable);

    @Query(value = "select * from t_cognitive_task where task_code = :taskCode  ", nativeQuery = true)
    CognitiveTaskEntity getCognizeListByTaskCode(@Param("taskCode") String taskCode);

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

    @Query(value = "SELECT * FROM t_cognitive_task WHERE task_code != :taskCode and " +
            "task_code in(SELECT flag FROM t_category_subject WHERE " +
            "ename in(SELECT ename FROM t_category_subject WHERE flag = :taskCode)) ORDER BY test_num DESC LIMIT 10;", nativeQuery = true)
    List<CognitiveTaskEntity> getRelevantEvaluation(String taskCode);
}
