Skip to content

Commit d84c41c

Browse files
Création de la vue reporting_actions (#1336)
## Related Pull Requests & Issues - Resolve #1335
2 parents ab4d5ff + bfc4473 commit d84c41c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CREATE VIEW public.reporting_actions AS
2+
3+
SELECT
4+
r.id,
5+
TEXT(reporting_id) AS reporting_id,
6+
TO_TIMESTAMP(cast(created_at as TEXT),'YYYY-MM-DD-HH24:MI') AS signal_datetime_utc,
7+
TEXT(source_type) AS source_type,
8+
CASE
9+
WHEN source_type = 'SEMAPHORE' THEN semaphores.nom
10+
WHEN source_type = 'CONTROL_UNIT' THEN control_units.name
11+
ELSE TEXT(source_name)
12+
END AS origin_signal,
13+
TEXT(sea_front) AS signal_facade,
14+
CASE
15+
WHEN r.theme IS NOT NULL THEN TEXT(r.theme)
16+
ELSE control_plan_themes.theme
17+
END AS theme_level_1,
18+
TEXT(report_type) AS report_type,
19+
CASE
20+
WHEN vehicle_type IS NULL THEN TEXT(target_type)
21+
ELSE TEXT(vehicle_type)
22+
END AS target_type,
23+
REPLACE(details->>'mmsi',' ','') AS mmsi,
24+
details->>'vesselName' AS nom_navireSociete,
25+
details->>'size' AS size,
26+
details->>'imo' AS imo,
27+
details->>'externalReferenceNumber' AS immatriculation,
28+
details->>'operatorName' AS nom_propre,
29+
CASE
30+
WHEN with_vhf_answer = 'false' THEN TEXT('NON')
31+
WHEN with_vhf_answer = 'true' THEN TEXT('OUI')
32+
ELSE NULL
33+
END AS reponse_vhf,
34+
CASE
35+
WHEN is_control_required = 'false' THEN TEXT('NON')
36+
WHEN is_control_required = 'true' THEN TEXT('OUI')
37+
ELSE NULL
38+
END AS control_required,
39+
CASE
40+
WHEN has_no_unit_available = 'false' THEN TEXT('DISPONIBLE')
41+
WHEN has_no_unit_available = 'true' THEN TEXT('NON DISPONIBLE')
42+
WHEN has_no_unit_available IS NULL AND r.mission_id IS NOT NULL THEN TEXT('DISPONIBLE')
43+
ELSE NULL
44+
END AS control_unit_dispo,
45+
r.mission_id,
46+
r.geom,
47+
TEXT(description) AS description,
48+
TEXT(action_taken) AS action_taken,
49+
TEXT(open_by) AS open_by
50+
FROM reportings r
51+
LEFT JOIN semaphores ON r.semaphore_id = semaphores.id
52+
LEFT JOIN control_units ON r.control_unit_id = control_units.id
53+
LEFT JOIN control_plan_themes ON r.control_plan_theme_id = control_plan_themes.id
54+
LEFT JOIN LATERAL jsonb_array_elements(target_details) AS details ON TRUE
55+
WHERE is_deleted = 'false'
56+
ORDER BY id DESC

0 commit comments

Comments
 (0)