Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 팀 매핑이 되지 않은 행사들을 이전 학기 활동 팀으로 매핑 #165

Merged
merged 15 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,40 +29,63 @@ 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----------");
Set<Long> programs = getPrograms().stream().map(ProgramEntity::getId).collect(Collectors.toSet());

if(programs.isEmpty()) return;

Set<Long> presentations = getPresentations().stream().map(PresentationEntity::getProgramId).collect(Collectors.toSet());
Set<Long> presentations = getPresentations().stream()
.map(PresentationEntity::getProgramId)
.collect(Collectors.toSet());

Set<Long> target = programs.stream().filter(programId -> !presentations.contains(programId)).collect(Collectors.toSet());
Set<Long> target = programs.stream()
.filter(programId -> !presentations.contains(programId))
.collect(Collectors.toSet());

Long defaultTeamId = getTempTeam().getId();
List<Long> teams= getTeams().stream()
.map(TeamEntity::getId)
.toList();

Set<PresentationEntity> entities = target.stream().map(targetId -> PresentationEntity.builder().teamId(defaultTeamId).programId(targetId).build()).collect(Collectors.toSet());
target.stream().forEach(targetId ->
{
Set<PresentationEntity> 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<String> getTeamList(){
return Arrays.stream(teamList.split(",")).toList();
}

private List<ProgramEntity> getPrograms(){
return programRepository.findAll();
}

private TeamEntity getTempTeam(){
private List<TeamEntity> getTeams(){
List<String> 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<TeamEntity> createTeams(){
Set<TeamEntity> teams = getTeamList().stream().map(team -> TeamEntity.builder().name(team).status(false).build()).collect(Collectors.toSet());
return teamRepository.saveAll(teams);
}

private List<PresentationEntity> getPresentations(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<TeamEntity> 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("임시 팀이 생성되지 않았습니다.");
Expand Down
11 changes: 10 additions & 1 deletion eeos/src/main/resources/application-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ eeos:
admin:
name : ${ADMIN_NAME}
loginId : ${ADMIN_LOGIN_ID}
password: ${ADMIN_PASSWORD}
password: ${ADMIN_PASSWORD}
team:
list: ${ECONOVATION_TEAM_LIST}

server:
servlet:
encoding:
charset: UTF-8
enabled: true
force: true
3 changes: 3 additions & 0 deletions eeos/src/main/resources/application-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading