<?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"/>-->
<!--&lt;!&ndash;        <bm:field name="recipient_name" databasetype="VARCHAR2" datatype="java.lang.String" expression="(select user_name)"/>&ndash;&gt;-->
<!--        <bm:field name="workflow_name" databasetype="VARCHAR2" datatype="java.lang.String"  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"/>-->
<!--        &lt;!&ndash;  <bm:ref-field name="name_id" relationname="w" sourcefield="name_id"/> &ndash;&gt;-->
<!--        <bm:ref-field name="employee_name" prompt="WFL_WORKFLOW_DELIVER.DELIVER_TO" relationname="e" sourcefield="name"/>-->
<!--    </bm:ref-fields>-->
<!--    <bm:data-filters>-->
<!--&lt;!&ndash;        <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) )))"/>&ndash;&gt;-->
<!--        <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) ))) order by t.creation_date desc"/>-->
<!--    </bm:data-filters>-->
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
SELECT VV.*
  FROM (SELECT t.recipient_id,
               t.date_from,
               t.date_to,
               t.deliver_to_id,
               t.deliver_reason,
               t.creation_date,
               t.workflow_id,
               t.record_id,
               (select z.workflow_desc workflow_name
                  from zj_wfl_workflow z
                 where z.workflow_id = t.workflow_id) AS workflow_name,
               (select z.workflow_desc workflow_name
                  from zj_wfl_workflow z
                 where z.workflow_id = t.workflow_id) AS workflow_desc,
               r.EMPLOYEE_NAME AS recipient_name,
               s.EMPLOYEE_NAME AS created_by_name,
               u.user_name,
               e.NAME AS employee_name
          FROM ZJ_WFL_WORKFLOW_DELIVER t
         INNER JOIN ZJ_WFL_USERS_V r
            ON t.recipient_id = r.USER_ID
         INNER JOIN ZJ_WFL_USERS_V s
            ON t.CREATED_BY = s.USER_ID
         INNER JOIN sys_user u
            ON t.deliver_to_id = u.user_id
         INNER JOIN EXP_EMPLOYEES e
            ON e.employee_id = u.employee_id
         WHERE (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))))) VV
                         #WHERE_CLAUSE#
 order by vv.creation_date desc
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <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="workflow_name" databasetype="VARCHAR2" datatype="java.lang.String"  prompt="WFL_WORKFLOW.NAME"/>
        <bm:field name="workflow_desc" databasetype="VARCHAR2" datatype="java.lang.String"  prompt="WFL_WORKFLOW.NAME"/>
        <bm:field name="recipient_name" databasetype="VARCHAR2" datatype="java.lang.String"  prompt="转交人"/>
        <bm:field name="created_by_name" databasetype="VARCHAR2" datatype="java.lang.String"  prompt="操作人"/>
        <bm:field name="user_name" databasetype="VARCHAR2" datatype="java.lang.String"  prompt="转交给"/>
        <bm:field name="employee_name" databasetype="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="workflow_name" queryExpression="VV.workflow_name=${@workflow_name}"/>
    </bm:query-fields>
</bm:model>
