<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2015-6-10 下午03:17:55  
    $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,
                    faa.file_path,
                    faa.file_type_code,
                    cc.document_id contract_id,
                    (SELECT c.contract_status
                       FROM con_contract c
                      WHERE c.contract_id = cc.document_id) contract_status,
                    (SELECT hbm.bp_name
                       FROM con_contract c,hls_bp_master hbm
                      WHERE c.bp_id_tenant = hbm.bp_id
                      and c.contract_id = cc.document_id) bp_id_tenant_n,
                    '所有权转移通知书(' ||
                    (SELECT hbm.bp_name
                   FROM con_contract c,hls_bp_master hbm
                  WHERE c.bp_id_tenant = hbm.bp_id
                  and c.contract_id = cc.document_id)
                  || '_' ||
                 (SELECT c.contract_number
                    FROM con_contract c
                   WHERE c.contract_id = cc.document_id)|| ')' down_file_name,
                     faa.file_name to_file_name,
                    (SELECT 'Y'
                       FROM fnd_atm_attachment_multi m1
                      WHERE m1.table_name = 'HLS_DOC_FILE_CONTENT'
                        AND m1.table_pk_value = cc.content_id) file_exists_flag,
                    cc.content_id,
                    (SELECT cct.templet_code
                       FROM con_clause_templet cct
                      WHERE cct.templet_id = cc.templet_id) templet_code,
                    faa.attachment_id
               FROM fnd_atm_attachment       faa,
                    fnd_atm_attachment_multi m,
                    hls_doc_file_templet     lt,
                    con_clause_templet       t,
                    hls_doc_file_content     cc,
                    contract_cashflow_load_temp clt
              WHERE faa.attachment_id = m.attachment_id
                AND m.table_name = 'HLS_DOC_FILE_TEMPLET'
                AND m.table_pk_value = lt.templet_id
                AND lt.templet_id = t.doc_template_id
                AND t.doc_plugin_flag = 'Y'
                AND t.templet_id = cc.templet_id
                and clt.contract_id = cc.document_id
                and (((SELECT c.contract_status
                    FROM con_contract c
                   WHERE c.contract_id = cc.document_id) in
               ('TERMINATE', 'ET', 'INCEPT', 'ETING', 'TERMINATING') and
               cc.document_table = 'CON_CONTRACT_FINISH_LEASE') or
               ((SELECT c.contract_status
                    FROM con_contract c
                   WHERE c.contract_id = cc.document_id) in ('REPUR', 'REPURING') and
               cc.document_table = 'CON_CONTRACT_FINISH_REPUR'))
                and clt.session_id=${/session/@session_id}
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            	begin
            		hls_doc_file_templet_pkg.init_hls_doc_file_content(
            		  p_document_id    =>${@document_id},
                      p_document_table =>${@document_table},
                      p_user_id        =>nvl(${/session/@user_id},${/parameter/@user_id}));
            	end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
        <bm:field name="down_file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOWN_FILE_NAME"/>
        <bm:field name="file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_PATH"/>
        <bm:field name="file_type_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_TYPE_CODE"/>
        <bm:field name="file_exists_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_EXISTS_FLAG"/>
        <bm:field name="to_file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TO_FILE_NAME"/>
        <bm:field name="content_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ID"/>
        <bm:field name="attachment_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="bp_id_tenant_n" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="contract_status" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID"/>
      </bm:fields>
</bm:model>
