package com.goi.erp.client; import com.goi.erp.dto.ScheduleWorkerRequestDto; import com.goi.erp.dto.ext.ExtSamsaraOdometerFetchCommand; 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 SamsaraStatOdometerClient { private final WebClient webClient; public SamsaraStatOdometerClient( WebClient.Builder webClientBuilder, @Value("${integration.api.base-url}") String integrationBaseUrl ) { this.webClient = webClientBuilder .baseUrl(integrationBaseUrl) .build(); } /** * integration-service 호출 * POST /vehicle/odometer/fetch */ public ExtSamsaraOdometerFetchCommand fetchOdometer( ScheduleWorkerRequestDto request ) { try { return webClient.post() .uri("/vehicle/stat/odometer/fetch") .bodyValue(request) .retrieve() .onStatus( status -> status.is4xxClientError() || status.is5xxServerError(), resp -> resp.bodyToMono(String.class) .map(body -> new RuntimeException( "INTEGRATION_ERROR: " + body ) ) ) .bodyToMono(ExtSamsaraOdometerFetchCommand.class) .block(); } catch (Exception e) { // 이 메시지가 OPR 서비스 레벨까지 올라감 throw e; } } }