페이징 요청 수정

master
mjkhan21 9 months ago
parent 0c322e24af
commit 2455ea05d2

@ -6,9 +6,23 @@ import java.util.function.Function;
import cokr.xit.foundation.component.ScheduledBean; import cokr.xit.foundation.component.ScheduledBean;
/** Bean
* @author mjkhan
*/
public abstract class LntrisBean extends ScheduledBean { public abstract class LntrisBean extends ScheduledBean {
/**연계메시지 웹 요청자 */
protected Requestor requestor = new Requestor(); protected Requestor requestor = new Requestor();
/** .
* @param <Q>
* @param <R>
* @param <T>
* @param info
* @param getDetails function
* @param insertResps function
* @param updateReq function
* @param start (0 )
*/
protected <Q extends SourceMessage.Request, R extends TargetMessage.Response, T extends InterfaceInfo<Q, R>> void pagingRequest( protected <Q extends SourceMessage.Request, R extends TargetMessage.Response, T extends InterfaceInfo<Q, R>> void pagingRequest(
T info, T info,
Function<T, List<?>> getDetails, Function<T, List<?>> getDetails,
@ -16,13 +30,24 @@ public abstract class LntrisBean extends ScheduledBean {
BiConsumer<Object, Object> updateReq, BiConsumer<Object, Object> updateReq,
int start int start
) { ) {
R respBody = info.getTargetMessage().getBody();
String rstCd = respBody.getLinkRstCd(), // 최초 또는 이전 조회결과
rstMsg = respBody.getLinkRstMsg();
log().debug("Result before request: {} {}", rstCd, rstMsg);
requestor.request(info); requestor.request(info);
List<?> details = getDetails.apply(info); List<?> details = getDetails.apply(info);
int found = details.size(); int found = details.size();
boolean empty = found < 1; boolean empty = found < 1;
if (!empty) if (!empty)
InterfaceConfig.databaseActive(() -> insertResps.accept(info, start)); InterfaceConfig.databaseActive(() -> insertResps.accept(info, start));
if (found < 100) return; // 페이징 사이즈 = 100 if (found < 100) { // 페이징 사이즈 = 100
if (empty && !isEmpty(rstCd)) { // 마지막 페이지의 조회결과가 없을 경우(전체 데이터 수 mod 페이징 사이즈 == 0 일 경우) 최초 조회결과를 설정
respBody.setLinkRstCd(rstCd);
respBody.setLinkRstMsg(rstMsg);
}
return;
}
updateReq.accept(info.getRequest(), details.get(found - 1)); updateReq.accept(info.getRequest(), details.get(found - 1));

Loading…
Cancel
Save