<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="file_name"/>
        <bm:field name="file_path"/>
        <bm:field name="file_size"/>
        <bm:field name="order_seq"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select fa.file_name, fa.file_path, fa.file_size, ct.order_seq
              from fnd_atm_attachment       fa,
                   fnd_atm_attachment_multi fm,
                   con_contract_content     cc,
                   con_clause_templet       ct
             where fa.attachment_id = fm.attachment_id
               and fm.table_name = 'CON_CONTRACT_CONTENT'
               and cc.contract_id = ${@contract_id}
               and cc.content_id = fm.table_pk_value
               and cc.templet_id = ct.templet_id
               and fm.table_pk_value = cc.content_id
               and ct.templet_code in
                   (select cf.templet_code
                      from con_ele_signer_file cf, con_contract_ele_signer cs
                     where cf.con_ele_signer_id = cs.con_ele_signer_id
                       and cs.contract_id = ${@contract_id}
                       and (((select cr.id_type
                                from con_contract_ele_signer cr
                               where cr.id_no = ${@id_no}
                                 and rownum = 1) = 'IdCard' and exists
                            (select 1
                                from hls_doc_file_templet_signer hs,
                                     con_clause_templet          ct,
                                     hls_doc_file_templet        ht
                               where hs.templet_id = ht.templet_id
                                 and ht.templet_code = ct.templet_code
                                 and ct.templet_id = cf.templet_id
                                 and hs.enable_flag = 'Y'
                                 and hs.signer_category not in
                                     ('AGENCY_STORE_SEAL',
                                      'AGENCY_STORE_SIGN',
                                      'HONGLING_SEAL',
                                      'HONGLING_SIGN'))) or
                           (select cr.id_type
                               from con_contract_ele_signer cr
                              where cr.id_no = ${@id_no}
                                and rownum = 1) = 'license'))
                order by ct.order_seq
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
