parent
15afa8326f
commit
2452a39516
@ -0,0 +1,38 @@
|
|||||||
|
package com.taxi.servicemap.remote;
|
||||||
|
|
||||||
|
import com.internal.contant.AmapConfigConstant;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class MapDicDistrictClient {
|
||||||
|
|
||||||
|
@Value("${amap.key}")
|
||||||
|
private String amapKey;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public String dicDistrict(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());
|
||||||
|
ResponseEntity<String> forEntity =
|
||||||
|
restTemplate.getForEntity(url.toString(),String.class);
|
||||||
|
|
||||||
|
return forEntity.getBody();
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +1,23 @@
|
|||||||
package com.taxi.servicemap.service;
|
package com.taxi.servicemap.service;
|
||||||
|
|
||||||
import com.internal.contant.AmapConfigConstant;
|
|
||||||
import com.internal.dto.ResponseResult;
|
import com.internal.dto.ResponseResult;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import com.taxi.servicemap.remote.MapDicDistrictClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DicDistrictService {
|
public class DicDistrictService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
//?keywords=%E4%B8%AD%E5%9B%BD&subdistrict=3&key=01d85ea8f7db65efc370cfec18ff6397
|
private MapDicDistrictClient mapDicDistrictClient;
|
||||||
|
|
||||||
@Value("${amap.key}")
|
|
||||||
private String amapKey;
|
|
||||||
|
|
||||||
|
|
||||||
public ResponseResult initDicDistrict(String keywords){
|
public ResponseResult initDicDistrict(String keywords){
|
||||||
//拼接请求的URL
|
//拼接请求地图
|
||||||
StringBuilder url = new StringBuilder();
|
String dicDistrictObj = mapDicDistrictClient.dicDistrict(keywords);
|
||||||
url.append(AmapConfigConstant.DISTRICT_URL);
|
System.out.println(dicDistrictObj);
|
||||||
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();
|
return ResponseResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue