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 { @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 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 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 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 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 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 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 listSystemErrors(Integer checkTaskId); @Query("select w from ErrorRecord w where w.checkTask.id = :checkTaskId and w.device != null " + "and w.deleted = false") List 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 countSystemHazardsByProjectAndProblemIds(@Param("projectId") Integer projectId, @Param("taskStates") List taskStates, @Param("problemIds") List 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 countSystemHazardsByTaskIdsAndProblemIds(@Param("taskIds") List taskIds, @Param("problemIds") List 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 countDeviceHazardsByTaskIds(@Param("taskIds") List 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 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 inspectionResultsBasedOnPersonnel(List 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 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 getErrorRecordByNotDevice(); }