From 3bee34937645f332cd1f48a72db2ae9dc310b6ea Mon Sep 17 00:00:00 2001 From: jun02160 Date: Thu, 11 Apr 2024 00:36:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20bugfix:=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=EC=9D=98=20=EB=AF=B8=EC=85=98=20insert=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=A7=81=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?#155?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../motivoo/batch/service/scheduler/UserMissionScheduler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/motivoo-batch/src/main/java/sopt/org/motivoo/batch/service/scheduler/UserMissionScheduler.java b/motivoo-batch/src/main/java/sopt/org/motivoo/batch/service/scheduler/UserMissionScheduler.java index 0f8ac80c..cf6f9b8f 100644 --- a/motivoo-batch/src/main/java/sopt/org/motivoo/batch/service/scheduler/UserMissionScheduler.java +++ b/motivoo-batch/src/main/java/sopt/org/motivoo/batch/service/scheduler/UserMissionScheduler.java @@ -107,11 +107,13 @@ public void setCompletedStatus() { // @Scheduled(cron = "* */2 * * * *", zone = "Asia/Seoul") public void insertEmptyUserMission() { List users = userRetriever.findAll().stream() - .filter(user -> !user.isDeleted()).toList(); + .filter(user -> !user.isDeleted()) + .filter(user -> user.getParentchild().isMatched()).toList(); Mission emptyMission = missionRetriever.getEmptyMission(); MissionQuest missionQuest = missionQuestRetriever.getRandomMissionQuest(); userMissionRetriever.bulkSaveInitUserMission(users, LocalDate.now(), emptyMission, missionQuest); + log.info("User {} 명의 오늘의 미션 insert 성공", users.size()); } From 7cad548d66634bc7d859c909971bc6c5b642367b Mon Sep 17 00:00:00 2001 From: jun02160 Date: Thu, 11 Apr 2024 00:38:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A7=20chore:=20insert=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=EC=8B=9C=20=EC=8A=AC=EB=9E=99=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=EC=9D=84=20=EB=B0=9B=EC=9D=84=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20#155?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/UserMissionJdbcRepository.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/motivoo-domain/src/main/java/sopt/org/motivoo/domain/mission/repository/UserMissionJdbcRepository.java b/motivoo-domain/src/main/java/sopt/org/motivoo/domain/mission/repository/UserMissionJdbcRepository.java index f79c5ef9..add01a8f 100644 --- a/motivoo-domain/src/main/java/sopt/org/motivoo/domain/mission/repository/UserMissionJdbcRepository.java +++ b/motivoo-domain/src/main/java/sopt/org/motivoo/domain/mission/repository/UserMissionJdbcRepository.java @@ -6,6 +6,7 @@ import java.time.LocalDate; import java.util.List; +import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -15,7 +16,6 @@ import sopt.org.motivoo.domain.mission.entity.CompletedStatus; import sopt.org.motivoo.domain.mission.entity.Mission; import sopt.org.motivoo.domain.mission.entity.MissionQuest; -import sopt.org.motivoo.domain.mission.entity.UserMission; import sopt.org.motivoo.domain.user.entity.User; @Repository @@ -33,22 +33,26 @@ public void bulkSave(List users, LocalDate date, Mission mission, MissionQ private void batchInsert(int batchSize, List users, LocalDate date, Mission mission, MissionQuest quest) { String sql = "INSERT INTO user_mission (completed_status, created_at, updated_at, mission_id, mission_quest_mission_quest_id, user_id) values (?, ?, ?, ?, ?, ?)"; - jdbcTemplate.batchUpdate(sql, - new BatchPreparedStatementSetter() { - @Override - public void setValues(PreparedStatement ps, int i) throws SQLException { - ps.setString(1, CompletedStatus.NONE.toString()); - ps.setDate(2, Date.valueOf(date)); - ps.setDate(3, Date.valueOf(date)); - ps.setLong(4, mission.getId()); - ps.setLong(5, quest.getId()); - ps.setLong(6, users.get(i).getId()); - } - - @Override - public int getBatchSize() { - return users.size(); - } - }); + try { + jdbcTemplate.batchUpdate(sql, + new BatchPreparedStatementSetter() { + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + ps.setString(1, CompletedStatus.NONE.toString()); + ps.setDate(2, Date.valueOf(date)); + ps.setDate(3, Date.valueOf(date)); + ps.setLong(4, mission.getId()); + ps.setLong(5, quest.getId()); + ps.setLong(6, users.get(i).getId()); + } + + @Override + public int getBatchSize() { + return users.size(); + } + }); + } catch (final DataAccessException e) { + throw new IllegalStateException(e); + } } }