<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng    modify  by shz 2017-11-13
    $Date: 2017-7-18 下午5:07: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
                    t1.request_id,
                    t1.trx_category,
                    t1.trx_id,
                    t1.request_user_id,
                    t1.document_owner_user_id,
                    t1.request_status,
                    t1.end_date,
                    t1.start_date,
                    v.chance_bp_id,
                    v.chance_bp_name,
                    v.bp_class_n,
                    v.unit_id_n,
                    v.owner_user_id_n,
                      (select su.description from sys_user su where su.user_id  =t1.request_user_id) request_user_id_n
                FROM
                    hn_document_grant_request t1,
                    hn_chance_bp_v v
                WHERE
                    t1.trx_category = 'CHANCE_BP' AND
                    t1.trx_id       = v.chance_bp_id AND
                    t1.request_id   = ${@request_id} AND
                    t1.trx_id       = ${@trx_id}
                    
                UNION
                SELECT
                    t1.request_id,
                    t1.trx_category,
                    t1.trx_id,
                    t1.request_user_id,
                    t1.document_owner_user_id,
                    t1.request_status,
                    t1.end_date,
                    t1.start_date,
                    v.bp_id chance_bp_id,
                    v.bp_name chance_bp_name,
                    v.bp_class_n,
                    (select e1.unit_name
                     from exp_emp_assign_e_v e1
                     where e1.user_id = v.owner_user_id
                     and e1.primary_position_flag = 'Y')unit_id_n,
                     v.owner_user_id_n,
                      (select su.description from sys_user su where su.user_id  =t1.request_user_id) request_user_id_n
                FROM
                    hn_document_grant_request t1,
                    hls_bp_master_lv v
                WHERE
                    t1.trx_category = 'BP' AND
                    t1.trx_id       = v.bp_id AND
                    t1.request_id   = ${@request_id} AND
                    t1.trx_id       = ${@trx_id}
                
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="request_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REQUEST_ID" required="true"/>
        <bm:field name="trx_category" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TRX_CATEGORY"/>
        <bm:field name="trx_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TRX_ID"/>
        <bm:field name="request_user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REQUEST_USER_ID"/>
        <bm:field name="document_owner_user_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOCUMENT_OWNER_USER_ID"/>
        <bm:field name="request_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REQUEST_STATUS"/>
        <bm:field name="end_date" databaseType="DATE" datatype="java.util.Date" physicalName="END_DATE"/>
        <bm:field name="start_date" databaseType="DATE" datatype="java.util.Date" physicalName="START_DATE"/>
        <bm:field name="chance_bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CHANCE_BP_ID" required="true"/>
        <bm:field name="chance_bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CHANCE_BP_NAME"/>
        <bm:field name="bp_class_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_CLASS_N"/>
        <bm:field name="unit_id_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="UNIT_ID_N"/>
        <bm:field name="owner_user_id_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="OWNER_USER_ID_N"/>
        <bm:field name="request_user_id_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REQUEST_USER_ID_N"/>
    </bm:fields>
</bm:model>
