<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
             SELECT
                    *
                FROM
                    (SELECT
                        A.*,
                        ROWNUM RN
                    FROM
                        (SELECT
                            *
                        FROM
                            (
               SELECT t1.instance_id,
       t1.workflow_id,
       (select distinct t.submitted_by_name
          from zj_wfl_instance_node_rcpt_v t where t.instance_id=t1.instance_id) submitted_by_name,
       t1.workflow_code,
       t1.workflow_desc,
       t1.current_seq,
       t1.created_by,
      (select user_name from sys_user where user_id = t1.submitted_by)user_name,
       t1.instance_status,
       t1.instance_status_desc,
       t1.current_node_desc,
       t1.last_approve_date,
       t1.company_id,
       t1.company_info,
       t1.approve_user_code,
       t1.approve_user_name,
       t1.document_info
  FROM zj_wfl_workflow_instance_v t1
 where t1.instance_status = 1
 and t1.created_by = ${@user_id}
 
 union all
 
 SELECT t1.instance_id,
       t1.workflow_id,
       (select distinct t.submitted_by_name
          from zj_wfl_instance_node_rcpt_v t where t.instance_id=t1.instance_id) submitted_by_name,
       t1.workflow_code,
       t1.workflow_desc,
       t1.current_seq,
       t1.created_by,
      (select user_name from sys_user where user_id = t1.submitted_by)user_name,
       t1.instance_status,
       t1.instance_status_desc,
       t1.current_node_desc,
       t1.last_approve_date,
       t1.company_id,
       t1.company_info,
       t1.approve_user_code,
       t1.approve_user_name,
       t1.document_info
  FROM zj_wfl_workflow_instance_v t1
 where t1.instance_status != 1
 and t1.created_by = ${@user_id}) t #WHERE_CLAUSE#
                        ORDER BY
                            t.last_approve_date DESC
                        )A
                    WHERE
                        ROWNUM <= NVL(${@pagesize},10) * NVL(${@offsize},1)
                    )
                WHERE
                    RN >= 1 + ((NVL(${@offsize},1)-1) * NVL(${@pagesize},10))

            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="instance_id"/>
        <bm:field name="user_name"/>
        <bm:field name="workflow_desc"/>
        <bm:field name="instance_status_desc"/>
        <bm:field name="document_info"/>
        <bm:field name="last_approve_date"/>
        <bm:field name="approve_user_name"/>
        <bm:field name="submitted_by_name"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="searchInput" queryExpression="t.document_info like &apos;%&apos;||${@searchInput}||&apos;%&apos; or t.workflow_desc like &apos;%&apos;||${@searchInput}||&apos;%&apos; or t.instance_status_desc like &apos;%&apos;||${@searchInput}||&apos;%&apos; or t.submitted_by_name like &apos;%&apos;||${@searchInput}||&apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
