<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date: 2017-12-12 下午4:33:19  
    $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
                        pp.project_id,
                        pp.bp_id_tenant,
                        (SELECT hbm.bp_name FROM hls_bp_master hbm WHERE hbm.bp_id = pp.bp_id_tenant
                        ) bp_name,
                        pp.project_number,
                        pp.project_name
                    FROM
                        prj_project pp
                    WHERE
                        pp.project_status = 'APPROVED' AND
                        pp.data_class     = 'NORMAL' AND
                        NOT EXISTS
                        (SELECT
                            1
                        FROM
                            prj_project_change_req ps
                        WHERE
                            ps.project_id  = pp.project_id AND
                            ps.req_status IN ('NEW', 'APPROVING', 'REJECT', 'RETURN')
                        )AND
                        EXISTS
                        (SELECT
                            1
                        FROM
                            aut_trx_user_authorize a1,
                            aut_owner_user_authorize a2
                        WHERE
                            a1.trx_category = 'PROJECT' AND
                            a1.trx_id       = pp.project_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.project_id DESC
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="project_id"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="PROJECT_NUMBER" prompt="项目编号"/>
        <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" forQuery="true" physicalName="PROJECT_NAME" prompt="项目名称"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" forDisplay="true" physicalName="BP_NAME" prompt="承租人"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="project_number" queryOperator="like"/>
        <bm:query-field field="project_name" queryOperator="like"/>
    </bm:query-fields>
</bm:model>
