飞滴出行网约车2022-api-passenger使用feign联调service-price实现预估价格

master
yh 3 years ago
parent a96fb4e518
commit 8658e53565

@ -0,0 +1,18 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.response.ForecastPriceResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@Service
@FeignClient("service-price")
public interface ServicePriceClient {
@PostMapping("/forecast-price")
public ResponseResult<ForecastPriceResponse> forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO);
}

@ -1,9 +1,11 @@
package com.mashibing.apipassenger.service; package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServicePriceClient;
import com.mashibing.internalcommon.dto.ResponseResult; import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO; import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.response.ForecastPriceResponse; import com.mashibing.internalcommon.response.ForecastPriceResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -11,6 +13,9 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ForecastPriceService { public class ForecastPriceService {
@Autowired
private ServicePriceClient servicePriceClient;
/** /**
* *
* @param depLongitude * @param depLongitude
@ -21,16 +26,23 @@ public class ForecastPriceService {
*/ */
public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude,String destLatitude){ public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude,String destLatitude){
log.info("出发地经度:"+depLongitude); // log.info("出发地经度:"+depLongitude);
log.info("出发地纬度:"+depLatitude); // log.info("出发地纬度:"+depLatitude);
log.info("目的地经度:"+destLongitude); // log.info("目的地经度:"+destLongitude);
log.info("目的地纬度:"+destLatitude); // log.info("目的地纬度:"+destLatitude);
// 调用 计价服务,进行价格预估 // 调用 计价服务,进行价格预估
ForecastPriceDTO priceDTO = new ForecastPriceDTO();
priceDTO.setDepLatitude(depLatitude);
priceDTO.setDepLongitude(depLongitude);
priceDTO.setDestLatitude(destLatitude);
priceDTO.setDestLongitude(destLongitude);
ResponseResult<ForecastPriceResponse> forecastPriceResponseResult = servicePriceClient.forecastPrice(priceDTO);
double price = forecastPriceResponseResult.getData().getPrice();
// 返回 封装结果对象
ForecastPriceResponse priceResponse = new ForecastPriceResponse(); ForecastPriceResponse priceResponse = new ForecastPriceResponse();
priceResponse.setPrice(12.34); priceResponse.setPrice(price);
return ResponseResult.success(priceResponse); return ResponseResult.success(priceResponse);
} }

@ -2,6 +2,7 @@ package com.mashibing.serviceprice.controller;
import com.mashibing.internalcommon.dto.ResponseResult; import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO; import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.response.ForecastPriceResponse;
import com.mashibing.serviceprice.service.ForecastPriceService; import com.mashibing.serviceprice.service.ForecastPriceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -15,7 +16,7 @@ public class ForecastPriceController {
private ForecastPriceService priceService; private ForecastPriceService priceService;
@PostMapping("/forecast-price") @PostMapping("/forecast-price")
public ResponseResult forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO){ public ResponseResult<ForecastPriceResponse> forecastPrice(@RequestBody ForecastPriceDTO forecastPriceDTO){
String depLongitude = forecastPriceDTO. getDepLongitude(); String depLongitude = forecastPriceDTO. getDepLongitude();
String depLatitude = forecastPriceDTO.getDepLatitude(); String depLatitude = forecastPriceDTO.getDepLatitude();

@ -35,12 +35,12 @@ public class ForecastPriceService {
* @param destLatitude * @param destLatitude
* @return * @return
*/ */
public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude){ public ResponseResult<ForecastPriceResponse> forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude){
log.info("出发地经度:"+depLongitude); // log.info("出发地经度:"+depLongitude);
log.info("出发地纬度:"+depLatitude); // log.info("出发地纬度:"+depLatitude);
log.info("目的地经度:"+destLongitude); // log.info("目的地经度:"+destLongitude);
log.info("目的地纬度:"+destLatitude); // log.info("目的地纬度:"+destLatitude);
ForecastPriceDTO priceDTO = new ForecastPriceDTO(); ForecastPriceDTO priceDTO = new ForecastPriceDTO();
priceDTO.setDepLatitude(depLatitude); priceDTO.setDepLatitude(depLatitude);
@ -52,8 +52,8 @@ public class ForecastPriceService {
Integer distance = driving.getData().getDistance(); Integer distance = driving.getData().getDistance();
Integer duration = driving.getData().getDuration(); Integer duration = driving.getData().getDuration();
System.out.println("distance = " + distance); // System.out.println("distance = " + distance);
System.out.println("duration = " + duration); // System.out.println("duration = " + duration);
// 读取计价规则 // 读取计价规则
Map<String,Object> queryMap = new HashMap<>(); Map<String,Object> queryMap = new HashMap<>();

Loading…
Cancel
Save