-
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 973] Ajout de Calcul_Debit_Pression_973
Issue: #226851 Change-Id: I9a6955f78c365f29fc8b3348974ca45bd8f3c6cc
- Loading branch information
Clément GRENOT
authored and
Myriam Labbé
committed
Dec 13, 2024
1 parent
76fed7c
commit cfcc42c
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
server/sdis-remocra/home/postgres/remocra_db/patches/sdis/973/203_001.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,80 @@ | ||
-- Création fonction spécifique calcul_debit_pression_973 | ||
create or replace function remocra.calcul_debit_pression_973(id_hydrant bigint) | ||
returns void | ||
language plpgsql | ||
AS $function$ | ||
DECLARE | ||
p_anomalie_id INTEGER; | ||
P_rec remocra.hydrant_pibi % rowtype; | ||
p_code_type_hydrant_nature VARCHAR; | ||
BEGIN | ||
select * into p_rec from remocra.hydrant_pibi where id = id_hydrant; | ||
-- Suppression des anciennes anomalies | ||
delete from remocra.hydrant_anomalies where hydrant = p_rec.id and anomalies in ( | ||
select id | ||
from remocra.type_hydrant_anomalie | ||
where critere IS NULL | ||
AND code <> 'INDISPONIBILITE_TEMP'); | ||
-- Récupération du type_hydrant_nature id | ||
select thn.code into p_code_type_hydrant_nature from remocra.hydrant h left join remocra.type_hydrant_nature thn on (thn.id=h.nature) where h.id = id_hydrant; | ||
-- Définition des règles de calcul_debit_pression_973 | ||
IF FOUND THEN | ||
-- Pression dynamique | ||
---- Pression dynamique insuffisante | ||
IF(p_rec.pression_dyn IS NULL) THEN | ||
SELECT id INTO p_anomalie_id FROM remocra.type_hydrant_anomalie WHERE code = 'PRESSION_DYN_INSUFF'; | ||
INSERT INTO remocra.hydrant_anomalies (hydrant,anomalies) VALUES (p_rec.id,p_anomalie_id); | ||
END IF; | ||
-- Pression | ||
---- Pression insuffisante | ||
IF(p_rec.pression IS NULL OR p_rec.pression < 1) THEN | ||
SELECT id INTO p_anomalie_id FROM remocra.type_hydrant_anomalie WHERE code = 'PRESSION_INSUFF'; | ||
INSERT INTO remocra.hydrant_anomalies (hydrant,anomalies) VALUES (p_rec.id,p_anomalie_id); | ||
END IF; | ||
-- Débit | ||
---- Débit insuffisant | ||
if (p_rec.debit IS NULL OR p_rec.debit < 30) 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); | ||
END IF; | ||
---- Débit insuffisant non-conforme | ||
if (p_rec.debit < 60) 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; | ||
END; | ||
$function$; | ||
|
||
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
-- @@ Gestion des appels de fonctions @@ | ||
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
---- Ajout fonction appel calul_debit_pression_973 | ||
Create or replace function remocra.trg_calcul_debit_pression_973() | ||
returns TRIGGER | ||
language plpgsql | ||
as $function$ | ||
declare p_rec RECORD; | ||
BEGIN | ||
if (TG_OP = 'DELETE') then | ||
p_rec = OLD; | ||
else | ||
p_rec = NEW; | ||
end if; | ||
perform remocra.calcul_debit_pression_973(p_rec.id); | ||
RETURN p_rec; | ||
END; | ||
$function$; | ||
---- Ajout Trigger calcul_debit_pression_973 à la table hydrant_pibi | ||
DROP TRIGGER IF EXISTS trig_debit_pression_973 ON remocra.hydrant_pibi; | ||
CREATE TRIGGER trig_debit_pression_973 | ||
AFTER INSERT OR UPDATE ON remocra.hydrant_pibi | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE remocra.trg_calcul_debit_pression_973(); | ||
---- Désactivation du trigger de calcul_debit_pression initial | ||
ALTER TABLE remocra.hydrant_pibi DISABLE TRIGGER trig_debit_pression; | ||
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
-- @@ Remise en état des anomalies avec la nouvelle regle de calcul @@ | ||
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
SELECT remocra.calcul_debit_pression_973(id) FROM remocra.hydrant_pibi; | ||
ALTER TABLE remocra.hydrant_pibi ENABLE TRIGGER trig_debit_pression_973; |