<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                 UPDATE con_contract_ele_signer cs
                    SET cs.ec_sign_status   = 'Y',
                        cs.sign_time = to_date(${@sign_time},'yyyy-mm-dd HH24:MI:SS'),
                        cs.sign_result = ${@sign_result},
                        cs.last_update_date = sysdate
                  WHERE cs.contract_id = ${@contract_id}
                    AND cs.id_no = ${@id_no}
                    AND cs.esign_type = 'ET';

                   update con_contract_change_req cc
                      set cc.ec_sign_type     = 'SIGNING',
                          cc.last_update_date = sysdate
                    where cc.ele_flow_id = ${@flow_id}
                      and cc.ec_sign_type != 'SIGNED';
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                BEGIN
                   update con_contract_change_req cc
                      set cc.ec_sign_type     = 'SIGNED',
                          cc.flow_status = ${@flow_status},
                          cc.end_time = to_date(${@end_time},'yyyy-mm-dd HH24:MI:SS'),
                          cc.last_update_date = sysdate
                    where cc.ele_flow_id = ${@flow_id}
                      and cc.contract_id = ${@contract_id};

                   update con_contract_ele_signer cs
                      set cs.ec_sign_status = 'Y',
                          cs.last_update_date = sysdate
                    where cs.contract_id = ${@contract_id};

                   wx_ele_contract_pkg.downloadEleFile(p_contract_id => ${@contract_id},
                                                       p_ele_flow_id => ${@flow_id},
                                                       p_user_id     => 1,
                                                       p_company_id  => 1);
                  COMMIT;
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
