Skip to content

Commit

Permalink
chore : 관규님 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
duehee committed Dec 28, 2024
1 parent df9032d commit 1724336
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package in.koreatech.koin.domain.graduation.model;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

public record GradeExcelData(
String year,
String semester,
String code,
String classTitle,
String lectureClass,
String professor,
String courseType,
String credit,
String grade,
String retakeStatus
) {
public static GradeExcelData fromRow(Row row) {
return new GradeExcelData(
getCellValueAsString(row.getCell(1)),
getCellValueAsString(row.getCell(2)),
getCellValueAsString(row.getCell(4)),
getCellValueAsString(row.getCell(5)),
getCellValueAsString(row.getCell(6)),
getCellValueAsString(row.getCell(7)),
getCellValueAsString(row.getCell(8)),
getCellValueAsString(row.getCell(9)),
getCellValueAsString(row.getCell(10)),
getCellValueAsString(row.getCell(11))
);
}

private static String getCellValueAsString(Cell cell) {
if (cell == null) {
return "";
}
return switch (cell.getCellType()) {
case STRING -> cell.getStringCellValue();
case NUMERIC -> String.valueOf((int)cell.getNumericCellValue());
default -> "";
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import in.koreatech.koin.domain.graduation.dto.ExcelStudentData;
import in.koreatech.koin.domain.graduation.model.GradeExcelData;
import in.koreatech.koin.domain.graduation.model.CourseType;
import in.koreatech.koin.domain.graduation.repository.CourseTypeRepository;
import in.koreatech.koin.domain.graduation.exception.ExcelFileCheckException;
Expand Down Expand Up @@ -58,30 +58,28 @@ public void readStudentGradeExcelFile(MultipartFile file, Integer userId) throws
String currentSemester = "default";

for (Row row : sheet) {
ExcelStudentData data = extractStudentData(row);
GradeExcelData data = extractExcelData(row);
if (row.getRowNum() == 0 || skipRow(data))
continue;

if (data.excelClassTitle().equals(TOTAL))
if (data.classTitle().equals(TOTAL))
break;

String semester = getKoinSemester(data.excelSemester(), data.excelYear());
CourseType courseType = courseTypeRepository.findByName(data.excelCourseType()).orElse(null);
String semester = getKoinSemester(data.semester(), data.year());
CourseType courseType = courseTypeRepository.findByName(data.courseType()).orElse(null);
Lecture lecture = lectureRepositoryV2.findBySemesterAndCodeAndLectureClass(semester,
data.excelCode(), data.excelLectureClass()).orElse(null);
data.code(), data.lectureClass()).orElse(null);

if (!currentSemester.equals(semester)) {
currentSemester = semester;
graduationFrame = createFrameAboutExcel(userId, currentSemester);
}

TimetableLecture timetableLecture = TimetableLecture.builder()
.classTitle(data.excelClassTitle())
.classTitle(data.classTitle())
.classTime(lecture != null ? lecture.getClassTime() : null)
.classPlace(null)
.professor(data.excelProfessor())
.grades(data.excelCredit())
.memo(null)
.professor(data.professor())
.grades(data.credit())
.isDeleted(false)
.lecture(lecture)
.timetableFrame(graduationFrame)
Expand All @@ -107,7 +105,7 @@ private TimetableFrame createFrameAboutExcel(Integer userId, String semester) {
TimetableFrame graduationFrame = TimetableFrame.builder()
.user(user)
.semester(saveSemester)
.name("졸업학점 계산용 테이블")
.name("Graduation Frame")
.isDeleted(false)
.isMain(true)
.build();
Expand All @@ -116,6 +114,10 @@ private TimetableFrame createFrameAboutExcel(Integer userId, String semester) {
return graduationFrame;
}

private GradeExcelData extractExcelData(Row row) {
return GradeExcelData.fromRow(row);
}

private void checkFiletype(MultipartFile file) {
if (file == null) {
throw new ExcelFileNotFoundException("파일이 있는지 확인 해주세요.");
Expand All @@ -133,36 +135,10 @@ private void checkFiletype(MultipartFile file) {
}
}

private ExcelStudentData extractStudentData(Row row) {
return new ExcelStudentData(
getCellValueAsString(row.getCell(1)),
getCellValueAsString(row.getCell(2)),
getCellValueAsString(row.getCell(4)),
getCellValueAsString(row.getCell(5)),
getCellValueAsString(row.getCell(6)),
getCellValueAsString(row.getCell(7)),
getCellValueAsString(row.getCell(8)),
getCellValueAsString(row.getCell(9)),
getCellValueAsString(row.getCell(10)),
getCellValueAsString(row.getCell(11))
);
}

private boolean skipRow(ExcelStudentData excelStudentData) {
return excelStudentData.excelClassTitle().equals(MIDDLE_TOTAL) ||
excelStudentData.excelRetakeStatus().equals(RETAKE) ||
excelStudentData.excelGrade().equals(UNSATISFACTORY);
}

private String getCellValueAsString(Cell cell) {
if (cell == null) {
return "";
}
return switch (cell.getCellType()) {
case STRING -> cell.getStringCellValue();
case NUMERIC -> String.valueOf((int)cell.getNumericCellValue());
default -> "";
};
private boolean skipRow(GradeExcelData gradeExcelData) {
return gradeExcelData.classTitle().equals(MIDDLE_TOTAL) ||
gradeExcelData.retakeStatus().equals(RETAKE) ||
gradeExcelData.grade().equals(UNSATISFACTORY);
}

private String getKoinSemester(String semester, String year) {
Expand Down

0 comments on commit 1724336

Please sign in to comment.