Skip to content

Commit

Permalink
[PPANTT-142] feat: Add new query to fetch all stations' maintenances
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Oct 17, 2024
1 parent f0caf57 commit 76f3375
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,27 @@ Page<StationMaintenance> findAllByFilters(
@Param("endDateTimeAfter") OffsetDateTime endDateTimeAfter,
Pageable pageable
);

@Query(value =
"SELECT m " +
"FROM StationMaintenance m JOIN FETCH m.station s JOIN FETCH s.intermediarioPa ipa " +
"WHERE m.fkStation = s.objId " +
"AND s.fkIntermediarioPa = ipa.objId " +
"AND (cast(cast(:startDateTimeBefore as text) as timestamp) IS NULL OR m.startDateTime < cast(cast(:startDateTimeBefore as text) as timestamp)) " +
"AND (cast(cast(:startDateTimeAfter as text) as timestamp) IS NULL OR m.startDateTime > cast(cast(:startDateTimeAfter as text) as timestamp)) " +
"AND (cast(cast(:endDateTimeBefore as text) as timestamp) IS NULL OR m.endDateTime < cast(cast(:endDateTimeBefore as text) as timestamp)) " +
"AND (cast(cast(:endDateTimeAfter as text) as timestamp) IS NULL OR m.endDateTime > cast(cast(:endDateTimeAfter as text) as timestamp))",
countQuery =
"SELECT COUNT(m) " +
"FROM StationMaintenance m JOIN Stazioni s ON m.fkStation = s.objId JOIN IntermediariPa ipa ON s.fkIntermediarioPa = ipa.objId " +
"AND (cast(cast(:startDateTimeBefore as text) as timestamp) IS NULL OR m.startDateTime < cast(cast(:startDateTimeBefore as text) as timestamp)) " +
"AND (cast(cast(:startDateTimeAfter as text) as timestamp) IS NULL OR m.startDateTime > cast(cast(:startDateTimeAfter as text) as timestamp)) " +
"AND (cast(cast(:endDateTimeBefore as text) as timestamp) IS NULL OR m.endDateTime < cast(cast(:endDateTimeBefore as text) as timestamp)) " +
"AND (cast(cast(:endDateTimeAfter as text) as timestamp) IS NULL OR m.endDateTime > cast(cast(:endDateTimeAfter as text) as timestamp))")
Page<StationMaintenance> findAllByFilters(
@Param("startDateTimeBefore") OffsetDateTime startDateTimeBefore,
@Param("startDateTimeAfter") OffsetDateTime startDateTimeAfter,
@Param("endDateTimeBefore") OffsetDateTime endDateTimeBefore,
@Param("endDateTimeAfter") OffsetDateTime endDateTimeAfter
);
}

0 comments on commit 76f3375

Please sign in to comment.