Skip to content

Commit b243c33

Browse files
Flag acknowledged prior notifications in pno list query
1 parent 3851570 commit b243c33

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBLogbookReportRepository.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,37 +136,32 @@ interface DBLogbookReportRepository :
136136
AND lr.operation_type = 'DEL'
137137
),
138138
139-
ret_pno_logbook_reports AS (
140-
SELECT
141-
lr.*,
142-
CAST(NULL AS TEXT[]) AS prior_notification_type_names,
143-
CAST(NULL AS TEXT[]) AS specy_codes,
144-
CAST(NULL AS TEXT[]) AS trip_gear_codes,
145-
CAST(NULL AS TEXT[]) AS trip_segment_codes,
146-
CAST(NULL AS INTEGER) AS reporting_count
139+
acknowledged_report_ids AS (
140+
SELECT DISTINCT referenced_report_id
147141
FROM logbook_reports lr
148-
JOIN filtered_dat_and_cor_pno_logbook_reports fdacplr ON lr.referenced_report_id = fdacplr.report_id
149142
WHERE
150143
-- This filter helps Timescale optimize the query since `operation_datetime_utc` is indexed
151144
lr.operation_datetime_utc
152145
BETWEEN CAST(:willArriveAfter AS TIMESTAMP) - INTERVAL '48 hours'
153146
AND CAST(:willArriveBefore AS TIMESTAMP) + INTERVAL '48 hours'
154147
155148
AND lr.operation_type = 'RET'
149+
AND lr.value->>'returnStatus' = '000'
156150
)
157151
158152
SELECT *
159153
FROM filtered_dat_and_cor_pno_logbook_reports
154+
WHERE
155+
report_id IN (SELECT referenced_report_id FROM acknowledged_report_ids)
156+
OR transmission_format = 'FLUX'
160157
161-
UNION
158+
UNION ALL
162159
163160
SELECT *
164161
FROM del_pno_logbook_reports
165-
166-
UNION
167-
168-
SELECT *
169-
FROM ret_pno_logbook_reports;
162+
WHERE
163+
operation_number IN (SELECT referenced_report_id FROM acknowledged_report_ids)
164+
OR transmission_format = 'FLUX'
170165
""",
171166
nativeQuery = true,
172167
)

0 commit comments

Comments
 (0)