service-price调用service-map

main
topsun 2 years ago
parent 09214dcaa6
commit cfbb91076d

@ -20,5 +20,20 @@
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
</dependencies>
</project>

@ -3,9 +3,11 @@ package com.taxi.serviceprice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient//服务发现
@EnableFeignClients
public class ServicePriceApplication {
public static void main(String[] args) {

@ -0,0 +1,17 @@
package com.taxi.serviceprice.remote;
import com.internal.dto.ResponseResult;
import com.internal.request.ForecastPriceDTO;
import com.internal.response.DirectionResponse;
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-map")
public interface ServiceMapClient {
@RequestMapping(method = RequestMethod.GET,value = "/direction/driving")
ResponseResult<DirectionResponse> direction(@RequestBody ForecastPriceDTO forecastPriceDTO);
}

@ -1,14 +1,20 @@
package com.taxi.serviceprice.service;
import com.internal.dto.ResponseResult;
import com.internal.response.ForecastPriceResponse;
import com.internal.request.ForecastPriceDTO;
import com.internal.response.DirectionResponse;
import com.taxi.serviceprice.remote.ServiceMapClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class ForecastPriceService {
@Autowired
private ServiceMapClient serviceMapClient;
/**
*
* @param depLongitude
@ -25,11 +31,18 @@ public class ForecastPriceService {
log.info("目的地纬度," + destLatitude);
log.info("调用地图服务,查询地图和时长");
ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
forecastPriceDTO.setDepLongitude(depLongitude);
forecastPriceDTO.setDepLatitude(depLatitude);
forecastPriceDTO.setDestLongitude(destLongitude);
forecastPriceDTO.setDestLatitude(destLatitude);
ResponseResult<DirectionResponse> directionResponse = serviceMapClient.direction(forecastPriceDTO);
log.info("距离"+directionResponse.getData().getDistance());
log.info("时间"+directionResponse.getData().getDuration());
log.info("读取计价规则");
log.info("根据距离、时长,计价规则;计算价格");
ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse();
forecastPriceResponse.setPrice(12.121);
return ResponseResult.success(forecastPriceResponse);
return ResponseResult.success();
}
}

@ -7,4 +7,4 @@ spring:
discovery:
server-addr: 127.0.0.1:8848
application:
name: servcie-price
name: service-price

@ -7,4 +7,4 @@ spring:
discovery:
server-addr: 127.0.0.1:8848
application:
name: servcie-price
name: service-price

@ -21,6 +21,7 @@
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</project>
Loading…
Cancel
Save