Skip to content

Commit

Permalink
feat(#68): grade table for not examination qulification
Browse files Browse the repository at this point in the history
  • Loading branch information
gimhanul committed Sep 4, 2023
1 parent 7f44353 commit a1df5ac
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.bamdoliro.maru.application.form;

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.domain.form.domain.type.AchievementLevel;
import com.bamdoliro.maru.domain.form.domain.value.Subject;
import com.bamdoliro.maru.domain.form.domain.value.SubjectMap;
import com.bamdoliro.maru.domain.form.exception.FormAlreadySubmittedException;
import com.bamdoliro.maru.domain.form.service.FormFacade;
Expand All @@ -10,18 +11,26 @@
import com.bamdoliro.maru.infrastructure.pdf.MergePdfService;
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService;
import com.bamdoliro.maru.infrastructure.thymeleaf.Templates;
import com.bamdoliro.maru.presentation.form.dto.request.SubjectRequest;
import com.bamdoliro.maru.shared.annotation.UseCase;
import com.bamdoliro.maru.shared.constants.Schedule;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.utils.PdfMerger;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ByteArrayResource;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@RequiredArgsConstructor
@UseCase
public class ExportFormUseCase {
Expand All @@ -41,6 +50,7 @@ public ByteArrayResource execute(User user) {
"grade21", subjectMap.getSubjectListOf(2, 1),
"grade22", subjectMap.getSubjectListOf(2, 2),
"grade31", subjectMap.getSubjectListOf(3, 1),
"achievementLevelBySubject", achievementLevelBySubject(form),
"year", Schedule.getAdmissionYear()
);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand All @@ -59,6 +69,29 @@ public ByteArrayResource execute(User user) {
return new ByteArrayResource(outputStream.toByteArray());
}

private List<SubjectVO> achievementLevelBySubject(Form form) {
List<SubjectVO> value = new ArrayList<>();
Map<String, List<Subject>> subjectMap = form.getGrade()
.getSubjectListValue()
.stream()
.collect(Collectors.groupingBy(Subject::getSubjectName));

subjectMap.forEach((key, values) -> {
SubjectVO subject = new SubjectVO(key);
values.forEach(v -> {
try {
SubjectVO.class.getField("achievementLevel" + v.toString())
.set(subject, v.getAchievementLevel());
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
});
value.add(subject);
});

return value;
}

private void validateFormStatus(Form form) {
if (!(form.isSubmitted() || form.isRejected())) {
throw new FormAlreadySubmittedException();
Expand All @@ -84,3 +117,19 @@ private List<String> getRequiredTemplates(Form form) {
);
}
}

@Getter
class SubjectVO {

private String subjectName;

public AchievementLevel achievementLevel21;

public AchievementLevel achievementLevel22;

public AchievementLevel achievementLevel31;

public SubjectVO(String subjectName) {
this.subjectName = subjectName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
@Getter
@RequiredArgsConstructor
public enum AchievementLevel implements EnumProperty {
A("A", 5),
B("B", 4),
C("C", 3),
D("D", 2),
E("E", 1);
A("A", 5, "수", "우수"),
B("B", 4, "우", "보통"),
C("C", 3, "미", "미흡"),
D("D", 2, "양", null),
E("E", 1, "가", null);

private final String description;
private final int score;
private final String korean;
private final String korean3step;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ public Integer getCount() {
public String toString() {
return String.format("%d%d", grade, semester);
}

public String achievementLevelToString() {
if (subjectName.equals("음악") ||
subjectName.equals("미술") ||
subjectName.equals("체육")
) {
return String.format("%s/%s", achievementLevel.name(), achievementLevel.getKorean3step());
}

return String.format("%s/%s", achievementLevel.name(), achievementLevel.getKorean());
}
}
84 changes: 77 additions & 7 deletions src/main/resources/templates/grade-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
<th class="ba">인적사항</th>
<td class="ba" th:text='${"검정, "+form.applicant.name}'></td>
<th class="ba">생년월일</th>
<td class="ba"th:text="${#temporals.format(form.applicant.birthday, 'YYYY년 MM월 dd일')}"></td>
<td class="ba" th:text="${#temporals.format(form.applicant.birthday, 'YYYY년 MM월 dd일')}"></td>
</tr>
</table>
<table>
<table th:if="${form.education.isQualificationExamination()}">
<caption th:text='${"1. 교과성적 - " + form.score.subjectGradeScore + "점"}'></caption>
<tr>
<th class="ba">과목</th>
Expand All @@ -104,36 +104,106 @@
<td class="ba">92</td>
</tr>
</table>
<table>
<table th:unless="${form.education.isQualificationExamination()}">
<caption th:text='${"1. 교과성적 - " + form.score.subjectGradeScore + "점"}'></caption>
<tr>
<th rowspan="2" class="ba">과목</th>
<th class="ba">2학년 1학기</th>
<th class="ba">2학년 2학기</th>
<th class="ba">3학년 1학기</th>
</tr>
<tr>
<th class="ba">성취수준</th>
<th class="ba">성취수준</th>
<th class="ba">성취수준</th>
</tr>
<tr th:each="subject : ${achievementLevelBySubject}">
<td class="ba" th:text="${subject.subjectName}"></td>
<td class="ba disabled" th:if="${subject.achievementLevel21 == null}"></td>
<td class="ba" th:unless="${subject.achievementLevel21 == null}" th:text="${subject.achievementLevel21}"></td>
<td class="ba disabled" th:if="${subject.achievementLevel22 == null}"></td>
<td class="ba" th:unless="${subject.achievementLevel22 == null}" th:text="${subject.achievementLevel22}"></td>
<td class="ba disabled" th:if="${subject.achievementLevel31 == null}"></td>
<td class="ba" th:unless="${subject.achievementLevel31 == null}" th:text="${subject.achievementLevel31}"></td>
</tr>
</table>
<table th:if="${form.education.isQualificationExamination()}">
<caption th:text='${"2. 출결 상황 - " + form.score.attendanceScore + "점"}'></caption>
<tr>
<th class="ba">출결</th>
<th class="ba">부여점수</th>
</tr>
<tr th:if="${form.education.isQualificationExamination()}">
<tr>
<th class="ba">출결내역</th>
<td class="ba">14점(기본점수)</td>
</tr>
</table>
<table>
<table th:unless="${form.education.isQualificationExamination()}">
<caption th:text='${"2. 출결 상황 - " + form.score.attendanceScore + "점"}'></caption>
<tr>
<th class="ba" colspan="4">1학년</th>
<th class="ba" colspan="4">2학년</th>
<th class="ba" colspan="4">3학년</th>
</tr>
<tr>
<th class="ba">미인정<br/>결석</th><th class="ba">미인정<br/>지각</th><th class="ba">미인정<br/>조퇴</th><th class="ba">미인정<br/>결과</th>
<th class="ba">미인정<br/>결석</th><th class="ba">미인정<br/>지각</th><th class="ba">미인정<br/>조퇴</th><th class="ba">미인정<br/>결과</th>
<th class="ba">미인정<br/>결석</th><th class="ba">미인정<br/>지각</th><th class="ba">미인정<br/>조퇴</th><th class="ba">미인정<br/>결과</th>
</tr>
<tr>
<td class="ba" th:text="${form.grade.attendance1.absenceCount}"></td>
<td class="ba" th:text="${form.grade.attendance1.latenessCount}"></td>
<td class="ba" th:text="${form.grade.attendance1.earlyLeaveCount}"></td>
<td class="ba" th:text="${form.grade.attendance1.classAbsenceCount}"></td>
<td class="ba" th:text="${form.grade.attendance2.absenceCount}"></td>
<td class="ba" th:text="${form.grade.attendance2.latenessCount}"></td>
<td class="ba" th:text="${form.grade.attendance2.earlyLeaveCount}"></td>
<td class="ba" th:text="${form.grade.attendance2.classAbsenceCount}"></td>
<td class="ba" th:text="${form.grade.attendance3.absenceCount}"></td>
<td class="ba" th:text="${form.grade.attendance3.latenessCount}"></td>
<td class="ba" th:text="${form.grade.attendance3.earlyLeaveCount}"></td>
<td class="ba" th:text="${form.grade.attendance3.classAbsenceCount}"></td>
</tr>
</table>
<table th:if="${form.education.isQualificationExamination()}">
<caption th:text='${"3. 봉사활동 - " + form.score.volunteerScore + "점"}'></caption>
<tr>
<th class="ba">봉사활동</th>
<th class="ba">부여점수</th>
</tr>
<tr th:if="${form.education.isQualificationExamination()}">
<tr>
<th class="ba">봉사내역</th>
<td class="ba">14점(기본점수)</td>
</tr>
</table>
<table th:unless="${form.education.isQualificationExamination()}">
<caption th:text='${"3. 봉사활동 - " + form.score.volunteerScore + "점"}'></caption>
<tr>
<th class="ba" style="width: 20%">학년</th>
<th class="ba">봉사활동시간수</th>
</tr>
<tr>
<td class="ba">1학년</td>
<td class="ba" th:text="${form.grade.volunteerTime1}"></td>
</tr>
<tr>
<td class="ba">2학년</td>
<td class="ba" th:text="${form.grade.volunteerTime2}"></td>
</tr>
<tr>
<td class="ba">3학년</td>
<td class="ba" th:text="${form.grade.volunteerTime3}"></td>
</tr>
</table>
<table>
<caption th:text='${"4. 가산점 - " + form.score.bonusScore + "점"}'></caption>
<tr>
<th class="ba">자격증명</th>
</tr>
<tr>
<td class="ba disabled" th:if="${form.score.bonusScore == 0}">-</td>
<td class="ba" th:unless="${form.score.bonusScore == 0}" th:text="${form.grade.certificateList.toString()}"></td>
<td class="ba" th:unless="${form.score.bonusScore == 0}"
th:text="${form.grade.certificateList.toString()}"></td>
</tr>
</table>
<table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static Form createRandomForm(User user) {
)
),
new Education(
GraduationType.QUALIFICATION_EXAMINATION,
GraduationType.EXPECTED,
"2021",
new School("비전중학교", "경기도", "7631003"),
new Teacher("나교사", new PhoneNumber("0519701234"), new PhoneNumber("01012344321"))
Expand All @@ -156,16 +156,16 @@ public static Form createRandomForm(User user) {
new Subject(3, 1, "사회", randomAchievementLevel()),
new Subject(3, 1, "과학", randomAchievementLevel()),
new Subject(3, 1, "영어", randomAchievementLevel()),
new Subject(3, 1, "체육", randomAchievementLevel())
new Subject(3, 1, "체육", randomAchievementLevel()),
new Subject(3, 1, "한문", randomAchievementLevel())
)),
new Attendance(randomNumber(0, 5), randomNumber(0, 5), randomNumber(0, 5), randomNumber(0, 5)),
new Attendance(randomNumber(0, 3), randomNumber(0, 3), randomNumber(0, 3), randomNumber(0, 3)),
new Attendance(randomNumber(0, 2), randomNumber(0, 2), randomNumber(0, 2), randomNumber(0, 2)),
randomNumber(0, 100),
randomNumber(0, 100),
randomNumber(0, 100),
// new CertificateList(List.of(Certificate.COMPUTER_SPECIALIST_LEVEL_2, Certificate.CRAFTSMAN_COMPUTER))
new CertificateList(null)
new CertificateList(List.of(Certificate.COMPUTER_SPECIALIST_LEVEL_2, Certificate.CRAFTSMAN_COMPUTER))
),
new Document(
"하이난김밤돌",
Expand Down

0 comments on commit a1df5ac

Please sign in to comment.