<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:oracle="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t" basetable="ZJ_WFL_WORKFLOW_DELIVER">
    <bm:fields>
        <bm:field name="recipient_id" databasetype="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="date_from" databasetype="DATE" datatype="java.sql.Date" prompt="开始日期"/>
        <bm:field name="date_to" databasetype="DATE" datatype="java.sql.Date" prompt="结束日期"/>
        <bm:field name="deliver_to_id" databasetype="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="deliver_reason" databasetype="VARCHAR2" datatype="java.lang.String" prompt="转交原因"/>
        <bm:field name="workflow_id" databasetype="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="record_id" databasetype="NUMBER" datatype="java.lang.Long"/>
<!--        <bm:field name="recipient_name" databasetype="VARCHAR2" datatype="java.lang.String" expression="(select user_name)"/>-->
        <bm:field name="workflow_name" databasetype="VARCHAR2" datatype="java.lang.String" expression="(select z.workflow_desc workflow_name  from  zj_wfl_workflow z where z.workflow_id= t.workflow_id)" prompt="WFL_WORKFLOW.NAME"/>
        <bm:field name="workflow_desc" databasetype="VARCHAR2" datatype="java.lang.String" expression="(select z.workflow_desc workflow_name  from  zj_wfl_workflow z where z.workflow_id= t.workflow_id)" prompt="WFL_WORKFLOW.NAME"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="record_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="recipient_id" queryexpression="t.recipient_id=${/session/@user_id}"/>
        <bm:query-field name="workflow_name" queryexpression="(select z.workflow_desc workflow_name  from  zj_wfl_workflow z where z.workflow_id= t.workflow_id)  like ${@workflow_name}"/>
    </bm:query-fields>
    <bm:relations>
        <bm:relation name="w" jointype="INNER" refmodel="zjwfl.zj_wfl_workflow">
            <bm:reference foreignfield="workflow_id" localfield="workflow_id"/>
        </bm:relation>
        <bm:relation name="u" jointype="INNER" refmodel="sys.sys_user">
            <bm:reference foreignfield="user_id" localfield="deliver_to_id"/>
        </bm:relation>
        <bm:relation name="r" jointype="INNER" refmodel="zjwfl.zj_wfl_users_v_lov">
            <bm:reference foreignfield="user_id" localfield="recipient_id"/>
        </bm:relation>
        <bm:relation name="s" jointype="INNER" refmodel="zjwfl.zj_wfl_users_v_lov">
            <bm:reference foreignfield="user_id" localfield="created_by"/>
        </bm:relation>
        <bm:relation name="e" jointype="INNER" refmodel="exp.exp_employees">
            <bm:reference expression="e.employee_id=u.employee_id"/>
        </bm:relation>
    </bm:relations>
    <bm:features>
        <oracle:sequence-pk/>
        <f:standard-who/>
    </bm:features>
    <bm:ref-fields>
        <bm:ref-field name="recipient_name" prompt="转交人" relationname="r" sourcefield="employee_name"/>
        <bm:ref-field name="created_by_name" prompt="操作人" relationname="s" sourcefield="employee_name"/>
        <bm:ref-field name="user_name" prompt="转交给" relationname="u" sourcefield="user_name"/>
        <!--  <bm:ref-field name="name_id" relationname="w" sourcefield="name_id"/> -->
        <bm:ref-field name="employee_name" prompt="WFL_WORKFLOW_DELIVER.DELIVER_TO" relationname="e" sourcefield="name"/>
    </bm:ref-fields>
    <bm:data-filters>
<!--        <bm:data-filter name="query" expression="(exists (select 1 from sys_user su where su.user_id= ${/session/@user_id} and (su.user_name  in('HAND','HL_ADMIN') or   (su.user_name not in('HAND','HL_ADMIN') and su.user_id=t.recipient_id) )))"/>-->
        <bm:data-filter name="query" expression="(exists (select 1 from sys_role sr where sr.role_id= ${/session/@role_id} and (sr.role_code  in('0017','HAND') or   (sr.role_code not  in('0017','HAND') and ${/session/@user_id}=t.recipient_id) )))"/>
    </bm:data-filters>
</bm:model>
