aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_nbis_sync_json
Parameters
Name
Type
Mode
i_prop_id
integer
IN
Definition
DECLARE v_nbis jsonb; v_avail boolean; v_rate boolean; v_restr boolean; BEGIN SELECT coalesce(i.configs, '{}'::jsonb) INTO v_nbis FROM interfaces i WHERE i.code = 'NBIS'; IF i_prop_id IS NOT NULL THEN BEGIN SELECT r.sync_avail, r.sync_rate, r.sync_restriction INTO v_avail, v_rate, v_restr FROM dblink(fn_conn_authen(), format('SELECT sync_avail, sync_rate, sync_restriction FROM public.property WHERE id = %L', i_prop_id)) AS r(sync_avail boolean, sync_rate boolean, sync_restriction boolean); EXCEPTION WHEN OTHERS THEN -- การอ่านต้องไม่ทำให้หน้าจอเปิดไม่ได้ ถ้า authen ล่มก็ใช้ค่าใน configs ไปก่อน RAISE WARNING 'fn_nbis_sync_json: cannot read authen.property (prop_id=%): %', i_prop_id, SQLERRM; END; END IF; RETURN jsonb_build_object( 'avail', coalesce(v_avail, nullif(v_nbis->>'INTERFACE_ROOMAVAIL_ENABLED', '')::boolean, false), 'rate', coalesce(v_rate, nullif(v_nbis->>'INTERFACE_RATE_ENABLED', '')::boolean, false), 'restriction', coalesce(v_restr, nullif(v_nbis->>'INTERFACE_RESTRICTIONS_ENABLED', '')::boolean, nullif(v_nbis->>'INTERFACE_RESTRICTION_ENABLED', '')::boolean, false) ); END