<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lxb 
    $Date: 2015-7-10 下午03:44:00  
    $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
                        A.*,
                        ROWNUM RN
                    FROM
                        (SELECT
                            t1.instance_id,
                            t1.workflow_id,
                            t1.workflow_code,
                            t1.workflow_desc,
                            t1.submitted_by,
                            t1.submitted_by_name,
                            t1.current_seq,
                            t1.created_by,
                            t1.instance_status,
                            t1.instance_status_desc,
                            DECODE(t1.instance_status, '1', 'agree', '10', 'agree', '-1', 'return') status,
                            DECODE(t1.instance_status, '1', '正在运行', '10', '已通过', '-1', '已拒绝') status_n,
                            t1.current_node_desc,
                            t1.last_approve_date,
                            t1.document_info,
                            DECODE(t1.workflow_code, 'CSH_PAYMENT_WFL', '付', 'WFL_PRJ_DEP2', '租' ,'WFL_PRJ_DEP1', '租','PRJ_PREAPPLY_WFL', '租', '') title,
                            
                            DECODE(t1.workflow_code, 'CSH_PAYMENT_WFL', 'yellow', 'WFL_PRJ_DEP2', 'green' ,'WFL_PRJ_DEP1', 'green','PRJ_PREAPPLY_WFL', 'green', '') color,
                            wx_wfl_pkg.get_document_id(p_instance_id => t1.instance_id, p_current_seq => t1.current_seq, p_workflow_code => t1.workflow_code) document_id
                        FROM
                            zj_wfl_workflow_instance_v t1 #WHERE_CLAUSE#
                        ORDER BY
                            t1.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" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INSTANCE_ID"/>
        <bm:field name="workflow_id" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WORKFLOW_ID"/>
        <bm:field name="workflow_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WORKFLOW_CODE"/>
        <bm:field name="workflow_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WORKFLOW_DESC"/>
        <bm:field name="submitted_by" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SUBMITTED_BY"/>
        <bm:field name="submitted_by_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SUBMITTED_BY_NAME"/>
        <bm:field name="current_seq" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID"/>
        <bm:field name="created_by" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CREATED_BY"/>
        <bm:field name="instance_status"/>
        <bm:field name="instance_status_desc"/>
        <bm:field name="status"/>
        <bm:field name="status_n"/>
        <bm:field name="current_node_desc"/>
        <bm:field name="last_approve_date" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LAST_APPROVE_DATE"/>
        <bm:field name="document_info"/>
        <bm:field name="document_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DOCUMENT_ID"/>
        <bm:field name="title"/>
        <bm:field name="color"/>
    </bm:fields>
    <bm:data-filters>
        <bm:data-filter name="user_id" enforceOperations="query" expression="t1.submitted_by = ${@user_id}"/>
        <bm:data-filter name="company_id" enforceOperations="query" expression="t1.company_id=1"/>
        <bm:data-filter name="workflow_code" enforceOperations="query" expression="t1.workflow_code in (&apos;CSH_PAYMENT_WFL&apos;,&apos;WFL_PRJ_DEP2&apos;,&apos;WFL_PRJ_DEP1&apos;,&apos;PRJ_PREAPPLY_WFL&apos;)"/>
    </bm:data-filters>
    <bm:query-fields>
        <bm:query-field name="last_approve_date" queryExpression="t1.last_approve_date &gt; to_date(${@date},&apos;yyyy-MM-dd hh24:mi:ss&apos;)"/>
    </bm:query-fields>
</bm:model>
