package com.estate.expert.admin.domain.standard.problem; import com.estate.expert.admin.domain.common.EntityBaseRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; public interface ProblemRepository extends EntityBaseRepository { @Query("select p from Problem p where p.hierarchyId = :hierarchyId " + "and p.hierarchyPath in :hierarchyPaths " + "and (:keyword is null or :keyword = '' " + "or p.description like %:keyword% " + "or function('json_search', p.specificTerms, 'one', concat(concat('%', :keyword), '%')) is not null) " + "and p.deleted = false") Page findProblems(@Param("hierarchyId") Integer hierarchyId, @Param("hierarchyPaths") List hierarchyPaths, @Param("keyword") String keyword, Pageable pageReq); @Query("select distinct(p.id) from Problem p where p.hierarchyId = :hierarchyId " + "and (p.hierarchyPath in :ps) " + "and p.deleted = false") List findProblemIds(@Param("hierarchyId") Integer hierarchyId, @Param("ps") List hierarchyPaths); @Query("select distinct(p.id) from Problem p where p.hierarchyId = :hierarchyId and p.deleted = false") List findAllProblemIds(@Param("hierarchyId") Integer hierarchyId); List findAllByHierarchyIdAndDeleted(Integer hierarchyId, boolean deleted); @Query("select p from Problem p where p.hierarchyId = :hierarchyId " + "and (p.hierarchyPath in :hierarchyPaths) " + "and (p.id in :problemIds) " + "and p.deleted = false") List findProblems(@Param("hierarchyId") Integer hierarchyId, @Param("hierarchyPaths") List hierarchyPaths, @Param("problemIds") List problemIds); @Query("select p from Problem p where p.hierarchyId = :hierarchyId " + "and (p.hierarchyPath in :hierarchyPaths) " + "and p.deleted = false") List findProblems(@Param("hierarchyId") Integer hierarchyId, @Param("hierarchyPaths") List hierarchyPaths); }