package com.estate.expert.admin.domain.plan; 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 PlanRepository extends EntityBaseRepository { @Query("select p from Plan p " + "where (:clientId is null or p.client.id = :clientId) and p.deleted = false") List findAllByClientId(Integer clientId); @Query("select p from Plan p where ( :keyword is null or :keyword = '' or p.name like %:keyword%) " + "and (coalesce(:planTypes, null) is null or p.type in :planTypes) " + "and (coalesce(:planStates, null) is null or p.state in :planStates) " + "and (coalesce(:clientIds, null) is null or p.client.id in :clientIds) " + "and (coalesce(:planIds, null) is null or p.id in :planIds) " + "and p.deleted = false " + "or (p.deleted = false and (:userId is null or p.creator.id = :userId)) " + "order by p.updateTime desc") Page myPlans(@Param("keyword") String keyword, @Param("planTypes") List planTypes, @Param("planStates") List planStates, @Param("clientIds") List clientIds, @Param("userId") Integer userId, @Param("planIds") List planIds, Pageable page); @Query("select p from Plan p where ( :keyword is null or :keyword = '' or p.name like %:keyword%) " + "and (coalesce(:planTypes, null) is null or p.type in :planTypes) " + "and (coalesce(:planStates, null) is null or p.state in :planStates) " + "and (coalesce(:clientIds, null) is null or p.client.id in :clientIds) " + "and (coalesce(:planIds, null) is null or p.id in :planIds) " + "and (:creatorId is null or p.creator.id = :creatorId) " + "and p.deleted = false " + "order by p.updateTime desc") Page findPlans(@Param("keyword") String keyword, @Param("planTypes") List planTypes, @Param("planStates") List planStates, @Param("clientIds") List clientIds, @Param("creatorId") Integer creatorId, @Param("planIds") List planIds, Pageable page); @Query("select p from Plan p where ( :keyword is null or :keyword = '' or p.name like %:keyword%) " + "and (coalesce(:planTypes, null) is null or p.type in :planTypes) " + "and (coalesce(:planStates, null) is null or p.state in :planStates) " + "and (coalesce(:clientIds, null) is null or p.client.id in :clientIds) " + "and (coalesce(:planIds, null) is null or p.id in :planIds) " + "and (:creatorId is null or p.creator.id = :creatorId) " + "and p.deleted = false " + "order by p.updateTime desc") List findPlans(@Param("keyword") String keyword, @Param("planTypes") List planTypes, @Param("planStates") List planStates, @Param("clientIds") List clientIds, @Param("creatorId") Integer creatorId, @Param("planIds") List planIds); }