Renovus-Tech / solarec-db

GNU Affero General Public License v3.0
0 stars 0 forks source link

Views of all alert not send by email #15

Closed pferrariuy closed 1 month ago

pferrariuy commented 1 month ago

Feature Request

Description

Create 2 view to retrieve all the alerts that are enabled and ready to be send my email:

Use Case

Views will be use by: https://github.com/Renovus-Tech/solarec-java/issues/45

Expected Behavior

pferrariuy commented 1 month ago

Flags taken according to definition in: https://github.com/Renovus-Tech/solarec-java/issues/45

CREATE VIEW vw_cli_gen_alert_to_send_by_email AS
select
 cga.*,
 g.loc_id,
 g.gen_name,
 g.gen_code,
 l.loc_name,
 l.loc_code,
 c.cli_name
from
client c
join location l on c.cli_id_auto = l.cli_id
join generator g on g.cli_id = l.cli_id and g.loc_id = l.loc_id_auto
join cli_gen_alert cga on l.cli_id = cga.cli_id and g.gen_id_auto = cga.gen_id
where c.cli_flags ilike '__1%' and g.gen_flags ilike '_1%' and cga.cli_gen_alert_flags ilike '_0%';--

CREATE VIEW vw_cli_loc_alert_to_send_by_email AS 
select
 cla.*,
 l.loc_name,
 l.loc_code,
 c.cli_name
from
client c
join location l on c.cli_id_auto = l.cli_id
join cli_loc_alert cla on l.cli_id = cla.cli_id and l.loc_id_auto = cla.loc_id
where c.cli_flags ilike '__1%' and l.loc_flags ilike '_1%' and cla.cli_loc_alert_flags ilike '_0%';--