liujie
2026-04-17 8afcc37e0de5aa3ca3cc3f175f180e9339f60424
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.estate.expert.admin.domain.exam.task.check;
 
import com.estate.expert.admin.domain.common.EntityBaseRepository;
import com.estate.expert.admin.domain.plan.PlanState;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
 
import java.util.List;
 
public interface CheckTaskRepository extends EntityBaseRepository<CheckTask> {
 
    @Query("select t from CheckTask t where t.plan.id = :planId and ( t.state >= 3 ) " +
            "and t.deleted = false order by t.id desc")
    List<CheckTask> listClosedTasks(Integer planId);
 
    @Query("select t from CheckTask t where (coalesce(:planIds, null) is null or t.plan.id in :planIds) " +
            "and ( t.state >= 3 ) " +
            "and t.deleted = false order by t.id desc")
    List<CheckTask> listClosedTasks(List<Integer> planIds);
 
    /**
     * 查询我的任务
     * 其中包括,plan.creatorId = userId
     * groupLeaders 中包含 userId
     * groupMembers 中包含 userId
     * drivers 中包含 userId
     * creatorId = userId
     */
    @Query("select t from CheckTask t where t.deleted = false " +
            "and ( :planId is null or t.plan.id = :planId ) " +
            "and ( t.creator.id = :userId " +
            "or :userId in (select g.id from t.groupLeaders g) " +
            "or :userId in (select g.id from t.groupMembers g) " +
            "or :userId in (select g.id from t.drivers g) " +
            "or :userId = t.plan.creator.id) " +
            "order by t.id desc")
    List<CheckTask> listMyTasks(Integer userId, Integer planId);
 
    @Query("select t from CheckTask t where t.deleted = false " +
            "and t.state != 3 and  t.state != 7 " +
            "and t.plan.deleted = false " +
            "and (t.creator.id = :userId " +
            "or :userId in (select g.id from t.groupLeaders g) " +
            "or :userId in (select g.id from t.groupMembers g) " +
            "or :userId in (select g.id from t.drivers g) " +
            "or :userId = t.plan.creator.id)" +
            "order by t.id desc")
    List<CheckTask> listMyToDoTasks(Integer userId);
 
    @Query("select t.plan.id from CheckTask t where t.deleted = false and (t.creator.id = :userId " +
            "or :userId in (select g.id from t.groupLeaders g) " +
            "or :userId in (select g.id from t.groupMembers g) " +
            "or :userId in (select g.id from t.drivers g)) " +
            "or :userId = t.plan.creator.id " +
            "order by t.id desc")
    List<Integer> listMyTaskPlans(Integer userId);
 
    List<CheckTask> findAllByPlanIdAndDeleted(Integer planId, boolean deleted);
 
    CheckTask getFirstByPlanIdAndProjectIdAndDeleted(Integer planId, Integer projectId, boolean deleted);
 
    @Query("select t.id from CheckTask t " +
            "where t.deleted = false " +
            "and t.project.id = :projectId " +
            "and t.plan.deleted = false " +
            "and t.plan.state = :planState")
    List<Integer> listTaskIdsByProjectAndPlanState(@Param("projectId") Integer projectId,
                                                   @Param("planState") PlanState planState);
 
    @Query("select t.id from CheckTask t " +
            "where t.deleted = false " +
            "and t.project.id = :projectId " +
            "and t.project.client.id = :clientId " +
            "and t.plan.deleted = false " +
            "and t.plan.state = :planState")
    List<Integer> listTaskIdsByProjectAndClientAndPlanState(@Param("projectId") Integer projectId,
                                                             @Param("clientId") Integer clientId,
                                                             @Param("planState") PlanState planState);
 
    @Query("select t.id from CheckTask t " +
            "where t.deleted = false " +
            "and t.project.id = :projectId " +
            "and t.project.client.id = :clientId " +
            "and t.plan.deleted = false")
    List<Integer> listTaskIdsByProjectAndClient(@Param("projectId") Integer projectId,
                                                 @Param("clientId") Integer clientId);
 
    @Query("select t from CheckTask t " +
            "where t.deleted = false " +
            "and t.project.id = :projectId " +
            "and t.project.client.id = :clientId " +
            "and t.plan.deleted = false " +
            "and t.plan.state = :planState")
    List<CheckTask> listByProjectAndClientAndPlanState(@Param("projectId") Integer projectId,
                                                        @Param("clientId") Integer clientId,
                                                        @Param("planState") PlanState planState);
 
    @Query("select t from CheckTask t " +
            "where t.deleted = false " +
            "and t.project.id = :projectId " +
            "and t.project.client.id = :clientId " +
            "and t.plan.deleted = false " +
            "and t.state >= 3")
    List<CheckTask> listClosedByProjectAndClient(@Param("projectId") Integer projectId,
                                                  @Param("clientId") Integer clientId);
}