From 2b67d3a889462c4229ba9c6a1a066f7f64ef7b83 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:03:05 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20::=20Excel=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yapaghetti-infrastructure/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yapaghetti-infrastructure/build.gradle b/yapaghetti-infrastructure/build.gradle index 820995dc..35f0e781 100644 --- a/yapaghetti-infrastructure/build.gradle +++ b/yapaghetti-infrastructure/build.gradle @@ -69,6 +69,11 @@ dependencies { //cool sms implementation 'net.nurigo:javaSDK:2.2' + + // excel poi + implementation 'org.apache.poi:poi:3.16' + implementation 'org.apache.poi:poi-ooxml:3.16' + } test { From 6925369643cc2555b5af9c6e9b6753ed587a6cf6 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:03:27 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=93=91=20::=20ExcelErrorcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teacher/excel/exception/ExcelErrorCode.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java new file mode 100644 index 00000000..257bc0c5 --- /dev/null +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java @@ -0,0 +1,16 @@ +package kr.hs.entrydsm.yapaghetti.domain.teacher.excel.exception; + +import kr.hs.entrydsm.yapaghetti.error.ErrorProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public enum ExcelErrorCode implements ErrorProperty { + + EXCEL_IO_EXCEPTION(400, "엑셀을 다운로드 할 수 없습니다."); + + private final int status; + private final String message; +} From 91b03ff9d05a41a6a02b3b67ca5b16af42596056 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:03:41 +0900 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=93=91=20::=20ExcelIOException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teacher/excel/exception/ExcelOException.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java new file mode 100644 index 00000000..5aa9ce64 --- /dev/null +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java @@ -0,0 +1,12 @@ +package kr.hs.entrydsm.yapaghetti.domain.teacher.excel.exception; + +import kr.hs.entrydsm.yapaghetti.error.YapaghettiException; + +public class ExcelOException extends YapaghettiException { + + public static final YapaghettiException EXCEPTION = new ExcelOException(); + + private ExcelOException() { + super(ExcelErrorCode.EXCEL_IO_EXCEPTION); + } +} From 2788bd93b65da0f6921de05bc1a96ff0a7cfd7a1 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:03:56 +0900 Subject: [PATCH 04/14] =?UTF-8?q?=F0=9F=93=91=20::=20CreateExcelInterface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/teacher/excel/CreateExcelInterface.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelInterface.java diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelInterface.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelInterface.java new file mode 100644 index 00000000..bc6cd5bf --- /dev/null +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelInterface.java @@ -0,0 +1,7 @@ +package kr.hs.entrydsm.yapaghetti.domain.teacher.excel; + +import javax.servlet.http.HttpServletResponse; + +public interface CreateExcelInterface { + void execute(HttpServletResponse response); +} From c5242aaf6ce160f8fc6013556dc00b9147383186 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:04:06 +0900 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=93=91=20::=20CreateExcelImpl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/teacher/excel/CreateExcelImpl.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java new file mode 100644 index 00000000..3885aab7 --- /dev/null +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java @@ -0,0 +1,69 @@ +package kr.hs.entrydsm.yapaghetti.domain.teacher.excel; + +import kr.hs.entrydsm.yapaghetti.domain.student.persistence.StudentPersistenceAdapter; +import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.StudentElementByGradeClassNum; +import kr.hs.entrydsm.yapaghetti.domain.teacher.excel.exception.ExcelOException; +import lombok.AccessLevel; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import lombok.RequiredArgsConstructor; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@Component +public class CreateExcelImpl implements CreateExcelInterface { + + private final StudentPersistenceAdapter studentPersistenceAdapter; + @Override + public void execute(HttpServletResponse response) { + Workbook workbook = new XSSFWorkbook(); + Sheet sheet = workbook.createSheet("학생 정보"); + + int rowNum = 0; + String fileName = "전교생 현황"; + + Row headerRow = sheet.createRow(rowNum++); + headerRow.createCell(0).setCellValue("학번"); + headerRow.createCell(1).setCellValue("이름"); + headerRow.createCell(2).setCellValue("피드백 상태"); + headerRow.createCell(3).setCellValue("대기 문서 여부"); + headerRow.createCell(4).setCellValue("공개 문서 여부"); + + List excelElement = studentPersistenceAdapter + .queryStudentListByGradeAndClassNumAndDocStatus(null, null, null); + + for (StudentElementByGradeClassNum element : excelElement) { + Row row = sheet.createRow(rowNum++); + row.createCell(0).setCellValue(element.getGcn()); + row.createCell(1).setCellValue(element.getName()); + row.createCell(2).setCellValue(element.isFeedbackStatus() ? "O" : null); + row.createCell(3).setCellValue(element.isSubmitted() ? "O" : null); + row.createCell(4).setCellValue(element.isPublicStatus() ? "O" : null); + } + + try { + String time = LocalDateTime.now() + .format(DateTimeFormatter.ofPattern("yyyy년MM월dd일_HH시mm분_")); + String formatFileName = new String((time + fileName + ".xlsx") + .getBytes("KSC5601"), "8859_1"); + + response.setContentType("application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment; fileName=\"" + formatFileName + "\""); + + workbook.write(response.getOutputStream()); + workbook.close(); + } catch (IOException e) { + throw ExcelOException.EXCEPTION; + } + } + +} From 76f4416afa0ed9d2e4e0df81121d4f97eaed1f1b Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:04:35 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20ExcelAPI=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/teacher/presentation/TeacherWebAdapter.java | 8 ++++++++ .../yapaghetti/global/security/SecurityConfig.java | 1 + 2 files changed, 9 insertions(+) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java index f1fb1087..ea35e2f2 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java @@ -21,6 +21,7 @@ import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.CompanyListResponse; import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.NewCompanyResponse; import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.StudentDetailResponse; +import kr.hs.entrydsm.yapaghetti.domain.teacher.excel.CreateExcelInterface; import kr.hs.entrydsm.yapaghetti.domain.teacher.presentation.dto.request.WebCreateCompanyRequest; import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.StudentListResponse; import kr.hs.entrydsm.yapaghetti.domain.teacher.presentation.dto.request.WebCreateFeedbackRequest; @@ -38,6 +39,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.util.UUID; @@ -58,6 +61,7 @@ public class TeacherWebAdapter { private final QueryStudentDetailPort queryStudentDetailPort; private final QueryCompanyListPort queryCompanyListPort; private final DeleteFeedbackPort deleteFeedbackPort; + private final CreateExcelInterface createExcelUseCase; @ResponseStatus(HttpStatus.CREATED) @PostMapping("/feedback/{student-id}") @@ -162,4 +166,8 @@ public void deleteFeedback(@RequestBody @Valid WebDeleteFeedbackRequest request) ); } + @GetMapping("/excel") + public void getExcel(HttpServletResponse response) { + createExcelUseCase.execute(response); + } } diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/global/security/SecurityConfig.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/global/security/SecurityConfig.java index 260e9598..ff84ecb6 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/global/security/SecurityConfig.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/global/security/SecurityConfig.java @@ -64,6 +64,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .antMatchers(HttpMethod.DELETE, "/teachers/company/{company-id}").hasRole(TEACHER) .antMatchers(HttpMethod.DELETE, "/teachers/student/{student-id}").hasRole(TEACHER) .antMatchers(HttpMethod.DELETE, "/teachers/feedback").hasRole(TEACHER) + .antMatchers(HttpMethod.GET, "/teachers/excel").hasRole(TEACHER) // tags .antMatchers(HttpMethod.POST, "/tags").hasRole(TEACHER) From 10e825c28a4fad5667b07e11715a865956d2ec96 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:17:00 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=ED=99=95=EC=9E=A5=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yapaghetti/domain/teacher/excel/CreateExcelImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java index 3885aab7..15758dae 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java @@ -53,7 +53,7 @@ public void execute(HttpServletResponse response) { try { String time = LocalDateTime.now() .format(DateTimeFormatter.ofPattern("yyyy년MM월dd일_HH시mm분_")); - String formatFileName = new String((time + fileName + ".xlsx") + String formatFileName = new String((time + fileName + ".xls") .getBytes("KSC5601"), "8859_1"); response.setContentType("application/vnd.ms-excel"); From b3b8bd65b4bed711d90e55edbb1f012b51ac6adf Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 11:21:23 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20xlsx=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yapaghetti/domain/teacher/excel/CreateExcelImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java index 15758dae..55fdda38 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java @@ -53,10 +53,10 @@ public void execute(HttpServletResponse response) { try { String time = LocalDateTime.now() .format(DateTimeFormatter.ofPattern("yyyy년MM월dd일_HH시mm분_")); - String formatFileName = new String((time + fileName + ".xls") + String formatFileName = new String((time + fileName + ".xlsx") .getBytes("KSC5601"), "8859_1"); - response.setContentType("application/vnd.ms-excel"); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; fileName=\"" + formatFileName + "\""); workbook.write(response.getOutputStream()); From 550f74c28fe9d28e865086c3a05325e005301472 Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 12:24:17 +0900 Subject: [PATCH 09/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/teacher/presentation/TeacherWebAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java index ea35e2f2..402ce9b1 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/presentation/TeacherWebAdapter.java @@ -61,7 +61,7 @@ public class TeacherWebAdapter { private final QueryStudentDetailPort queryStudentDetailPort; private final QueryCompanyListPort queryCompanyListPort; private final DeleteFeedbackPort deleteFeedbackPort; - private final CreateExcelInterface createExcelUseCase; + private final CreateExcelInterface createExcelInterface; @ResponseStatus(HttpStatus.CREATED) @PostMapping("/feedback/{student-id}") @@ -168,6 +168,6 @@ public void deleteFeedback(@RequestBody @Valid WebDeleteFeedbackRequest request) @GetMapping("/excel") public void getExcel(HttpServletResponse response) { - createExcelUseCase.execute(response); + createExcelInterface.execute(response); } } From 5a69dfee76c11b04a792603811565c9b09d71b9c Mon Sep 17 00:00:00 2001 From: osangu Date: Wed, 19 Oct 2022 12:24:47 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20status=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/teacher/excel/exception/ExcelErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java index 257bc0c5..6b131261 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java @@ -9,7 +9,7 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) public enum ExcelErrorCode implements ErrorProperty { - EXCEL_IO_EXCEPTION(400, "엑셀을 다운로드 할 수 없습니다."); + EXCEL_IO_EXCEPTION(500, "엑셀을 다운로드 할 수 없습니다."); private final int status; private final String message; From 22b2082d6beba56e1c11b279a06ec8acd56a8b2e Mon Sep 17 00:00:00 2001 From: osangu Date: Tue, 25 Oct 2022 16:13:24 +0900 Subject: [PATCH 11/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20ExcelOException?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD=1C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yapaghetti/domain/teacher/excel/CreateExcelImpl.java | 4 ++-- .../domain/teacher/excel/exception/ExcelErrorCode.java | 2 +- .../{ExcelOException.java => ExcelOutPutException.java} | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/{ExcelOException.java => ExcelOutPutException.java} (53%) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java index 55fdda38..6991d5dc 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java @@ -2,7 +2,7 @@ import kr.hs.entrydsm.yapaghetti.domain.student.persistence.StudentPersistenceAdapter; import kr.hs.entrydsm.yapaghetti.domain.teacher.api.dto.response.StudentElementByGradeClassNum; -import kr.hs.entrydsm.yapaghetti.domain.teacher.excel.exception.ExcelOException; +import kr.hs.entrydsm.yapaghetti.domain.teacher.excel.exception.ExcelOutPutException; import lombok.AccessLevel; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -62,7 +62,7 @@ public void execute(HttpServletResponse response) { workbook.write(response.getOutputStream()); workbook.close(); } catch (IOException e) { - throw ExcelOException.EXCEPTION; + throw ExcelOutPutException.EXCEPTION; } } diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java index 6b131261..8b2b6472 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelErrorCode.java @@ -9,7 +9,7 @@ @AllArgsConstructor(access = AccessLevel.PRIVATE) public enum ExcelErrorCode implements ErrorProperty { - EXCEL_IO_EXCEPTION(500, "엑셀을 다운로드 할 수 없습니다."); + EXCEL_OUTPUT_EXCEPTION(500, "엑셀을 다운로드 할 수 없습니다."); private final int status; private final String message; diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOutPutException.java similarity index 53% rename from yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java rename to yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOutPutException.java index 5aa9ce64..b1595d40 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOException.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/exception/ExcelOutPutException.java @@ -2,11 +2,11 @@ import kr.hs.entrydsm.yapaghetti.error.YapaghettiException; -public class ExcelOException extends YapaghettiException { +public class ExcelOutPutException extends YapaghettiException { - public static final YapaghettiException EXCEPTION = new ExcelOException(); + public static final YapaghettiException EXCEPTION = new ExcelOutPutException(); - private ExcelOException() { - super(ExcelErrorCode.EXCEL_IO_EXCEPTION); + private ExcelOutPutException() { + super(ExcelErrorCode.EXCEL_OUTPUT_EXCEPTION); } } From 2d1becfaa71e6984fb1914761657b71ecab289fa Mon Sep 17 00:00:00 2001 From: osangu Date: Tue, 25 Oct 2022 16:39:58 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=A4=84?= =?UTF-8?q?=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yapaghetti/domain/teacher/excel/CreateExcelImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java index 6991d5dc..8f125632 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java @@ -23,6 +23,7 @@ public class CreateExcelImpl implements CreateExcelInterface { private final StudentPersistenceAdapter studentPersistenceAdapter; + @Override public void execute(HttpServletResponse response) { Workbook workbook = new XSSFWorkbook(); From d18affbdfe58368281bde17c70b90bfd08a170d9 Mon Sep 17 00:00:00 2001 From: osangu Date: Tue, 25 Oct 2022 17:16:52 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Excel=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=B2=B4=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{CreateExcelImpl.java => StudentXSSFExcelCreator.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/{CreateExcelImpl.java => StudentXSSFExcelCreator.java} (97%) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java similarity index 97% rename from yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java rename to yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java index 8f125632..6821d6c1 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/CreateExcelImpl.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java @@ -20,7 +20,7 @@ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) @Component -public class CreateExcelImpl implements CreateExcelInterface { +public class StudentXSSFExcelCreator implements CreateExcelInterface { private final StudentPersistenceAdapter studentPersistenceAdapter; From 213a499fd87eacc54c1bbd227661ce44ea37e995 Mon Sep 17 00:00:00 2001 From: osangu Date: Tue, 25 Oct 2022 17:50:27 +0900 Subject: [PATCH 14/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F::=20=EC=A0=95=EC=A0=81?= =?UTF-8?q?=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=ED=95=84=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/StudentXSSFExcelCreator.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java index 6821d6c1..b57789af 100644 --- a/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java +++ b/yapaghetti-infrastructure/src/main/java/kr/hs/entrydsm/yapaghetti/domain/teacher/excel/StudentXSSFExcelCreator.java @@ -18,12 +18,21 @@ import java.time.format.DateTimeFormatter; import java.util.List; -@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor @Component public class StudentXSSFExcelCreator implements CreateExcelInterface { private final StudentPersistenceAdapter studentPersistenceAdapter; - + + public static final String DATE_TIME_FORMAT_PATTERN = "yyyy년MM월dd일_HH시mm분_"; + public static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + public static final String HEADER_NAME = "\"Content-Disposition\""; + public static final String FILE_EXTENSION = ".xlsx"; + public static final String CHARSET_NAME = "8859_1"; + public static final String BITE_CHARSET_NAME = "KSC5601"; + public static final String HEADER_VALUE_BEFORE_NAME = "attachment; fileName=\""; + public static final String HEADER_VALUE_AFTER_NAME = "\""; + @Override public void execute(HttpServletResponse response) { Workbook workbook = new XSSFWorkbook(); @@ -53,12 +62,12 @@ public void execute(HttpServletResponse response) { try { String time = LocalDateTime.now() - .format(DateTimeFormatter.ofPattern("yyyy년MM월dd일_HH시mm분_")); - String formatFileName = new String((time + fileName + ".xlsx") - .getBytes("KSC5601"), "8859_1"); + .format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT_PATTERN)); + String formatFileName = new String((time + fileName + FILE_EXTENSION) + .getBytes(BITE_CHARSET_NAME), CHARSET_NAME); - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - response.setHeader("Content-Disposition", "attachment; fileName=\"" + formatFileName + "\""); + response.setContentType(CONTENT_TYPE); + response.setHeader(HEADER_NAME, HEADER_VALUE_BEFORE_NAME + formatFileName + HEADER_VALUE_AFTER_NAME); workbook.write(response.getOutputStream()); workbook.close();