<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="attachment_id"/>
        <bm:field name="file_name"/>
        <bm:field name="file_path"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
select fa.file_name,fa.file_path,fa.attachment_id
                   from prj_cdd_item pi,PRJ_CDD_ITEM_CHECK pc,fnd_atm_attachment_multi fm,fnd_atm_attachment fa
                  where pc.cdd_item_id = pi.cdd_item_id
                   and fm.table_pk_value = pc.check_id
                   and fm.attachment_id = fa.attachment_id
                   and fm.table_name = 'CON_CONTRACT'
                   and pi.cdd_item in
                        (select decode(cf.templet_code,
                                'LEASE_CONTRACT_MASTER_OEC','CONTRACT',
                                'LEASE_REQUEST_OEC','LEASE_ITEM_REQ',
                                'LEASE_INFO_OEC','TN_GU_INFO',
                                'LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'LEASE_SURE_SEL_OEC','S_GUARANTEE_LETTER_OEC',
                                'LEASE_CHECK_OEC','CHECK_INFO',
                                'LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'LEASE_SALE_RL_OEC','PUR_CONTRACT',
                                'LEASE_SALE_YL_OEC','PUR_CONTRACT',
                                'LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_CONTRACT_MASTER_OEC','CONTRACT',
                                'R_LEASE_REQUEST_OEC','LEASE_ITEM_REQ',
                                'R_LEASE_INFO_OEC','TN_GU_INFO',
                                'R_LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_SURE_SEL_OEC','S_GUARANTEE_LETTER_OEC',
                                'R_LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_CHECK_OEC','CHECK_INFO',
                                'R_LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'R_LEASE_SALE_OEC','PUR_CONTRACT',
                                'S_LEASE_CONTRACT_MASTER_B_OEC','CONTRACT',
                                'S_LEASE_PAY_OEC','CASHFLOW_INFO',
                                'S_LEASE_CHECK_OEC','CHECK_INFO',
                                'S_LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'S_LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'S_LEASE_SURE_F_OEC','S_GUARANTEE_LETTER_OEC',
                                'S_LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'S_LEASE_ORDER_OEC','ITEM_TRAN_NOTICE',
                                'S_LEASE_PAY_REQ_OEC','PAYMENT_REQ',
                                'S_LEASE_MOR_OEC','MORT_CONTRACT',
                                'FINANCE_LEASE_CONTRACT_TJ_S_E',  --update by xsh35973 铁甲电子签约
                                'FINANCE_LEASE_CONTRACT_TJ_S_E',
                                'FINANCE_LEASE_CONTRACT_TJ_E',
                                'FINANCE_LEASE_CONTRACT_TJ_E',
                                'CON_COLLECTION_PAYMENT_TJ_E',
                                'CON_COLLECTION_PAYMENT_TJ_E',
                                'CON_CONTRACT_MORTGAGE_TJ_E',
                                'CON_CONTRACT_MORTGAGE_TJ_E',
                                'PERSONAL_CREDIT',
                                'PERSONAL_CREDIT',
                                'FINANCE_LEASE_CONTRACT_TJ_FR_E',
                                'FINANCE_LEASE_CONTRACT_TJ_FR_E',
								'FINANCE_LEASE_CONTRACT_FR_TJ_E','FINANCE_LEASE_CONTRACT_FR_TJ_E',
                                'CSH_PAYMENT_REQ_TJ_E','CSH_PAYMENT_REQ_TJ_E',
                                'CON_GUR_NP',
                                'CON_GUR_NP',
                                --'FINANCE_LEASE_CONTRACT_FR_KJ_E','FINANCE_LEASE_CONTRACT_FR_KJ_E',--update by gzj 北京卡家电子签约
                                --'FINANCE_LEASE_CONTRACT_KJ_FR_E','FINANCE_LEASE_CONTRACT_KJ_FR_E',
                                --'FINANCE_LEASE_CONTRACT_KJ_S_E','FINANCE_LEASE_CONTRACT_KJ_S_E',
                                --'FINANCE_LEASE_CONTRACT_KJ_E','FINANCE_LEASE_CONTRACT_KJ_E',
                                --'CSH_PAYMENT_REQ_KJ_1_E','CSH_PAYMENT_REQ_KJ_1_E',
                                --'CON_CONTRACT_MORTGAGE_KJ_E','CON_CONTRACT_MORTGAGE_KJ_E',
                                --'LEASE_CONTRACT_PAR_KJ_E','LEASE_CONTRACT_PAR_KJ_E',
                                --'LEASE_CONTRACT_PAR_KJ_1_E','LEASE_CONTRACT_PAR_KJ_1_E',
                                --'CON_COLLECTION_PAYMENT_KJ_E','CON_COLLECTION_PAYMENT_KJ_E',
								 --北京心诚合并二手机
                                'FINANCE_LEASE_CONTRACT_KJ_E','FINANCE_LEASE_CONTRACT_TJ_E',
                                'CON_CONTRACT_MORTGAGE_KJ_E','CON_CONTRACT_MORTGAGE_TJ_E',
                                'CON_COLLECTION_PAYMENT_KJ_E','CON_COLLECTION_PAYMENT_TJ_E',
                                'CSH_PAYMENT_REQ_KJ_1_E','CSH_PAYMENT_REQ_TJ_E',
                                'LEASE_CONTRACT_PAR_KJ_1_E','SPOUSE_COMMITMENT',
                                'LEASE_CONTRACT_PAR_KJ_E','GUARANTEE_COMMITMENT',
                                'FINANCE_LEASE_CONTRACT_KJ_S_E','FINANCE_LEASE_CONTRACT_TJ_S_E',
                                'FINANCE_LEASE_CONTRACT_FR_KJ_E','FINANCE_LEASE_CONTRACT_FR_TJ_E',
                                'FINANCE_LEASE_CONTRACT_KJ_FR_E','FINANCE_LEASE_CONTRACT_TJ_FR_E',
                                --'PERSONAL_CREDIT','PERSONAL_CREDIT',
                                'ENTERPRISE_CREDIT','ENTERPRISE_CREDIT',
								'PERSONAL_CREDIT_BLD_E',
                                'CREDIT_AUTHOR',
                                'ENTERPRISE_CREDIT_BLD_E',
                                'CREDIT_AUTHOR',
                                'PERSONAL_CREDIT_GUTA_BLD_E',
                                'CREDIT_AUTHOR',
                                'ENTERPRISE_CREDIT_GUTA_BLD_E',
                                'CREDIT_AUTHOR',
                                'ACCEPTANCE_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PAR_TENANT_BLD_E',
                                'SPOUSE_COMMITMENT',
                                'PAR_GUTA_BLD_E',
                                'SPOUSE_COMMITMENT',
                                'SURE_LEASE_GR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'SURE_LEASE_FR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PROOF_RECEIPT_LEASE_BLD_E',
                                'CHECK_INFO',
                                'LEASE_SALE_BLD_E',
                                'PUR_CONTRACT',
                                'FINANCE_LEASE_CONTRACT_BLD_E',
                                'CONTRACT',
                                'SURE_LEASEBACK_GR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'SURE_LEASEBACK_FR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PROOF_RECEIPT_LEASEBACK_BLD_E',
                                'CHECK_INFO',
                                'LEASE_ORDER_LEASEBACK_BLD_E',
                                'ITEM_TRAN_NOTICE',
                                'CON_CONTRACT_MORTGAGE_BLD_E',
                                'MORT_CONTRACT',
                                'CON_CONTRACT_LEASEBACK_BLD_E',
                                'CONTRACT',
								  --云南铁拳合同文本匹配关系  18083 2024/5/22
                                'CON_CONTRACT_LEASEBACK_YNTQ','FINANCE_LEASE_CONTRACT_TJ_E',
                                'CON_CONTRACT_MORTGAGE_YNTQ','CON_CONTRACT_MORTGAGE_TJ_E',
                                'CON_COLLECTION_PAYMENT_YNTQ','CON_COLLECTION_PAYMENT_TJ_E',
                                'CSH_LEASEBACK_YNTQ','CSH_PAYMENT_REQ_TJ_E',
                                'PAR_TENANT_YNTQ','SPOUSE_COMMITMENT',
                                'PAR_GUTA_YNTQ','GUARANTEE_COMMITMENT',
                                'SURE_LEASEBACK_GR_YNTQ','FINANCE_LEASE_CONTRACT_TJ_S_E',
                                'SURE_LEASEBACK_FR_YNTQ','FINANCE_LEASE_CONTRACT_FR_TJ_E',
                                'SURE_LEASEBACK_FR_HLJ_YNTQ','FINANCE_LEASE_CONTRACT_TJ_FR_E',
                                'PERSONAL_CREDIT_YNTQ','PERSONAL_CREDIT',
                                'ENTERPRISE_CREDIT_YNTQ','ENTERPRISE_CREDIT',
                                'PERSONAL_CREDIT_GUTA_YNTQ','PERSONAL_CREDIT',
                                'ENTERPRISE_CREDIT_GUTA_YNTQ','ENTERPRISE_CREDIT',
								--河南融投和茂甲文本匹配  38823
                                'PAR_TENANT_LB_OEC','SPOUSE_COMMITMENT',
                                'PAR_GUTA_LB_OEC','GUARANTEE_COMMITMENT',
                                'F_LEASE_CONTRACT_TJ_S_EHN','FINANCE_LEASE_CONTRACT_TJ_E',
                                'LEASEBACK_ORDER_OEC','LEASEBACK_ORDER_OEC',
								 --二手机合并新增模板匹配
                                'PERSONAL_CREDIT_KJ_E','PERSONAL_CREDIT',
                                'GUARANTOR_PERSONAL_CREDIT_KJ_E','PERSONAL_CREDIT',
                                'ENTERPRISE_CREDIT_KJ_E','ENTERPRISE_CREDIT',
                                'PERSONAL_CREDIT_MJ_E','PERSONAL_CREDIT',
                                'GUARANTOR_PERSONAL_CREDIT_MJ_E','PERSONAL_CREDIT',
                                'ENTERPRISE_CREDIT_MJ_E','ENTERPRISE_CREDIT',
								--二手机新增付款请求书区分签署人，卖方付款
                                'CSH_PAYMENT_REQ_TJ_RE','CSH_PAYMENT_REQ_TJ_E',
                                --'CSH_PAYMENT_REQ_KJ_1_RE','CSH_PAYMENT_REQ_KJ_1_E',
								 'CSH_PAYMENT_REQ_KJ_1_RE','CSH_PAYMENT_REQ_TJ_E',
                                'CSH_LEASEBACK_YNTQ_RE','CSH_PAYMENT_REQ_TJ_E',
                                --广东鑫源  保证函（广东鑫众实控人）
                                'FINANCE_LEASE_CONTRACT_GXZ_S_E','FINANCE_LEASE_CONTRACT_GXZ_S_E',
                                'GUA_PERSONAL_CREDIT_MJ_SE','PERSONAL_CREDIT'
                                )
                    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 ((('AGENT' not in (select cb.bp_category
                     from con_contract_bp cb, hls_bp_master hm
                    where cb.bp_id = hm.bp_id
                      and hm.social_code = ${@id_no}
                      and cb.contract_id = cs.contract_id) or
                    not exists (select 1
                           from con_contract_bp cb, hls_bp_master hm
                          where cb.bp_id = hm.bp_id
                            and hm.social_code = ${@id_no}
                            and cb.contract_id = cs.contract_id))
                     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',
										 'MAN_FACTURER_SEAL',
                                         'MAN_FACTURER_SIGN',
                                         'SUPPLIER_SEAL',
                                         'SUPPLIER_SIGN',
                                         'LEASE_SUPPLIER_SEAL',
                                         'LEASE_SUPPLIER_SIGN')))
                     or 'AGENT' in (select cb.bp_category
                   from con_contract_bp cb, hls_bp_master hm
                  where cb.bp_id = hm.bp_id
                    and hm.social_code = ${@id_no}
                    and cb.contract_id = cs.contract_id)
				   or 'VENDER' in (select cb.bp_category
                                     from con_contract_bp cb, hls_bp_master hm
                                    where cb.bp_id = hm.bp_id
                                      and hm.social_code = ${@id_no}
                                      and cb.contract_id = cs.contract_id)))
                    and pi.cdd_list_id =
                        (select cc.cdd_list_id
                           from con_contract cc
                          where cc.contract_id = ${@contract_id}
                            and cc.data_class = 'NORMAL')
                    order by pi.order_seq
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
