Skip to content

Commit

Permalink
perf(#132): 2차 전형 합격 처리 로직 중복 코드 처리
Browse files Browse the repository at this point in the history
- 전형별로 합격을 시키는 과정에서 똑같은 for 반복문이 너무 많이 사용되어서 함수형 인터페이스를 사용해서 메서드화 하여서 중복 코드를 줄였어요.
- 특별전형 인원 미달 시 일반전형 지원자로 충원하는 로직을 SelectFirstPassUseCase처럼 수정했어요.
  • Loading branch information
cabbage16 committed Sep 26, 2024
1 parent 91a50b2 commit dc370f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.shared.annotation.UseCase;
import com.bamdoliro.maru.shared.constants.FixedNumber;
import com.bamdoliro.maru.shared.variable.AdmissionCapacity;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -38,16 +37,12 @@ public void execute() {
int gap = FixedNumber.MEISTER_TALENT - meisterTalentFormList.size();
regularCount += gap;
meisterTalentCount -= gap;
AdmissionCapacity.regular += gap;
AdmissionCapacity.meisterTalent -= gap;
}

if (socialIntegrationFormList.size() < FixedNumber.SOCIAL_INTEGRATION) {
int gap = FixedNumber.SOCIAL_INTEGRATION - socialIntegrationFormList.size();
regularCount += gap;
socialIntegrationCount -= gap;
AdmissionCapacity.regular += gap;
AdmissionCapacity.socialIntegration -= gap;
}

regularCount = calculateMultiple(regularCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.shared.annotation.UseCase;
import com.bamdoliro.maru.shared.constants.FixedNumber;
import com.bamdoliro.maru.shared.variable.AdmissionCapacity;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.function.Consumer;

@RequiredArgsConstructor
@UseCase
Expand All @@ -25,63 +25,58 @@ public class SelectSecondPassUseCase {
public void execute() {
validate();

int regularCount = AdmissionCapacity.regular;
int meisterTalentCount = AdmissionCapacity.meisterTalent;
int socialIntegrationCount = AdmissionCapacity.socialIntegration;
int regularCount = FixedNumber.REGULAR;
int meisterTalentCount = FixedNumber.MEISTER_TALENT;
int socialIntegrationCount = FixedNumber.SOCIAL_INTEGRATION;
int nationalVeteransEducationCount = FixedNumber.NATIONAL_VETERANS_EDUCATION;
int specialAdmissionCount = FixedNumber.SPECIAL_ADMISSION;
int equalOpportunityCount = (int) Math.round(socialIntegrationCount * 0.5);
int societyDiversityCount = equalOpportunityCount;

List<Form> specialFormList = formRepository.findFirstPassedSpecialForm();
List<Form> meisterTalentFormList = classifyFormsByType(specialFormList, FormType::isMeister);
List<Form> socialIntegrationFormList = classifyFormsByType(specialFormList, FormType::isSocial);
List<Form> equalOpportunityFormList = classifyFormsByType(specialFormList, FormType::isEqualOpportunity);
List<Form> societyDiversityFormList = classifyFormsByType(specialFormList, FormType::isSocietyDiversity);

for (Form form : socialIntegrationFormList) {
if (form.getType().isEqualOpportunity() && equalOpportunityCount > 0) {
form.pass();
equalOpportunityCount--;
} else if (form.getType().isSocietyDiversity() && societyDiversityCount > 0) {
form.pass();
societyDiversityCount--;
} else {
changeToRegularAndCalculateScoreAgain(form);
}
if (meisterTalentFormList.size() < FixedNumber.MEISTER_TALENT) {
int gap = FixedNumber.MEISTER_TALENT - meisterTalentFormList.size();
regularCount += gap;
meisterTalentCount -= gap;
}

for (Form form : meisterTalentFormList) {
if (meisterTalentCount > 0) {
form.pass();
meisterTalentCount--;
} else {
changeToRegularAndCalculateScoreAgain(form);
}
if (socialIntegrationFormList.size() < FixedNumber.SOCIAL_INTEGRATION) {
int gap = FixedNumber.SOCIAL_INTEGRATION - socialIntegrationFormList.size();
regularCount += gap;
socialIntegrationCount -= gap;
}

int equalOpportunityCount = (int) Math.round(socialIntegrationCount * 0.5);
int societyDiversityCount = equalOpportunityCount;

processForms(equalOpportunityFormList, equalOpportunityCount, this::changeToRegularAndCalculateScoreAgain);
processForms(societyDiversityFormList, societyDiversityCount, this::changeToRegularAndCalculateScoreAgain);
processForms(meisterTalentFormList, meisterTalentCount, this::changeToRegularAndCalculateScoreAgain);

formRepository.flush();
List<Form> regularFormList = formRepository.findFirstPassedRegularForm();

for (Form form : regularFormList) {
if (regularCount > 0) {
form.pass();
regularCount--;
} else {
form.fail();
}
}
processForms(regularFormList, regularCount, Form::fail);

formRepository.flush();
List<Form> supernumeraryFormList = formRepository.findFirstPassedSupernumeraryForm();
List<Form> nationalVeteransEducationFormList = classifyFormsByType(supernumeraryFormList, FormType::isNationalVeteransEducation);
List<Form> specialAdmissionFormList = classifyFormsByType(supernumeraryFormList, FormType::isSpecialAdmission);

for (Form form : supernumeraryFormList) {
if (form.getType().isNationalVeteransEducation() && nationalVeteransEducationCount > 0) {
form.pass();
nationalVeteransEducationCount--;
} else if (form.getType().isSpecialAdmission() && specialAdmissionCount > 0) {
processForms(nationalVeteransEducationFormList, nationalVeteransEducationCount, Form::fail);
processForms(specialAdmissionFormList, specialAdmissionCount, Form::fail);
}

private void processForms(List<Form> formList, int count, Consumer<Form> action) {
for (Form form: formList) {
if (count > 0) {
form.pass();
specialAdmissionCount--;
count--;
} else {
form.fail();
action.accept(form);
}
}
}
Expand Down

This file was deleted.

0 comments on commit dc370f9

Please sign in to comment.