insert into pay_payment ( payment_no, supplier_id, supplier_name, currency, pay_date, pay_method, bank_account, amount, bank_fee, exchange_rate, status, remark, create_by, create_time ) values ( #{paymentNo}, #{supplierId}, #{supplierName}, #{currency}, #{payDate}, #{payMethod}, #{bankAccount}, #{amount}, #{bankFee}, ifnull(#{exchangeRate}, 1), 'DRAFT', #{remark}, #{createBy}, sysdate() ) insert into pay_payment_alloc (payment_id, bill_id, alloc_amount, alloc_status) values (#{paymentId}, #{billId}, #{allocAmount}, 'ACTIVE') update pay_payment set status = #{status}, confirm_by = #{confirmBy}, confirm_time = #{confirmTime}, exchange_rate = ifnull(#{exchangeRate}, exchange_rate), base_amount = ifnull(#{baseAmount}, base_amount), alloc_amount = ifnull(#{allocAmount}, alloc_amount) where payment_id = #{paymentId} update pay_payment_alloc set alloc_status = 'REVERSED', reverse_by = #{reverseBy}, reverse_time = sysdate() where alloc_id = #{allocId} and alloc_status = 'ACTIVE'