-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDIS 21] Met a jour le calcul_debit_pression_21
Issue: #244337 Change-Id: If49b462db53980b787c3ee1811c93680d3792468
- Loading branch information
Clément GRENOT
committed
Feb 18, 2025
1 parent
3258d94
commit 7bdee50
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
server/sdis-remocra/home/postgres/remocra_db/patches/sdis/21/203_002.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- DROP FUNCTION remocra.calcul_debit_pression_21(int8); | ||
|
||
CREATE OR REPLACE FUNCTION remocra.calcul_debit_pression_21(id_hydrant bigint) | ||
RETURNS void | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
|
||
DECLARE | ||
p_anomalie_id integer; | ||
p_rec remocra.hydrant_pibi%ROWTYPE; | ||
p_diametre_id integer; | ||
BEGIN | ||
|
||
SELECT * INTO p_rec | ||
FROM remocra.hydrant_pibi | ||
WHERE id = id_hydrant; | ||
|
||
-- Suppression des anomalies débit/pression des règles communes | ||
DELETE FROM remocra.hydrant_anomalies | ||
WHERE hydrant = id_hydrant | ||
AND anomalies IN (SELECT id FROM remocra.type_hydrant_anomalie WHERE critere IS NULL and code <> 'INDISPONIBILITE_TEMP'); | ||
|
||
-- Anomalies Debit | ||
---- Diamètre 150 | ||
SELECT id into p_diametre_id FROM remocra.type_hydrant_diametre WHERE code ILIKE 'diam150'; | ||
IF (p_rec.diametre = p_diametre_id) THEN | ||
IF (p_rec.debit < 27) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
ELSIF (p_rec.debit < 109) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF_NC'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
end if; | ||
end if; | ||
---- Diamètre 100 | ||
SELECT id into p_diametre_id FROM remocra.type_hydrant_diametre WHERE code ILIKE 'diam100'; | ||
IF (p_rec.diametre = p_diametre_id) THEN | ||
IF (p_rec.debit < 27) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
ELSIF (p_rec.debit < 54) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF_NC'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
end if; | ||
end if; | ||
---- Diamètre 70 | ||
SELECT id into p_diametre_id FROM remocra.type_hydrant_diametre WHERE code ILIKE 'diam70'; | ||
IF (p_rec.diametre = p_diametre_id) THEN | ||
IF (p_rec.debit < 27) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
ELSIF (p_rec.debit < 30) then | ||
select id into p_anomalie_id from remocra.type_hydrant_anomalie where code = 'DEBIT_INSUFF_NC'; | ||
insert into remocra.hydrant_anomalies (hydrant,anomalies) values (p_rec.id, p_anomalie_id); | ||
end if; | ||
end if; | ||
|
||
perform remocra.calcul_indispo(p_rec.id); | ||
|
||
END; | ||
$function$ | ||
; | ||
|
||
|
||
SELECT remocra.calcul_debit_pression_21(id) FROM remocra.hydrant_pibi; |