11package kgu .developers .domain .graduationUser .application .query ;
22
33import kgu .developers .common .response .PaginatedListResponse ;
4+ import kgu .developers .domain .certificate .domain .CertificateRepository ;
45import kgu .developers .domain .graduationUser .domain .GraduationType ;
56import kgu .developers .domain .graduationUser .domain .GraduationUser ;
67import kgu .developers .domain .graduationUser .domain .GraduationUserExcel ;
78import kgu .developers .domain .graduationUser .domain .GraduationUserRepository ;
89import kgu .developers .domain .graduationUser .exception .GraduationUserNotFoundException ;
10+ import kgu .developers .domain .graduationUser .infrastructure .excel .GraduationUserExcelRow ;
11+ import kgu .developers .domain .thesis .domain .ThesisRepository ;
912import lombok .RequiredArgsConstructor ;
1013import org .springframework .data .domain .Pageable ;
1114import org .springframework .stereotype .Service ;
1821@ Transactional (readOnly = true )
1922public class GraduationUserQueryService {
2023 private final GraduationUserRepository graduationUserRepository ;
24+ private final ThesisRepository thesisRepository ;
25+ private final CertificateRepository certificateRepository ;
2126 private final GraduationUserExcel graduationUserExcel ;
2227
2328 public GraduationUser getById (Long graduationUserId ) {
@@ -31,7 +36,68 @@ public PaginatedListResponse<GraduationUser> getGraduationUsersByNameAndGraduati
3136
3237 public byte [] getGraduationUsersExcelByGraduationType (GraduationType graduationType ) {
3338 List <GraduationUser > graduationUsers = graduationUserRepository .findAllByGraduationTypeOrderByIdAsc (graduationType );
34- return graduationUserExcel .generate (graduationUsers ); //TODO: 추후 Approval 여부를 함께 넘겨주어야 함
39+
40+ List <GraduationUserExcelRow > graduationUserExcelRows = graduationUsers .stream ()
41+ .map (this ::getGraduationUserExcelRow )
42+ .toList ();
43+
44+ return graduationUserExcel .generate (graduationUserExcelRows );
45+ }
46+
47+ private GraduationUserExcelRow getGraduationUserExcelRow (GraduationUser graduationUser ) {
48+ return GraduationUserExcelRow .from (graduationUser , determineStage (graduationUser ), determineStatus (graduationUser ));
49+ }
50+
51+ private String determineStage (GraduationUser user ) {
52+ if (user .getGraduationType () == null ) {
53+ return "졸업 유형 미제출" ;
54+ }
55+
56+ if (user .getAdvisorProfessor () == null ) {
57+ return "지도교수 미배정" ;
58+ }
59+
60+ if (user .getGraduationType () == GraduationType .THESIS ) {
61+ if (user .getMidThesisId () == null ) {
62+ return "중간 논문 미제출" ;
63+ }
64+ if (user .getFinalThesisId () == null ) {
65+ return "최종 논문 미제출" ;
66+ }
67+ return "최종 논문 제출 완료" ;
68+ }
69+ else if (user .getGraduationType () == GraduationType .CERTIFICATE ) {
70+ if (user .getCertificateId () == null ) {
71+ return "자격증 미제출" ;
72+ }
73+ return "자격증 제출 완료" ;
74+ }
75+
76+ return "졸업 요건 충족" ;
77+ }
78+
79+ private String determineStatus (GraduationUser user ) {
80+ if (user .getGraduationType () == GraduationType .THESIS ) {
81+ if (user .getFinalThesisId () != null ) {
82+ return thesisRepository .findApprovalByIdAndDeletedAtIsNull (user .getFinalThesisId ())
83+ .map (approved -> approved ? "승인" : "미승인" )
84+ .orElse ("미승인" );
85+ }
86+ if (user .getMidThesisId () != null ) {
87+ return thesisRepository .findApprovalByIdAndDeletedAtIsNull (user .getMidThesisId ())
88+ .map (approved -> approved ? "승인" : "미승인" )
89+ .orElse ("미승인" );
90+ }
91+ }
92+ else if (user .getGraduationType () == GraduationType .CERTIFICATE ) {
93+ if (user .getCertificateId () != null ) {
94+ return certificateRepository .findApprovalByIdAndDeletedAtIsNull (user .getCertificateId ())
95+ .map (approved -> approved ? "승인" : "미승인" )
96+ .orElse ("미승인" );
97+ }
98+ }
99+
100+ return "대기" ;
35101 }
36102
37103 public GraduationUser getByStudentId (String studentId ) {
0 commit comments