<?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 * FROM(
            select tlc.data_class,
			       tlc.original_con_num,
			       tlc.loan_contract_number, --借款合同号
			       tlc.loan_con_bp, --交易对手
			       (select e.bp_name
			        from hls_bp_master e
			        where e.bp_id=tlc.loan_con_bp) loan_bp_name,
			       tlc.loan_amount,   --借款金额
			       tlc.total_interest,--全部利息
			       tlc.inside_or_outside,
			       tlc.loan_contract_id,
			       'v' || (SELECT COUNT(1) + 1
					                 FROM hls_document_history cct
					                WHERE cct.document_id = tlc.loan_contract_id
					                  AND cct.data_class IN ('NORMAL', 'HISTORY')) version
			  from tre_loan_contract tlc
			 where tlc.data_class = 'NORMAL'
			   and tlc.loan_con_wfl_status = 'WFL_APPROVED'
			   and tlc.loan_contract_id in
			       (select pq.document_id
			          from prj_quotation pq
			         where pq.document_category = 'LOAN_CONTRACT'
			           and pq.document_id = tlc.loan_contract_id
			           and nvl(pq.main_contract_flag, 'N') <> 'Y'
			           and nvl(pq.wfl_status, 'NEW') = 'APPROVED')) t1
                    #WHERE_CLAUSE#
           ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="data_class" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DATA_CLASS"/>
        <bm:field name="original_con_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ORIGINAL_CON_NUM"/>
        <bm:field name="loan_contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LOAN_CONTRACT_NUMBER"/>
        <bm:field name="loan_con_bp" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LOAN_CON_BP"/>
        <bm:field name="loan_bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LOAN_BP_NAME"/>
        <bm:field name="loan_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LOAN_AMOUNT"/>
        <bm:field name="inside_or_outside" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSIDE_OR_OUTSIDE"/>
        <bm:field name="loan_contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LOAN_CONTRACT_ID" required="true"/>
        <bm:field name="version" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="loan_contract_number" queryExpression="t1.loan_contract_number like &apos;%&apos;||${@loan_contract_number}||&apos;%&apos;"/>
        <bm:query-field name="original_con_num" queryExpression="t1.original_con_num like &apos;%&apos;||${@original_con_num}||&apos;%&apos;"/>
        <bm:query-field name="loan_bp_name" queryExpression="t1.loan_bp_name like &apos;%&apos;||${@loan_bp_name}||&apos;%&apos;"/>
        <!--  <bm:query-field name="loan_amount" queryExpression="t1.loan_amount like &apos;%&apos;||${@loan_amount}||&apos;%&apos;"/> -->
        <bm:query-field name="inside_or_outside_n" queryExpression="t1.inside_or_outside like &apos;%&apos;||${@inside_or_outside}||&apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
