<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zc
    $Date: 2020年11月20日
    $Revision: 1.0
    $Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="contract_id"/>
        <bm:field name="ele_flow_id"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                 select * from (select c.contract_id, c.ele_flow_id
                  from con_contract c
                 where c.sign_type = 'ELE_SIGN'
                   and nvl(c.ele_file_dl_flag,'N') = 'N'
                   and c.data_class = 'NORMAL'
                   and c.flow_status = 2
                union all
                select cr.contract_id, cr.ele_flow_id
                  from con_contract_change_req cr
                 where cr.sign_type = 'ELE_SIGN'
                   and nvl(cr.ele_file_dl_flag, 'N') = 'N'
                   and cr.flow_status = 2) t1
                 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                  wx_ele_contract_pkg.init_con_atm(p_contract_id => ${@contract_id},
                                                   p_file_path   => ${@file_url},
                                                   p_file_name   => ${@file_name},
                                                   p_file_length => ${@file_size},
                                                   p_user_id     => nvl(${/session/@user_id},1));
                   COMMIT;
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                BEGIN
                    update con_contract c
                       set c.ele_file_dl_flag = 'Y'
                     where c.ele_flow_id =${@flow_id}
                       and c.contract_id =${@contract_id};

                    update con_contract_change_req cr
                       set cr.ele_file_dl_flag = 'Y'
                     where cr.ele_flow_id =${@flow_id}
                       and cr.contract_id =${@contract_id};
                   COMMIT;
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="contract_id" queryOperator="="/>
        <bm:query-field field="ele_flow_id" queryOperator="="/>
    </bm:query-fields>
</bm:model>
