liujie
2026-01-14 f976a39b294f8c7dd60bcd2c661983c0dcc97fc6
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
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 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();
}