<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    wfl_instance_pdf_pkg.create_wfl_instance_content(p_instance_id => ${@instance_id},
                    					p_user_id => nvl(${/session/@user_id},${@user_id}));
                    commit;
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                BEGIN
                    wfl_instance_pdf_pkg.insert_fnd_atm(
                        p_table_name     =>${@table_name},
                        p_table_pk_value =>${@instance_id},
                        p_file_name      =>${@file_name},
                        p_file_path      =>${@file_path},
                        p_user_id        =>nvl(${/session/@user_id},${@user_id}),
                        p_file_size      =>${@file_size}
                    );
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    faa.file_name,
                    faa.file_path,
                    faa.file_type_code,
                    '建机审批流版式文件-' ||decode(z.workflow_id,-1,substr(z.instance_desc,instr(z.instance_desc,'-',1)+1),(select w.workflow_desc from zj_wfl_workflow w where w.workflow_id=z.workflow_id)) || '-' || z.instance_id || '.docx' to_file_name,
                    lt.pwd,
                    fc.document_id,
                    fc.content_id
                FROM
                    fnd_atm_attachment faa,
                    fnd_atm_attachment_multi m,
                    hls_doc_file_templet lt,
                    con_clause_templet t,
                    hls_doc_file_content fc,
                    zj_wfl_workflow_instance z
                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      = fc.templet_Id AND
                    fc.document_id = z.instance_id AND
                    fc.document_table = 'ZJ_WFL_WORKFLOW_INSTANCE' and
                    z.instance_id = ${@instance_id}
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                begin
                    wfl_instance_pdf_pkg.save_pdf_atm(p_instance_id =>${@instance_id},
               									p_table_name    =>${@table_name});
                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="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="to_file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TO_FILE_NAME"/>
        <bm:field name="pwd" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PWD"/>
        <bm:field name="document_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOCUMENT_ID"/>
        <bm:field name="content_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ID"/>
    </bm:fields>
</bm:model>
