liujie
2026-05-21 34fb8efd9fef8a6ed0d7cbaff74f37f06bf2db60
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.estate.expert.admin.domain.exam.record.error;
 
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.time.LocalDateTime;
import java.util.List;
 
public interface ErrorRecordRepository extends EntityBaseRepository<ErrorRecord> {
 
    @Query("select w from ErrorRecord w where w.checkTask.id = :checkTaskId " +
            "and (:creatorId is null or w.creator.id = :creatorId) " +
            "and w.device is null " +
            "and w.deleted = false " +
            "order by w.updateTime desc")
    Page<ErrorRecord> listSystemErrors(@Param("checkTaskId") Integer checkTaskId,
                                       @Param("creatorId") Integer creatorId,
                                       Pageable pageable);
 
    @Query("select w from ErrorRecord w where w.checkTask.id = :checkTaskId " +
            "and (:creatorId is null or w.creator.id = :creatorId) " +
            "and w.device is not null " +
            "and (:deviceId is null or w.device.id = :deviceId) " +
            "and w.deleted = false " +
            "order by w.device.id asc, w.updateTime desc")
    Page<ErrorRecord> listDeviceErrors(@Param("checkTaskId") Integer checkTaskId,
                                       @Param("deviceId") Integer deviceId,
                                       @Param("creatorId") Integer creatorId,
                                       Pageable pageable);
 
    @Query("select w from ErrorRecord w where ( :clientId is null or w.checkTask.project.client.id = :clientId) " +
            "and ( :planId is null or w.checkTask.plan.id = :planId) " +
            "and ( :taskId is null or w.checkTask.id = :taskId) " +
            "and w.device is null " +
            "and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) " +
            "and w.deleted = false " +
            "order by w.updateTime desc")
    List<ErrorRecord> listSystemErrors(@Param("clientId") Integer clientId,
                                       @Param("planId") Integer planId,
                                       @Param("taskId") Integer taskId,
                                       @Param("startDate") LocalDateTime startDate,
                                       @Param("endDate") LocalDateTime endDate);
 
    @Query("select w from ErrorRecord w where ( :clientId is null or w.checkTask.project.client.id = :clientId) " +
            "and ( :planId is null or w.checkTask.plan.id = :planId) " +
            "and ( :taskId is null or w.checkTask.id = :taskId) " +
            "and w.device is null " +
            "and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) " +
            "and w.deleted = false " +
            "order by w.updateTime desc")
    Page<ErrorRecord> listSystemErrors(@Param("clientId") Integer clientId,
                                       @Param("planId") Integer planId,
                                       @Param("taskId") Integer taskId,
                                       @Param("startDate") LocalDateTime startDate,
                                       @Param("endDate") LocalDateTime endDate,
                                       Pageable pageable);
 
 
    @Query("select w from ErrorRecord w where ( :clientId is null or w.checkTask.project.client.id = :clientId) " +
            "and ( :planId is null or w.checkTask.plan.id = :planId) " +
            "and ( :taskId is null or w.checkTask.id = :taskId) " +
            "and w.device is not null " +
            "and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) " +
            "and w.deleted = false " +
            "order by w.updateTime desc")
    List<ErrorRecord> listDeviceErrors(@Param("clientId") Integer clientId,
                                       @Param("planId") Integer planId,
                                       @Param("taskId") Integer taskId,
                                       @Param("startDate") LocalDateTime startDate,
                                       @Param("endDate") LocalDateTime endDate);
 
    @Query("select w from ErrorRecord w where ( :clientId is null or w.checkTask.project.client.id = :clientId) " +
            "and ( :planId is null or w.checkTask.plan.id = :planId) " +
            "and ( :taskId is null or w.checkTask.id = :taskId) " +
            "and w.device is not null " +
            "and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) " +
            "and w.deleted = false " +
            "order by w.updateTime desc")
    Page<ErrorRecord> listDeviceErrors(@Param("clientId") Integer clientId,
                                       @Param("planId") Integer planId,
                                       @Param("taskId") Integer taskId,
                                       @Param("startDate") LocalDateTime startDate,
                                       @Param("endDate") LocalDateTime endDate,
                                       Pageable pageable);
 
 
    @Query("select w from ErrorRecord w where w.checkTask.id = :checkTaskId and w.device = null " +
            "and w.deleted = false")
    List<ErrorRecord> listSystemErrors(Integer checkTaskId);
 
    @Query("select w from ErrorRecord w where w.checkTask.id = :checkTaskId and w.device != null " +
            "and w.deleted = false")
    List<ErrorRecord> listDeviceErrors(Integer checkTaskId);
 
    @Query("select w.problem.id, count(w) from ErrorRecord w " +
            "where w.deleted = false " +
            "and w.device is null " +
            "and w.level is not null " +
            "and w.problem is not null " +
            "and w.problem.id in :problemIds " +
            "and w.checkTask.project.id = :projectId " +
            "and w.checkTask.state in :taskStates " +
            "group by w.problem.id")
    List<Object[]> countSystemHazardsByProjectAndProblemIds(@Param("projectId") Integer projectId,
                                                           @Param("taskStates") List<com.estate.expert.admin.domain.exam.task.check.CheckTaskState> taskStates,
                                                           @Param("problemIds") List<Integer> problemIds);
 
    @Query("select w.problem.id, count(w) from ErrorRecord w " +
            "where w.deleted = false " +
            "and w.device is null " +
            "and w.problem is not null " +
            "and w.problem.id in :problemIds " +
            "and w.checkTask.id in :taskIds " +
            "group by w.problem.id")
    List<Object[]> countSystemHazardsByTaskIdsAndProblemIds(@Param("taskIds") List<Integer> taskIds,
                                                           @Param("problemIds") List<Integer> problemIds);
 
    @Query(value = "select r.device_id, r.problem_id, count(*) " +
            "from record r " +
            "where r.deleted = false " +
            "and r.device_id is not null " +
            "and r.problem_id is not null " +
            "and r.record_type = 'error' " +
            "and r.check_task_id in (:taskIds) " +
            "group by r.device_id, r.problem_id", nativeQuery = true)
    List<Object[]> countDeviceHazardsByTaskIds(@Param("taskIds") List<Integer> taskIds);
 
    //根据人员来获取检查成果
    @Query("select w from ErrorRecord w where w.deleted = false  and w.creator.id = :creatorId"+ " and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) " )
    List<ErrorRecord> inspectionResultsBasedOnPersonnel(Integer creatorId,  @Param("startDate") LocalDateTime startDate,
                                                        @Param("endDate") LocalDateTime endDate);
 
    //根据人员来获取检查成果
    @Query("select w from ErrorRecord w where w.deleted = false  and w.creator.id in :creatorIds"+ " and ( :startDate is null or w.createTime >= :startDate) " +
            "and ( :endDate is null or w.createTime < :endDate) ")
    List<ErrorRecord> inspectionResultsBasedOnPersonnel(List<Integer> creatorIds,  @Param("startDate") LocalDateTime startDate,
                                                        @Param("endDate") LocalDateTime endDate);
 
    @Query("select w from ErrorRecord w join fetch w.problem  join fetch w.checkTask c join fetch c.project p where w.deleted = false" )
    List<ErrorRecord> getErrorRecordAndProblem();
 
    @Query("select w from ErrorRecord w join fetch w.problem pr join fetch w.checkTask c join fetch c.project p where w.deleted = false and pr.hierarchyId = 1 " )
    List<ErrorRecord> getErrorRecordByNotDevice();
}