Skip to content

Commit

Permalink
perf(#132): 1차 전형 자동 합격 시 동점자 처리
Browse files Browse the repository at this point in the history
- 입학요강에 따라 커트라인 점수를 저장해서, 이미 1차 정원이 다 찼더라도 동점자의 경우 추가로 합격을 시키도록 만들었어요.
- 전형별로 합격을 시키는 과정에서 똑같은 for 반복문이 너무 많이 사용되어서 함수형 인터페이스를 사용해서 메서드화 하여서 중복 코드를 줄였어요.
  • Loading branch information
cabbage16 committed Sep 26, 2024
1 parent 0f9a897 commit 7c6a88b
Showing 1 changed file with 25 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.transaction.annotation.Transactional;

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

@RequiredArgsConstructor
@UseCase
Expand All @@ -30,6 +31,8 @@ public void execute() {
List<Form> specialFormList = formRepository.findReceivedSpecialForm();
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);

if (meisterTalentFormList.size() < FixedNumber.MEISTER_TALENT) {
int gap = FixedNumber.MEISTER_TALENT - meisterTalentFormList.size();
Expand All @@ -55,58 +58,38 @@ public void execute() {
int equalOpportunityCount = (int) Math.round(socialIntegrationCount * 0.5);
int societyDiversityCount = equalOpportunityCount;


for (Form form : socialIntegrationFormList) {
if (form.getType().isEqualOpportunity() && equalOpportunityCount > 0) {
form.firstPass();
equalOpportunityCount--;
} else if (form.getType().isSocietyDiversity() && societyDiversityCount > 0) {
form.firstPass();
societyDiversityCount--;
} else {
changeToRegularAndCalculateGradeAgain(form);
}
}

for (Form form : meisterTalentFormList) {
if (meisterTalentCount > 0) {
form.firstPass();
meisterTalentCount--;
} else {
changeToRegularAndCalculateGradeAgain(form);
}
}
processForms(equalOpportunityFormList, equalOpportunityCount, this::changeToRegularAndCalculateGradeAgain);
processForms(societyDiversityFormList, societyDiversityCount, this::changeToRegularAndCalculateGradeAgain);
processForms(meisterTalentFormList, meisterTalentCount, this::changeToRegularAndCalculateGradeAgain);

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

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

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

processForms(nationalVeteransFormList, nationalVeteransEducationCount, Form::firstFail);
processForms(specialAdmissionFormList, specialAdmissionCount, Form::firstFail);
}

private void processForms(List<Form> formList, int count, Consumer<Form> action) {
if (formList.isEmpty())
return;

Double lastScore = formList.get(Math.min(count, formList.size())-1).getScore().getFirstRoundScore();

for (Form form : supernumeraryFormList) {
if (
form.getType().isNationalVeteransEducation() &&
nationalVeteransEducationCount > 0
) {
for (Form form: formList) {
if (count > 0) {
form.firstPass();
nationalVeteransEducationCount--;
} else if (
form.getType().isSpecialAdmission() &&
specialAdmissionCount > 0
) {
count--;
} else if (form.getScore().getFirstRoundScore().equals(lastScore)) {
form.firstPass();
specialAdmissionCount--;
} else {
form.firstFail();
action.accept(form);
}
}
}
Expand All @@ -122,7 +105,7 @@ private List<Form> classifyFormsByType(List<Form> formList, FormTypeFilter filte
}

private int calculateMultiple(int count) {
return (int) Math.round(count * FixedNumber.MULTIPLE);
return (int) Math.ceil(count * FixedNumber.MULTIPLE);
}
}

Expand Down

0 comments on commit 7c6a88b

Please sign in to comment.