From bca5845aff2338448f89d2b007683559467cdf03 Mon Sep 17 00:00:00 2001 From: jeongchanmin Date: Sun, 29 Dec 2024 12:54:18 +0900 Subject: [PATCH] =?UTF-8?q?Chore=20:=20=ED=95=99=EC=8A=B5=20=EC=84=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80=20=EC=8B=9C=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20-=20=EA=B8=B0=EC=A1=B4=EC=97=90=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8D=98=20=ED=95=99=EC=8A=B5=20?= =?UTF-8?q?=EC=84=B8=ED=8A=B8=20=EB=B2=88=ED=98=B8=EC=9D=BC=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=B6=94=EA=B0=80=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=8C=20-=20=EA=B8=B0=EC=A1=B4=EC=97=90=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EB=8D=98=20=ED=95=99=EC=8A=B5=20=EC=84=B8?= =?UTF-8?q?=ED=8A=B8=EB=8A=94=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/LearningSetRepository.java | 3 +++ .../learning/service/LearningAdminService.java | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ripple/BE/learning/repository/LearningSetRepository.java b/src/main/java/com/ripple/BE/learning/repository/LearningSetRepository.java index 9db3c75..92e30d6 100644 --- a/src/main/java/com/ripple/BE/learning/repository/LearningSetRepository.java +++ b/src/main/java/com/ripple/BE/learning/repository/LearningSetRepository.java @@ -13,4 +13,7 @@ public interface LearningSetRepository extends JpaRepository @Query("SELECT l.id FROM LearningSet l WHERE l.level = :level") List findIdsByLevel(@Param("level") Level level); + + @Query("SELECT ls.learningSetNum FROM LearningSet ls") + List findAllLearningSetNums(); } diff --git a/src/main/java/com/ripple/BE/learning/service/LearningAdminService.java b/src/main/java/com/ripple/BE/learning/service/LearningAdminService.java index d089ac2..a6e8b5a 100644 --- a/src/main/java/com/ripple/BE/learning/service/LearningAdminService.java +++ b/src/main/java/com/ripple/BE/learning/service/LearningAdminService.java @@ -36,19 +36,28 @@ public class LearningAdminService { @Transactional public void createLearningSetByExcel() { try { + List learningSetList = parseLearningSetsFromExcel(); Map learningSetMap = learningSetList.stream() .collect( Collectors.toMap(LearningSet::getLearningSetNum, learningSet -> learningSet)); + // 기존에 존재하는 LearningSetNum 조회 + List existingLearningSetNums = learningSetRepository.findAllLearningSetNums(); + + // 새로운 학습 세트만 필터링 + List newLearningSets = + learningSetList.stream() + .filter( + learningSet -> !existingLearningSetNums.contains(learningSet.getLearningSetNum())) + .collect(Collectors.toList()); + addConceptsToLearningSets(learningSetMap); addQuizzesToLearningSets(learningSetMap); - learningSetRepository.saveAll(learningSetList); - - // 모든 사용자에게 학습 세트를 배포 - learningSetCompleteEventListener.handleLearningSetCompleteEvent(learningSetList); + learningSetRepository.saveAll(newLearningSets); + learningSetCompleteEventListener.handleLearningSetCompleteEvent(newLearningSets); } catch (Exception e) { log.error("Failed to save learning set by excel", e);