<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2014-11-26 下午04:24:11  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    faa.file_name,
                    (ccc.bp_id_agent_level1_n
                    ||'_'
                    ||
                    (SELECT
                        t.contract_number
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = doc.contract_id
                    )
                    ||'_'
                    ||ccc.bp_name
                    || '_'
                    || ccc.templet_name
                    ||'.doc') AS file_name2,
                    faa.file_path,
                    (SELECT
                        t.bp_id_tenant_n
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = doc.contract_id
                    ) bp_id_tenant_n,
                    (SELECT
                        t.contract_number
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = doc.contract_id
                    ) contract_number,
                    (SELECT
                        t.project_number
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = doc.contract_id
                    ) project_number,
                    doc.content_number,
                    faa.attachment_id,
                    ccc.templet_code
                FROM
                    con_contract_content doc,
                    fnd_atm_attachment_multi fam,
                    fnd_atm_attachment faa,
                    CON_CONTRACT_CONTENT_V ccc,
                    content_create_temp ct
                WHERE
                    doc.content_id         =ccc.content_id AND
                    doc.content_print_flag = 'Y' AND
                    doc.content_id         = NVL(${@content_id}, doc.content_id) AND
                    doc.contract_id        = ct.contract_id AND
                    ct.session_id		   = ${@session_id} and
                    doc.clause_usage	   = 'CON_SQUARE' AND
                    fam.table_name         = 'CON_CONTRACT_CONTENT' AND
                    fam.table_pk_value     = doc.content_id AND
                    fam.attachment_id      = faa.attachment_id
                order by ccc.bp_id_agent_level1_n
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="file_name2" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
        <bm:field name="file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_PATH"/>
        <bm:field name="bp_id_tenant_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_ID_TENANT_N"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NUMBER"/>
        <bm:field name="content_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTENT_NUMBER"/>
        <bm:field name="attachment_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ATTACHMENT_ID"/>
        <bm:field name="templet_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TEMPLET_CODE"/>
    </bm:fields>
</bm:model>
