parent
23f00f568b
commit
1b66257c05
@ -0,0 +1,8 @@
|
||||
package com.internal.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServiceMapResponse {
|
||||
private String sid;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.taxi.servicemap.remote;
|
||||
|
||||
import com.internal.contant.AmapConfigConstant;
|
||||
import com.internal.dto.ResponseResult;
|
||||
import com.internal.dto.ServiceMapResponse;
|
||||
import com.taxi.servicemap.service.ServiceMapService;
|
||||
import net.sf.json.JSONObject;
|
||||
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
|
||||
public class ServiceClient {
|
||||
@Value("${amap.key}")
|
||||
private String amapKey;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
public ResponseResult addService(String name){
|
||||
//拼接请求的URL
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append(AmapConfigConstant.SERVICE_MAP_ADD_URL);
|
||||
url.append("?");
|
||||
url.append("key="+amapKey);
|
||||
url.append("&");
|
||||
url.append("name="+name);
|
||||
|
||||
ResponseEntity<String> forEntity =
|
||||
restTemplate.postForEntity(url.toString(),null,String.class);
|
||||
String bodyStr = forEntity.getBody();
|
||||
JSONObject result = JSONObject.fromObject(bodyStr);
|
||||
ServiceMapResponse serviceMapResponse = new ServiceMapResponse();
|
||||
if(result.has("data")){
|
||||
JSONObject data = result.getJSONObject("data");
|
||||
if(data != null && data.has("sid")){
|
||||
String sid = data.getString("sid");
|
||||
serviceMapResponse.setSid(sid);
|
||||
}
|
||||
}
|
||||
return ResponseResult.success(serviceMapResponse);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.taxi.servicemap.service;
|
||||
|
||||
import com.internal.dto.ResponseResult;
|
||||
import com.taxi.servicemap.remote.ServiceClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ServiceMapService {
|
||||
@Autowired
|
||||
ServiceClient serviceClient;
|
||||
/**
|
||||
* 创建服务
|
||||
* @return
|
||||
*/
|
||||
public ResponseResult addService(String name){
|
||||
return serviceClient.addService(name);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"data": {
|
||||
"name": "飞滴出行service",
|
||||
"sid": 936178
|
||||
},
|
||||
"errcode": 10000,
|
||||
"errdetail": null,
|
||||
"errmsg": "OK"
|
||||
}
|
||||
|
||||
//终端管理
|
||||
{
|
||||
"data": {
|
||||
"name": "车辆1",
|
||||
"tid": 685615847,
|
||||
"sid": 936178
|
||||
},
|
||||
"errcode": 10000,
|
||||
"errdetail": null,
|
||||
"errmsg": "OK"
|
||||
}
|
Loading…
Reference in new issue