59 lines
1.7 KiB
Java
59 lines
1.7 KiB
Java
package com.goi.erp.client;
|
|
|
|
import com.goi.erp.dto.ScheduleWorkerRequestDto;
|
|
import com.goi.erp.dto.ext.ExtSamsaraEngineSecondsFetchCommand;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class SamsaraStatEngineSecondsClient {
|
|
|
|
private final WebClient webClient;
|
|
|
|
public SamsaraStatEngineSecondsClient(
|
|
WebClient.Builder webClientBuilder,
|
|
@Value("${integration.api.base-url}") String integrationBaseUrl
|
|
) {
|
|
this.webClient = webClientBuilder
|
|
.baseUrl(integrationBaseUrl)
|
|
.build();
|
|
}
|
|
|
|
/**
|
|
* integration-service 호출
|
|
* POST /vehicle/odometer/fetch
|
|
*/
|
|
public ExtSamsaraEngineSecondsFetchCommand fetchEngineSeconds(
|
|
ScheduleWorkerRequestDto request
|
|
) {
|
|
|
|
try {
|
|
return webClient.post()
|
|
.uri("/vehicle/stat/engine-seconds/fetch")
|
|
.bodyValue(request)
|
|
.retrieve()
|
|
.onStatus(
|
|
status -> status.is4xxClientError() || status.is5xxServerError(),
|
|
resp -> resp.bodyToMono(String.class)
|
|
.map(body ->
|
|
new RuntimeException(
|
|
"INTEGRATION_ERROR: " + body
|
|
)
|
|
)
|
|
)
|
|
.bodyToMono(ExtSamsaraEngineSecondsFetchCommand.class)
|
|
.block();
|
|
|
|
} catch (Exception e) {
|
|
// 이 메시지가 OPR 서비스 레벨까지 올라감
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|