<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-12-14 下午6:48:34  
    $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
                    *
                FROM
                    (SELECT
                        hbm.bp_id,
                        hbm.bp_code,
                        hbm.bp_name,
                        hbm.bp_class
                    FROM
                        hls_bp_master hbm
                    WHERE
                        EXISTS
                        (SELECT
                            1
                        FROM
                            hls_bp_master_role d
                        WHERE
                            d.bp_id        = hbm.bp_id AND
                            d.bp_category  = 'VENDER' AND
                            d.enabled_flag = 'Y'
                        ) AND
                        hbm.enabled_flag = 'Y' AND
                        EXISTS
                        (SELECT
                            1
                        FROM
                            aut_trx_user_authorize a1,
                            aut_owner_user_authorize a2
                        WHERE
                            a1.trx_category = 'BP' AND
                            a1.trx_id       = hbm.bp_id AND
                            TRUNC(sysdate) BETWEEN a1.start_date AND NVL(a1.end_date, TRUNC(sysdate)) AND
                            a1.user_id            = a2.owner_user_id AND
                            a1.trx_category       = a2.trx_category AND
                            a2.authorized_user_id = ${/session/@user_id} AND
                            TRUNC(sysdate) BETWEEN a2.start_date AND NVL(a2.end_date, TRUNC(sysdate))
                        )
                    ) t1 #WHERE_CLAUSE#
                ORDER BY
                    t1.bp_id DESC
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="bp_id"/>
        <bm:field name="bp_code" forDisplay="true" forQuery="true" prompt="商业伙伴编码"/>
        <bm:field name="bp_name" displayWidth="200" forDisplay="true" forQuery="true" prompt="商业伙伴名称"/>
        <bm:field name="bp_class"/>
    </bm:fields>
</bm:model>
