diff --git a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java index 8b532f04..d1b85b95 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java +++ b/eeos/src/main/java/com/blackcompany/eeos/target/application/util/PresentationInitializer.java @@ -9,10 +9,12 @@ import com.blackcompany.eeos.team.persistence.TeamRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -27,6 +29,9 @@ public class PresentationInitializer implements ApplicationRunner { private final ProgramRepository programRepository; private final TeamRepository teamRepository; + @Value("${eeos.team.list}") + private String teamList; + @Override public void run(ApplicationArguments args) throws Exception { System.out.println("------------Presentation Initializer----------"); @@ -34,33 +39,53 @@ public void run(ApplicationArguments args) throws Exception { if(programs.isEmpty()) return; - Set presentations = getPresentations().stream().map(PresentationEntity::getProgramId).collect(Collectors.toSet()); + Set presentations = getPresentations().stream() + .map(PresentationEntity::getProgramId) + .collect(Collectors.toSet()); - Set target = programs.stream().filter(programId -> !presentations.contains(programId)).collect(Collectors.toSet()); + Set target = programs.stream() + .filter(programId -> !presentations.contains(programId)) + .collect(Collectors.toSet()); - Long defaultTeamId = getTempTeam().getId(); + List teams= getTeams().stream() + .map(TeamEntity::getId) + .toList(); - Set entities = target.stream().map(targetId -> PresentationEntity.builder().teamId(defaultTeamId).programId(targetId).build()).collect(Collectors.toSet()); + target.stream().forEach(targetId -> + { + Set entities = + teams.stream() + .map(teamId -> PresentationEntity.builder() + .teamId(teamId) + .programId(targetId) + .build()) + .collect(Collectors.toSet()); + presentationRepository.saveAll(entities); + }); - presentationRepository.saveAll(entities); System.out.println("----------------------------------------------"); } + private List getTeamList(){ + return Arrays.stream(teamList.split(",")).toList(); + } + private List getPrograms(){ return programRepository.findAll(); } - private TeamEntity getTempTeam(){ + private List getTeams(){ + List teams = getTeamList(); try { - return teamRepository.findTeamEntityByName("임시 활동 팀").stream().findFirst().orElseThrow(()->new NotFoundTeamException(0L)); + return teamRepository.findAllTeams().stream().filter(team -> teams.contains(team.getName())).toList(); } catch (NotFoundTeamException e){ - return createTempTeam(); + return createTeams(); } } - private TeamEntity createTempTeam(){ - TeamEntity newTeam = TeamEntity.builder().name("임시 활동 팀").status(false).build(); - return teamRepository.save(newTeam); + private List createTeams(){ + Set teams = getTeamList().stream().map(team -> TeamEntity.builder().name(team).status(false).build()).collect(Collectors.toSet()); + return teamRepository.saveAll(teams); } private List getPresentations(){ diff --git a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java b/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java index 0cca5ff3..f905c19e 100644 --- a/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java +++ b/eeos/src/main/java/com/blackcompany/eeos/team/application/util/TeamInitializer.java @@ -4,10 +4,15 @@ import com.blackcompany.eeos.team.persistence.TeamRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + // 기존 데이터베이스와의 데이터 정합성을 위한 클래스 @RequiredArgsConstructor @@ -17,12 +22,18 @@ public class TeamInitializer implements ApplicationRunner { private final TeamRepository teamRepository; + @Value("${eeos.team.list}") + private String teamList; + @Override public void run(ApplicationArguments args) throws Exception { System.out.println("-----------Team Initializer-----------"); + Arrays.stream(teamList.split(",")).forEach(log::info); try { - TeamEntity defaultTeam = TeamEntity.builder().id(0L).name("임시 활동 팀").status(false).build(); - teamRepository.save(defaultTeam); + Set newTeams = Arrays.stream(teamList.split(",")) + .map(teamName -> TeamEntity.builder().name(teamName).status(false).build()) + .collect(Collectors.toSet()); + teamRepository.saveAll(newTeams); log.info("임시 팀이 생성되었습니다."); } catch (Exception e){ log.error("임시 팀이 생성되지 않았습니다."); diff --git a/eeos/src/main/resources/application-admin.yml b/eeos/src/main/resources/application-admin.yml index a7eb34ad..a316033e 100644 --- a/eeos/src/main/resources/application-admin.yml +++ b/eeos/src/main/resources/application-admin.yml @@ -7,4 +7,13 @@ eeos: admin: name : ${ADMIN_NAME} loginId : ${ADMIN_LOGIN_ID} - password: ${ADMIN_PASSWORD} \ No newline at end of file + password: ${ADMIN_PASSWORD} + team: + list: ${ECONOVATION_TEAM_LIST} + +server: + servlet: + encoding: + charset: UTF-8 + enabled: true + force: true \ No newline at end of file diff --git a/eeos/src/main/resources/application-mysql.yml b/eeos/src/main/resources/application-mysql.yml index 5a1622de..34ed5a50 100644 --- a/eeos/src/main/resources/application-mysql.yml +++ b/eeos/src/main/resources/application-mysql.yml @@ -12,6 +12,9 @@ spring: ddl-auto: validate generate-ddl: true open-in-view: false + properties: + hibernate: + dialect: org.hibernate.dialect.MySQL8Dialect flyway: baseline-on-migrate: true enabled: true