liujie
2026-01-29 b74a483a59ab4925b4f79d2b2e76e17ab4b8177d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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<Plan> {
 
    @Query("select p from Plan p " +
            "where (:clientId is null or p.client.id = :clientId) and p.deleted = false")
    List<Plan> 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<Plan> myPlans(@Param("keyword") String keyword,
                         @Param("planTypes") List<PlanType> planTypes,
                         @Param("planStates") List<PlanState> planStates,
                         @Param("clientIds") List<Integer> clientIds,
                         @Param("userId") Integer userId,
                         @Param("planIds") List<Integer> 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<Plan> findPlans(@Param("keyword") String keyword,
                         @Param("planTypes") List<PlanType> planTypes,
                         @Param("planStates") List<PlanState> planStates,
                         @Param("clientIds") List<Integer> clientIds,
                         @Param("creatorId") Integer creatorId,
                         @Param("planIds") List<Integer> 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<Plan> findPlans(@Param("keyword") String keyword,
                         @Param("planTypes") List<PlanType> planTypes,
                         @Param("planStates") List<PlanState> planStates,
                         @Param("clientIds") List<Integer> clientIds,
                         @Param("creatorId") Integer creatorId,
                         @Param("planIds") List<Integer> planIds);
 
}