From 2df4fe563260daf72146a32ff32ebfba9a7a865e Mon Sep 17 00:00:00 2001 From: saewoo1 Date: Fri, 25 Oct 2024 15:54:20 +0900 Subject: [PATCH] =?UTF-8?q?FEAT:=20=EC=97=AC=EB=9F=AC=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EB=8F=99=EC=9D=BC=ED=95=9C=20=EC=BD=94?= =?UTF-8?q?=EC=9D=B8=EC=9D=84=20=EC=A7=80=EA=B8=89=ED=95=98=EB=8A=94=20Bul?= =?UTF-8?q?k=20add=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cabinet/admin/item/service/AdminItemFacadeService.java | 4 +--- .../org/ftclub/cabinet/user/repository/UserRepository.java | 6 ++++++ .../org/ftclub/cabinet/user/service/UserCommandService.java | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java b/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java index be8d3960e..1726c01f5 100644 --- a/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java +++ b/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java @@ -67,9 +67,7 @@ public void assignItem(List userIds, Sku sku) { public void assignCoin(List userIds, Sku sku, Long amount) { Item item = itemQueryService.getBySku(sku); LocalDateTime now = LocalDateTime.now(); - userIds.forEach(userId -> { - userCommandService.updateCoinAmount(userId, amount); - }); + userCommandService.addBulkUserCoin(userIds, amount); itemHistoryCommandService.createCoinAssignHistory(userIds, item.getId(), now, amount); } diff --git a/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java b/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java index 0a384bb73..cd495bac0 100644 --- a/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java +++ b/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java @@ -140,4 +140,10 @@ public interface UserRepository extends JpaRepository { @Query("SELECT u FROM User u WHERE u.deletedAt IS NULL") List findAllDeletedAtIsNull(); + + @Modifying(clearAutomatically = true) + @Query("UPDATE User u " + + "SET u.coin = u.coin + :amount " + + "WHERE u.id IN :userIds") + void updateBulkUserCoin(@Param("userIds") List userIds, @Param("amount") Long amount); } diff --git a/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java b/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java index 994e9f7b8..54b1f545a 100644 --- a/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java +++ b/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java @@ -1,6 +1,7 @@ package org.ftclub.cabinet.user.service; import java.time.LocalDateTime; +import java.util.List; import javax.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.ftclub.cabinet.auth.domain.FtProfile; @@ -115,4 +116,8 @@ public void updateCoinAmount(Long userId, Long reward) { .orElseThrow(ExceptionStatus.NOT_FOUND_USER::asServiceException); user.addCoin(reward); } + + public void addBulkUserCoin(List userIds, Long amount) { + userRepository.updateBulkUserCoin(userIds, amount); + } }