diff --git a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/controller/ForecastPriceController.java b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/controller/ForecastPriceController.java index 705c52b..a52e356 100644 --- a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/controller/ForecastPriceController.java +++ b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/controller/ForecastPriceController.java @@ -2,6 +2,7 @@ package com.taxi.apipassenger.controller; import com.internal.dto.ResponseResult; import com.internal.request.ForecastPriceDTO; +import com.taxi.apipassenger.remote.ServicePriceClient; import com.taxi.apipassenger.service.ForecastPriceServcie; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +17,8 @@ public class ForecastPriceController { @Autowired private ForecastPriceServcie forecastPriceServcie; + + @PostMapping("/forecast-price") public ResponseResult forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO) { log.info("出发经度," + forecastPriceDTO.getDepLongitude()); @@ -29,6 +32,8 @@ public class ForecastPriceController { log.info("目的地经度," + forecastPriceDTO.getDestLongitude()); log.info("目的地纬度," + forecastPriceDTO.getDestLatitude()); + + return forecastPriceServcie.forecastPrice(depLongitude,depLatitude,destLongitude,destLatitude); } } diff --git a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/remote/ServicePriceClient.java b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/remote/ServicePriceClient.java new file mode 100644 index 0000000..7c86452 --- /dev/null +++ b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/remote/ServicePriceClient.java @@ -0,0 +1,19 @@ +package com.taxi.apipassenger.remote; + +import com.internal.dto.ResponseResult; +import com.internal.request.ForecastPriceDTO; +import com.internal.response.ForecastPriceResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + + +@FeignClient("service-price") +public interface ServicePriceClient { + + + @RequestMapping(method = RequestMethod.POST,value = "/forecast-price") + ResponseResult forecast(@RequestBody ForecastPriceDTO forecastPriceDTO); + +} diff --git a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/ForecastPriceServcie.java b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/ForecastPriceServcie.java index 94dbab2..5f58e5b 100644 --- a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/ForecastPriceServcie.java +++ b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/ForecastPriceServcie.java @@ -1,14 +1,18 @@ package com.taxi.apipassenger.service; import com.internal.dto.ResponseResult; +import com.internal.request.ForecastPriceDTO; import com.internal.response.ForecastPriceResponse; +import com.taxi.apipassenger.remote.ServicePriceClient; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service @Slf4j public class ForecastPriceServcie { - + @Autowired + private ServicePriceClient servicePriceClient; /** * 根据 出发地和目的的经纬度,计算预估价格 * @param depLongitude @@ -23,11 +27,17 @@ public class ForecastPriceServcie { log.info("出发纬度," + depLatitude); log.info("目的地经度," + destLongitude); log.info("目的地纬度," + destLatitude); - log.info("调用计价服务,计算价格"); + ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO(); + forecastPriceDTO.setDepLongitude(depLongitude); + forecastPriceDTO.setDepLatitude(depLatitude); + forecastPriceDTO.setDestLongitude(destLongitude); + forecastPriceDTO.setDestLatitude(destLatitude); + ResponseResult responseResult = servicePriceClient.forecast(forecastPriceDTO); + double price = responseResult.getData().getPrice(); ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse(); - forecastPriceResponse.setPrice(12.121); + forecastPriceResponse.setPrice(price); return ResponseResult.success(forecastPriceResponse); }