diff --git a/src/main/java/com/yn/bftl/thirdparty/common/repository/AccountRepository.java b/src/main/java/com/yn/bftl/thirdparty/common/repository/AccountRepository.java index b416ba6..8e64913 100644 --- a/src/main/java/com/yn/bftl/thirdparty/common/repository/AccountRepository.java +++ b/src/main/java/com/yn/bftl/thirdparty/common/repository/AccountRepository.java @@ -32,4 +32,9 @@ @Transactional @Query("UPDATE Account account SET account.balance = account.balance + :amount where account.company = :companyId and account.type = 'DEPOSIT' and account.state = 'ENABLED'") int plusBalanceForCompany(@Param("amount") BigDecimal amount, @Param("companyId") Long companyId); + + @Modifying + @Transactional + @Query("UPDATE Account account SET account.balance = account.balance - :amount where account.balance >= :amount and account.company = :companyId and account.type = 'DEPOSIT' and account.state = 'ENABLED'") + int subBalanceForCompany(@Param("amount") BigDecimal amount, @Param("companyId") Long companyId); }