<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select hbm.bp_id,
			       hbm.bp_name,                                                     --主承租人分析(集团内)
			       (SELECT distinct t.ref_v09
			                  FROM bgfl_hls_report_data t
			                 WHERE t.function_code = 'HN5040'
			                   and t.ref_v03 = 'WITHIN_GROUP'
			                   and t.session_id = ${/session/@session_id}
			                   and t.ref_n02 = hbm.bp_id) binary_classification_n,  --行业细分
			       (SELECT sum(t.ref_n09) 
			                  FROM bgfl_hls_report_data t
			                 WHERE t.function_code = 'HN5040'
			                   and t.ref_v03 = 'WITHIN_GROUP'
			                   and t.session_id = ${/session/@session_id}
			                   and t.ref_n02 = hbm.bp_id) sum_amount_rent,        --剩余租金小计
			       (TO_CHAR(ROUND((SELECT sum(t.ref_n09) 
			                  FROM bgfl_hls_report_data t
			                 WHERE t.function_code = 'HN5040'
			                   and t.ref_v03 = 'WITHIN_GROUP'
			                   and t.session_id = ${/session/@session_id}
			                   and t.ref_n02 = hbm.bp_id)/(
			        SELECT sum(bhrd.ref_n07)
			                   FROM bgfl_hls_report_data bhrd
			                 WHERE bhrd.function_code = 'HN5040'
			                     and bhrd.ref_v03 = 'WITHIN_GROUP'
			                     and bhrd.session_id = ${/session/@session_id})*100,2),'FM90.00')|| '%') sum_amount_rent_percent,   --剩余租金占比
			       (SELECT sum(t.ref_n06) 
			                  FROM bgfl_hls_report_data t
			                 WHERE t.function_code = 'HN5040'
			                   and t.ref_v03 = 'WITHIN_GROUP'
			                   and t.session_id = ${/session/@session_id}
			                   and t.ref_n02 = hbm.bp_id) sum_amount_principal,        --剩余本金小计
			       (TO_CHAR(ROUND((SELECT sum(t.ref_n06) 
			                  FROM bgfl_hls_report_data t
			                 WHERE t.function_code = 'HN5040'
			                   and t.ref_v03 = 'WITHIN_GROUP'
			                   and t.session_id = ${/session/@session_id}
			                   and t.ref_n02 = hbm.bp_id)/(
			        SELECT sum(bhrd.ref_n06)
			                   FROM bgfl_hls_report_data bhrd
			                 WHERE bhrd.function_code = 'HN5040'
			                     and bhrd.ref_v03 = 'WITHIN_GROUP'
			                     and bhrd.session_id = ${/session/@session_id})*100,2),'FM90.00')|| '%') sum_amount_principal_percent   --剩余租金占比
			  from hls_bp_master hbm
			 where hbm.bp_id in (select bhrd.ref_n02
			                       FROM bgfl_hls_report_data bhrd
			                      WHERE bhrd.function_code = 'HN5040'
			                        and bhrd.ref_v03 = 'WITHIN_GROUP'
			                        and bhrd.session_id = ${/session/@session_id})
	          ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
