-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] 축제 행사 정보 연동 개발 및 전시 정보 연동 기능 이식
- 축제 행사 정보 연동 기능 구현 - 전시 정보 연동 기능 artfriendly 앱에서 이식 - restTemplate에서 open feign으로 api 호출 방식 리팩토링 - Tasklet 방식 -> Chunk 방식으로 구현
- Loading branch information
Showing
51 changed files
with
1,854 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/org/com/artfriendlybatch/domain/exhibition/chunk/ExhibitionInfoChunk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.chunk; | ||
|
||
import org.com.artfriendlybatch.domain.exhibition.dto.ExhibitionInfoIntegrateDto; | ||
import org.com.artfriendlybatch.domain.exhibition.dto.apiIntegrationDto.callExhibitionDto.DetailPerformInfo; | ||
import org.com.artfriendlybatch.domain.exhibition.dto.apiIntegrationDto.callExhibitionsDto.PerformList; | ||
import org.com.artfriendlybatch.domain.exhibition.entity.ExhibitionInfo; | ||
import org.com.artfriendlybatch.domain.exhibition.mapper.ExhibitionInfoMapper; | ||
import org.com.artfriendlybatch.domain.exhibition.repository.ExhibitionInfoRepository; | ||
import org.com.artfriendlybatch.domain.exhibition.service.ExhibitionInfoService; | ||
import org.springframework.batch.item.ItemProcessor; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.batch.item.ItemWriter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Optional; | ||
|
||
@Configuration | ||
public class ExhibitionInfoChunk { | ||
private final ExhibitionInfoService exhibitionInfoService; | ||
private final ExhibitionInfoRepository exhibitionInfoRepository; | ||
|
||
public ExhibitionInfoChunk(ExhibitionInfoService exhibitionInfoService, ExhibitionInfoRepository exhibitionInfoRepository) { | ||
this.exhibitionInfoService = exhibitionInfoService; | ||
this.exhibitionInfoRepository = exhibitionInfoRepository; | ||
} | ||
|
||
@Bean | ||
public ItemReader<PerformList> exhibitionInfoIntegrateReader() { | ||
return new PerformReader(exhibitionInfoService); // API를 호출하여 데이터 읽기 | ||
} | ||
|
||
@Bean | ||
public ItemProcessor<PerformList, ExhibitionInfoIntegrateDto> exhibitionInfoIntegrateProcessor(ExhibitionInfoMapper exhibitionInfoMapper) { | ||
return item -> { | ||
// API 호출 및 ExhibitionInfo 생성 로직(이미 있는 값이면 업데이트로 수정) | ||
int seq = Integer.parseInt(item.getSeq()); | ||
DetailPerformInfo detailPerformInfo = exhibitionInfoService.getDetailPerformInfo(seq); | ||
Optional<ExhibitionInfo> optionalExhibitionInfo = Optional.ofNullable(exhibitionInfoRepository.findExhibitionInfoBySeq(seq)); | ||
|
||
// 새로운 dto 하나 더 만들어서 저장 할 때 업뎃 or 새로 생성 나눠서 할 수 있도록!! | ||
return optionalExhibitionInfo | ||
.map(existingInfo -> { | ||
// 업데이트 | ||
existingInfo.updateForm(exhibitionInfoMapper.perforInfoToExhibitionInfo(detailPerformInfo)); | ||
return ExhibitionInfoIntegrateDto.builder() | ||
.exhibitionInfo(existingInfo) | ||
.updateAble(true) | ||
.build(); | ||
}) | ||
.orElseGet(() -> { | ||
// 생성 | ||
ExhibitionInfo newExhibitionInfo = exhibitionInfoMapper.perforInfoToExhibitionInfo(detailPerformInfo); | ||
return ExhibitionInfoIntegrateDto.builder() | ||
.exhibitionInfo(newExhibitionInfo) | ||
.updateAble(false) | ||
.build(); | ||
}); | ||
}; | ||
} | ||
|
||
@Bean | ||
public ItemWriter<ExhibitionInfoIntegrateDto> exhibitionInfoIntegrateWriter() { | ||
return items -> { | ||
for (ExhibitionInfoIntegrateDto dto : items) { | ||
if (dto.isUpdateAble()) { | ||
// 업데이트 로직 | ||
exhibitionInfoRepository.save(dto.getExhibitionInfo()); | ||
} else { | ||
// 새로 생성하는 로직 | ||
exhibitionInfoService.createExhibition(dto.getExhibitionInfo()); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public ItemReader<ExhibitionInfo> exhibitionInfoReader() { | ||
return new ExhibitionInfoReader(exhibitionInfoService); | ||
} | ||
|
||
@Bean | ||
public ItemProcessor<ExhibitionInfo, ExhibitionInfo> exhibitionInfoProcessor() { | ||
return ExhibitionInfo::updateProgressStatus; | ||
} | ||
|
||
@Bean | ||
public ItemWriter<ExhibitionInfo> exhibitionInfoWriter() { | ||
return exhibitionInfoRepository::saveAll; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/com/artfriendlybatch/domain/exhibition/chunk/ExhibitionInfoReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.chunk; | ||
|
||
import org.com.artfriendlybatch.domain.exhibition.entity.ExhibitionInfo; | ||
import org.com.artfriendlybatch.domain.exhibition.service.ExhibitionInfoService; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.batch.item.NonTransientResourceException; | ||
import org.springframework.batch.item.ParseException; | ||
import org.springframework.batch.item.UnexpectedInputException; | ||
|
||
import java.util.List; | ||
|
||
public class ExhibitionInfoReader implements ItemReader<ExhibitionInfo> { | ||
private final ExhibitionInfoService exhibitionInfoService; | ||
private final List<ExhibitionInfo> details; | ||
private int currentIndex = 0; | ||
|
||
public ExhibitionInfoReader(ExhibitionInfoService exhibitionInfoService) { | ||
this.exhibitionInfoService = exhibitionInfoService; | ||
this.details = this.fetchDataFromDb(); | ||
} | ||
|
||
|
||
@Override | ||
public ExhibitionInfo read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { | ||
if (currentIndex < details.size()) { | ||
return details.get(currentIndex++); // 현재 인덱스의 항목 반환 후 인덱스 증가 | ||
} | ||
return null; // 더 이상 읽을 항목이 없으면 null 반환 | ||
} | ||
|
||
private List<ExhibitionInfo> fetchDataFromDb() { | ||
return exhibitionInfoService.getExhibitionInfoByProgressStatusIn(List.of("inProgress", "scheduled")); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/com/artfriendlybatch/domain/exhibition/chunk/PerformReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.chunk; | ||
|
||
import org.com.artfriendlybatch.domain.exhibition.dto.apiIntegrationDto.callExhibitionsDto.PerformList; | ||
import org.com.artfriendlybatch.domain.exhibition.service.ExhibitionInfoService; | ||
import org.springframework.batch.item.ItemReader; | ||
import org.springframework.batch.item.NonTransientResourceException; | ||
import org.springframework.batch.item.ParseException; | ||
import org.springframework.batch.item.UnexpectedInputException; | ||
|
||
import java.util.List; | ||
|
||
public class PerformReader implements ItemReader<PerformList> { | ||
|
||
private final ExhibitionInfoService exhibitionInfoService; | ||
private final List<PerformList> details; | ||
private int currentIndex = 0; | ||
|
||
public PerformReader(ExhibitionInfoService exhibitionInfoService) { | ||
this.exhibitionInfoService = exhibitionInfoService; | ||
this.details = this.fetchDataFromApi(); | ||
} | ||
|
||
@Override | ||
public PerformList read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { | ||
if (currentIndex < details.size()) { | ||
return details.get(currentIndex++); // 현재 인덱스의 항목 반환 후 인덱스 증가 | ||
} | ||
return null; // 더 이상 읽을 항목이 없으면 null 반환 | ||
} | ||
|
||
private List<PerformList> fetchDataFromApi() { | ||
return exhibitionInfoService.getPerformInfo(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/com/artfriendlybatch/domain/exhibition/dto/ExhibitionInfoIntegrateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.com.artfriendlybatch.domain.exhibition.entity.ExhibitionInfo; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
public class ExhibitionInfoIntegrateDto { | ||
ExhibitionInfo exhibitionInfo; | ||
boolean updateAble; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...a/org/com/artfriendlybatch/domain/exhibition/dto/apiIntegrationDto/ApiRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.dto.apiIntegrationDto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ApiRequestBuilder { | ||
private String realmCode; | ||
private String startDate; | ||
private String endDate; | ||
private int cPage; | ||
private int rows; | ||
private String sido; | ||
private String gugun; | ||
private String place; | ||
private String gpsxfrom; | ||
private String gpsyform; | ||
private String gpsxto; | ||
private String gpsyto; | ||
private String keyword; | ||
private int sortStdr; | ||
|
||
@Builder | ||
public ApiRequestBuilder(String realmCode, String startDate, String endDate, int cPage, int rows, String sido, String gugun, String place, Double gpsxfrom, Double gpsyform, Double gpsxto, Double gpsyto, String keyword, int sortStdr) { | ||
this.realmCode = realmCode; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.cPage = cPage; | ||
this.rows = rows; | ||
this.sido = sido == null ? "" : sido; | ||
this.gugun = gugun == null ? "" : gugun; | ||
this.place = place == null ? "" : place; | ||
this.gpsxfrom = gpsxfrom == null ? "" : String.valueOf(gpsxfrom); | ||
this.gpsyform = gpsyform == null ? "" : String.valueOf(gpsyform); | ||
this.gpsxto = gpsxto == null ? "" : String.valueOf(gpsxto); | ||
this.gpsyto = gpsyto == null ? "" : String.valueOf(gpsyto); | ||
this.keyword = keyword == null ? "" : keyword; | ||
this.sortStdr = sortStdr; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/org/com/artfriendlybatch/domain/exhibition/dto/apiIntegrationDto/ComMsgHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.com.artfriendlybatch.domain.exhibition.dto.apiIntegrationDto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import lombok.*; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ComMsgHeader { | ||
@JacksonXmlProperty(localName = "RequestMsgID") | ||
private String requestMsgID; | ||
|
||
@JacksonXmlProperty(localName = "ResponseTime") | ||
private String responseTime; | ||
|
||
@JacksonXmlProperty(localName = "ResponseMsgID") | ||
private String responseMsgID; | ||
|
||
@JacksonXmlProperty(localName = "SuccessYN") | ||
private String successYN; | ||
|
||
@JacksonXmlProperty(localName = "ReturnCode") | ||
private String returnCode; | ||
|
||
@JacksonXmlProperty(localName = "ErrMsg") | ||
private String errMsg; | ||
} |
Oops, something went wrong.