地区字典url拼接

main
topsun 2 years ago
parent 9a1355a379
commit 15afa8326f

@ -9,4 +9,5 @@ public class AmapConfigConstant {
public static final String DURATION = "duration"; public static final String DURATION = "duration";
public static final String DIRECTION_URL = "https://restapi.amap.com/v3/direction/driving"; public static final String DIRECTION_URL = "https://restapi.amap.com/v3/direction/driving";
public static final String DISTRICT_URL = "https://restapi.amap.com/v3/config/district";
} }

@ -0,0 +1,12 @@
package com.internal.dto;
import lombok.Data;
@Data
public class DicDistrict {
private String addressCode;
private String addressName;
private String parentAddressCode;
private Integer level;
}

@ -30,7 +30,7 @@ public class BigDecimalUtils {
} }
BigDecimal b1 = BigDecimal.valueOf(v1); BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2); BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP).doubleValue(); return b1.divide(b2).doubleValue();
} }
public static double subtract(double v1,double v2) { public static double subtract(double v1,double v2) {

@ -9,7 +9,6 @@ import com.internal.response.ForecastPriceResponse;
import com.internal.util.BigDecimalUtils; import com.internal.util.BigDecimalUtils;
import com.taxi.serviceprice.mapper.PriceRuleMapper; import com.taxi.serviceprice.mapper.PriceRuleMapper;
import com.taxi.serviceprice.remote.ServiceMapClient; import com.taxi.serviceprice.remote.ServiceMapClient;
import javafx.scene.effect.Light;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -111,7 +110,9 @@ public class ForecastPriceService {
Double unitPricePerMinute = priceRule.getUnitPricePerMinute(); Double unitPricePerMinute = priceRule.getUnitPricePerMinute();
double timeFare = BigDecimalUtils.multiply(time,unitPricePerMinute); double timeFare = BigDecimalUtils.multiply(time,unitPricePerMinute);
price = BigDecimalUtils.add(price,timeFare); price = BigDecimalUtils.add(price,timeFare);
return new BigDecimal(price).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); BigDecimal priceBigDecimal = new BigDecimal(price);
price = priceBigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return price;
} }
// public static void main(String[] args) throws IllegalAccessException { // public static void main(String[] args) throws IllegalAccessException {

@ -22,6 +22,16 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -1,6 +1,7 @@
package com.taxi.servicemap; package com.taxi.servicemap;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@ -9,6 +10,7 @@ import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient//服务发现 @EnableDiscoveryClient//服务发现
@MapperScan("com.taxi.servicemap.mapper")
public class ServiceMapApplication { public class ServiceMapApplication {
public static void main(String[] args) { public static void main(String[] args) {

@ -0,0 +1,21 @@
package com.taxi.servicemap.controller;
import com.internal.dto.ResponseResult;
import com.taxi.servicemap.service.DicDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DicDistrictController {
@Autowired
private DicDistrictService dicDistrictService;
@GetMapping("/dic-district")
public ResponseResult initDicDistrict(String keywords){
return dicDistrictService.initDicDistrict(keywords);
}
}

@ -2,7 +2,7 @@ package com.taxi.servicemap.controller;
import com.internal.dto.ResponseResult; import com.internal.dto.ResponseResult;
import com.internal.request.ForecastPriceDTO; import com.internal.request.ForecastPriceDTO;
import com.taxi.servicemap.service.DirectionSevice; import com.taxi.servicemap.service.DirectionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/direction") @RequestMapping("/direction")
public class DriectionController { public class DriectionController {
@Autowired @Autowired
private DirectionSevice directionSevice; private DirectionService directionSevice;
@GetMapping("/driving") @GetMapping("/driving")
public ResponseResult deiving(@RequestBody ForecastPriceDTO forecastPriceDTO) { public ResponseResult deiving(@RequestBody ForecastPriceDTO forecastPriceDTO) {

@ -1,8 +1,15 @@
package com.taxi.servicemap.controller; package com.taxi.servicemap.controller;
import com.internal.dto.DicDistrict;
import com.taxi.servicemap.mapper.DicDistrictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController @RestController
public class TestController { public class TestController {
@ -10,4 +17,16 @@ public class TestController {
public String test(){ public String test(){
return "service map"; return "service map";
} }
@Autowired
DicDistrictMapper mapper;
@GetMapping("/testMap")
public String testMap(){
Map<String,Object> map = new HashMap<>();
map.put("address_code","11000");
List<DicDistrict> dicDistrictList = mapper.selectByMap(map);
System.out.println(dicDistrictList);
return "test-map";
}
} }

@ -0,0 +1,9 @@
package com.taxi.servicemap.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.internal.dto.DicDistrict;
import org.springframework.stereotype.Repository;
@Repository
public interface DicDistrictMapper extends BaseMapper<DicDistrict> {
}

@ -0,0 +1,31 @@
package com.taxi.servicemap.service;
import com.internal.contant.AmapConfigConstant;
import com.internal.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class DicDistrictService {
//?keywords=%E4%B8%AD%E5%9B%BD&subdistrict=3&key=01d85ea8f7db65efc370cfec18ff6397
@Value("${amap.key}")
private String amapKey;
public ResponseResult initDicDistrict(String keywords){
//拼接请求的URL
StringBuilder url = new StringBuilder();
url.append(AmapConfigConstant.DISTRICT_URL);
url.append("?");
url.append("keywords="+keywords);
url.append("&");
url.append("subdistrict=3");
url.append("&");
url.append("key="+amapKey);
System.out.println(url.toString());
return ResponseResult.success();
}
}

@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class DirectionSevice { public class DirectionService {
@Autowired @Autowired
private MapDirectionClient mapDirectionClient; private MapDirectionClient mapDirectionClient;

@ -2,6 +2,11 @@ server:
port: 8085 port: 8085
spring: spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/service-map?characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: topsun123
cloud: cloud:
nacos: nacos:
discovery: discovery:

@ -2,6 +2,11 @@ server:
port: 8085 port: 8085
spring: spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/service-map?characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: topsun123
cloud: cloud:
nacos: nacos:
discovery: discovery:

Loading…
Cancel
Save