authen
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_system_alerts
Parameters
Name
Type
Mode
i_prop_id
integer
IN
i_lang
text
IN (DEFAULT 'EN')
Definition
declare v_lang text := upper(coalesce(nullif(i_lang, ''), 'EN')); v_system_enabled boolean; v_system_type text; v_system_en text; v_system_th text; v_system_message text; v_property_enabled boolean; v_property_type text; v_property_en text; v_property_th text; v_property_message text; alert_info jsonb; begin v_system_enabled := fn_get_config(null::integer, 'SYSTEM_ALERT_ENABLED', 'false') = 'true'; v_system_type := coalesce(nullif(fn_get_config(null::integer, 'SYSTEM_ALERT_TYPE', 'info'), ''), 'info'); v_system_en := coalesce(fn_get_config(null::integer, 'SYSTEM_ALERT_EN', ''), ''); v_system_th := coalesce(fn_get_config(null::integer, 'SYSTEM_ALERT_TH', ''), ''); v_system_enabled := v_system_enabled AND (v_system_en <> '' OR v_system_th <> ''); v_property_enabled := fn_get_config(i_prop_id, 'PROPERTY_ALERT_ENABLED', 'false') = 'true'; v_property_type := coalesce(nullif(fn_get_config(i_prop_id, 'PROPERTY_ALERT_TYPE', 'info'), ''), 'info'); v_property_en := coalesce(fn_get_config(i_prop_id, 'PROPERTY_ALERT_EN', ''), ''); v_property_th := coalesce(fn_get_config(i_prop_id, 'PROPERTY_ALERT_TH', ''), ''); v_property_enabled := v_property_enabled AND (v_property_en <> '' OR v_property_th <> ''); v_system_message := case when v_lang = 'TH' and v_system_th <> '' then v_system_th else v_system_en end; v_property_message := case when v_lang = 'TH' and v_property_th <> '' then v_property_th else v_property_en end; alert_info := jsonb_build_object( 'system', case when v_system_enabled then jsonb_build_object('type', v_system_type, 'message', v_system_message, 'message_en', v_system_en, 'message_th', v_system_th) else null end, 'property', case when v_property_enabled then jsonb_build_object('type', v_property_type, 'message', v_property_message, 'message_en', v_property_en, 'message_th', v_property_th) else null end ); if v_lang = '*' then alert_info := alert_info - 'message'; end if; return alert_info; end