<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018/7/6 8:17
    $Revision: 1.0 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[

               Select v.*
                  From (Select rank() over(Order By cc.contract_number Desc) rk,
                               cc.contract_id,
                               cc.contract_number,
                               (Select bp.bp_name
                                  From hls_bp_master bp
                                 Where bp.bp_id = cc.bp_id_tenant) bp_name,
                               to_char(cc.et_date, 'yyyy') Year,
                               to_char(cc.et_date, 'mm') Month,
                               to_char(cc.et_date, 'dd') Day,
                               to_char(Sysdate, 'yyyy') sys_year,
                               to_char(Sysdate, 'mm') sys_month,
                               to_char(Sysdate, 'dd') sys_day,
                               cci.full_name,
                               decode(cc.division,
                                      '00',
                                      '宏菱工程机械（中国）有限公司',
                                      '10',
                                      '宏菱工程机械（中国）有限公司',
                                      '01',
                                      '宏菱工程机械（中国）有限公司',
                                      '03',
                                      Null) manufacturer,
                               cci.pattern,
                               cci.machine_number,
                               Null As product_year,
                               '1台' As amount,
                               Null As detail,
                               (Select bp.bp_name
                                  From hls_bp_master bp
                                 Where bp.bp_id = cc.bp_id_agent_level1) agent_name
                          From con_contract cc, con_contract_lease_item cci
                         Where cc.contract_id = cci.contract_id
                           And cci.equipment_type = 'MAIN'
                           And cc.contract_id In (${:@contract_id})) v
                 Order By v.rk
]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                begin
                	update con_contract set
                		trans_cert_print_flag 		 = 'Y',
                		last_update_date = sysdate,
                		last_updated_by  = ${/session/@user_id}
                	where contract_id in (${:@contract_id});
                end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>