update c_account
set balance = balance + #{amount}
,before_day_time = CURRENT_DATE
,before_day_init_balance = before_day_balance
,before_day_balance = balance
,total_in_amount = total_in_amount + CASE
WHEN #{amount} > 0 THEN #{amount}
ELSE 0
END,
total_out_amount = total_out_amount + CASE
WHEN 0 > #{amount} THEN -#{amount}
ELSE 0
END
where id = #{accountId}
and balance + #{amount} >= 0
and DATE_FORMAT( before_day_time, '%Y-%m-%d' ) != CURRENT_DATE
UPDATE c_account
SET balance = balance + #{amount},
total_in_amount = total_in_amount + CASE
WHEN #{amount} > 0 THEN #{amount}
ELSE 0
END,
total_out_amount = total_out_amount + CASE
WHEN 0 > #{amount} THEN -#{amount}
ELSE 0
END
WHERE id = #{accountId}
AND balance + #{amount} >= 0
AND 1=1
update c_account set freeze_amount = freeze_amount + #{amount} where id = #{accountId} and freeze_amount + #{amount} >= 0