perf(sql): дельта АХР через _form_affected_rows, с предками SUB_SUB_ITEM (AURORA-1850)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
66b8b8a8e0
commit
c236dc0e81
@ -2740,3 +2740,50 @@ BEGIN
|
||||
END;
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION v3.get_form2_ahr_satellite_delta(p_form_id integer, p_source_sheet character varying, p_source_row_id integer)
|
||||
RETURNS TABLE(row_type character varying, depth integer, sort_order bigint, data jsonb)
|
||||
LANGUAGE sql
|
||||
STABLE
|
||||
AS $function$
|
||||
WITH target_lines AS (
|
||||
SELECT m.target_line_id AS line_id
|
||||
FROM v3.form2_ahr_satellite_line_source m
|
||||
JOIN v3.budget_line bl ON bl.id = m.target_line_id
|
||||
WHERE m.source_sheet = p_source_sheet
|
||||
AND m.source_id = p_source_row_id
|
||||
AND bl.budget_form_id = p_form_id
|
||||
AND p_source_sheet IN ('AHR_RENT', 'AHR_UTILITY', 'AHR_SECURITY')
|
||||
|
||||
UNION
|
||||
|
||||
SELECT bl.id AS line_id
|
||||
FROM v3.limit_template lt
|
||||
JOIN v3.expense_item ei
|
||||
ON ei.sheet = 'AHR'
|
||||
AND ei.direction = 'Support'
|
||||
AND (
|
||||
(ei.depth = 3 AND ei.item_id = lt.expense_item_code)
|
||||
OR ei.num_group_id = lt.expense_item_code
|
||||
)
|
||||
JOIN v3.budget_line bl
|
||||
ON bl.budget_form_id = p_form_id
|
||||
AND bl.expense_item_id = ei.id
|
||||
AND bl.name = regexp_replace(
|
||||
lt.name,
|
||||
'^[[:space:]]*-[[:space:]]*',
|
||||
''
|
||||
)
|
||||
WHERE p_source_sheet = 'AHR_LIMIT'
|
||||
AND lt.id = p_source_row_id
|
||||
AND lt.row_type = 'LEAF'
|
||||
)
|
||||
SELECT r.row_type, r.depth, r.sort_order, r.data
|
||||
FROM v3._form_affected_rows(
|
||||
p_form_id, 'AHR',
|
||||
COALESCE((SELECT array_agg(tl.line_id) FROM target_lines tl), '{}'),
|
||||
'Support', NULL) r
|
||||
ORDER BY r.sort_order;
|
||||
$function$
|
||||
;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user