Skip to content

Commit

Permalink
Merge pull request #156 from Team-Motivoo/fix/#155-user_mission_empty
Browse files Browse the repository at this point in the history
[FIX] Empty UserMission 관련 버그 해결
  • Loading branch information
jun02160 authored Apr 10, 2024
2 parents 0872fa8 + 7cad548 commit f51a4ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ public void setCompletedStatus() {
// @Scheduled(cron = "* */2 * * * *", zone = "Asia/Seoul")
public void insertEmptyUserMission() {
List<User> 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());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -33,22 +33,26 @@ public void bulkSave(List<User> users, LocalDate date, Mission mission, MissionQ
private void batchInsert(int batchSize, List<User> 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);
}
}
}

0 comments on commit f51a4ed

Please sign in to comment.