Skip to content

Commit

Permalink
[fix] : batch 필드명 수정
Browse files Browse the repository at this point in the history
[fix] : batch 필드명 수정
  • Loading branch information
Jeoongu authored Oct 5, 2024
2 parents dc749ea + 65a634f commit 2b02d98
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AdminController {
private final AdminService adminService;

@PostMapping("/s3-csv")
public ResponseEntity<ApiResponse<?>> csvToS3(@RequestParam MultipartFile file) {
public ResponseEntity<ApiResponse<?>> csvToS3(@RequestPart(value = "csv") MultipartFile file) {
adminService.uploadCsvToS3(file);
return ApiResponse.success(null);
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/ussum/homepage/domain/csv_user/StudentCsv.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class StudentCsv {
private Long STID;
private Long studentId;
private String studentName;
private String groupName;
private String program;
private String major;
private String specificMajor;
private String studentStatus;
private String studentGroup; // 학생그룹의 의미
// 전화번호?
private String studentEmail;

public static StudentCsv of(Long STID, Long studentId, String studentName, String groupName,
String major, String studentStatus, String studentGroup, String studentEmail) {
return new StudentCsv(STID, studentId, studentName, groupName,
major, studentStatus, studentGroup, studentEmail);
public static StudentCsv of(Long studentId, String studentName, String groupName,
String program, String major, String specificMajor, String studentStatus) {
return new StudentCsv(studentId, studentName, groupName,
program, major, specificMajor, studentStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
Expand All @@ -28,6 +29,7 @@ public Job studentDataLoadJob(JobRepository jobRepository, Step studentDataLoadS
}

@Bean
@JobScope
public Step studentDataLoadStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return new StepBuilder("studentDataLoadStep", jobRepository)
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/ussum/homepage/infra/csvBatch/csv/CSVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public FlatFileItemReader<StudentCsv> csvFileItemReader() { // 엔티티를 반
/* delimitedLineTokenizer : setNames를 통해 각각의 데이터의 이름 설정 */
DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer(",");
delimitedLineTokenizer.setNames(
"STID",
"studentId",
"studentName",
"groupName",
"major",
"studentStatus",
"studentGroup",
"studentEmail"
"studentId", // 학번
"studentName", // 성명
"groupName", // 대학
"program", // 프로그램?
"major", // 학과(부)
"specificMajor", // 세부전공(건축만 존재)
"studentStatus" // 재학여부(재학, 휴학)
);
defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void write(Chunk<? extends StudentCsv> chunk) throws Exception {
Chunk<StudentCsvEntity> students = new Chunk<>();

chunk.forEach(studentCsvDto -> {
StudentCsvEntity data = ussum.homepage.infra.jpa.csv_user.entity.StudentCsvEntity.of(studentCsvDto.getSTID(), studentCsvDto.getStudentId(), studentCsvDto.getStudentName(), studentCsvDto.getGroupName(),
studentCsvDto.getMajor(), studentCsvDto.getStudentStatus(), studentCsvDto.getStudentGroup(), studentCsvDto.getStudentEmail());
StudentCsvEntity data = ussum.homepage.infra.jpa.csv_user.entity.StudentCsvEntity.of(studentCsvDto.getStudentId(), studentCsvDto.getStudentName(), studentCsvDto.getGroupName(),
studentCsvDto.getProgram(), studentCsvDto.getMajor(), studentCsvDto.getSpecificMajor(), studentCsvDto.getStudentStatus());
students.add(data);
});
csvRepository.saveAll(students);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ public class StudentCsvMapper {

public StudentCsv toDomain(StudentCsvEntity csvData) {
return StudentCsv.of(
csvData.getSTID(),
csvData.getStudentId(),
csvData.getStudentName(),
csvData.getGroupName(),
csvData.getProgram(),
csvData.getMajor(),
csvData.getStudentStatus(),
csvData.getStudentGroup(),
csvData.getStudentEmail()
csvData.getSpecificMajor(),
csvData.getStudentStatus()
);
}

public StudentCsvEntity toEntity(StudentCsv studentCsv) {
return StudentCsvEntity.of(
studentCsv.getSTID(),
studentCsv.getStudentId(),
studentCsv.getStudentName(),
studentCsv.getProgram(),
studentCsv.getGroupName(),
studentCsv.getMajor(),
studentCsv.getStudentStatus(),
studentCsv.getStudentGroup(),
studentCsv.getStudentEmail()
studentCsv.getSpecificMajor(),
studentCsv.getStudentStatus()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@
@Builder
@Entity
public class StudentCsvEntity {
// STID / 학번 / 성명 / 대학 / 학과(부) / 학적상 / 학생그룹 / (전화번호) / (전자메일)
@Id
private Long STID;
private Long studentId;
private String studentName;
private String groupName;
private String program;
private String major;
private String specificMajor;
private String studentStatus;
private String studentGroup; // 학생그룹의 의미
// 전화번호?
private String studentEmail;

public static StudentCsvEntity of(Long STID, Long studentId, String studentName, String groupName,
String major, String studentStatus, String studentGroup, String studentEmail) {
return ussum.homepage.infra.jpa.csv_user.entity.StudentCsvEntity.builder()
.STID(STID)
public static StudentCsvEntity of(Long studentId, String studentName, String groupName,
String program, String major, String specificMajor, String studentStatus) {
return StudentCsvEntity.builder()
.studentId(studentId)
.studentName(studentName)
.groupName(groupName)
.program(program)
.major(major)
.specificMajor(specificMajor)
.studentStatus(studentStatus)
.studentGroup(studentGroup)
.studentEmail(studentEmail)
.build();
}
}

0 comments on commit 2b02d98

Please sign in to comment.