parent
1b66257c05
commit
693e397ec5
@ -0,0 +1,20 @@
|
||||
package com.internal.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* {
|
||||
* "data": {
|
||||
* "name": "车辆1",
|
||||
* "tid": 685621293,
|
||||
* "sid": 936178
|
||||
* },
|
||||
* "errcode": 10000,
|
||||
* "errdetail": null,
|
||||
* "errmsg": "OK"
|
||||
* }
|
||||
*/
|
||||
@Data
|
||||
public class TerminalResponse {
|
||||
private String tid;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.taxi.servicemap.controller;
|
||||
|
||||
import com.internal.dto.ResponseResult;
|
||||
import com.taxi.servicemap.service.TerminalService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/terminal")
|
||||
public class TerminalController {
|
||||
@Autowired
|
||||
TerminalService terminalService;
|
||||
@PostMapping("/addTerminal")
|
||||
public ResponseResult addTerminal(String name){
|
||||
return terminalService.addTerminal(name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.taxi.servicemap.remote;
|
||||
|
||||
import com.internal.contant.AmapConfigConstant;
|
||||
import com.internal.dto.ResponseResult;
|
||||
import com.internal.dto.ServiceMapResponse;
|
||||
import com.internal.dto.TerminalResponse;
|
||||
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 TerminalClient {
|
||||
@Value("${amap.key}")
|
||||
private String amapKey;
|
||||
|
||||
@Value("${amap.sid}")
|
||||
private String sid;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
/**
|
||||
* {
|
||||
* "code": 1,
|
||||
* "message": "success",
|
||||
* "data": {
|
||||
* "tid": "685651163"
|
||||
* }
|
||||
* }
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public ResponseResult addTerminal(String name){
|
||||
//拼接请求的URL
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append(AmapConfigConstant.TERMINAL_MAP_ADD_URL);
|
||||
url.append("?");
|
||||
url.append("key="+amapKey);
|
||||
url.append("&");
|
||||
url.append("sid="+sid);
|
||||
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);
|
||||
TerminalResponse terminalResponse = new TerminalResponse();
|
||||
/**
|
||||
* {
|
||||
* "data": {
|
||||
* "name": "车辆1",
|
||||
* "tid": 685621293,
|
||||
* "sid": 936178
|
||||
* },
|
||||
* "errcode": 10000,
|
||||
* "errdetail": null,
|
||||
* "errmsg": "OK"
|
||||
* }
|
||||
*/
|
||||
if(result.has("data")){
|
||||
JSONObject data = result.getJSONObject("data");
|
||||
if(data != null && data.has("tid")){
|
||||
String sid = data.getString("tid");
|
||||
terminalResponse.setTid(sid);
|
||||
}
|
||||
}
|
||||
return ResponseResult.success(terminalResponse);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.taxi.servicemap.service;
|
||||
|
||||
import com.internal.dto.ResponseResult;
|
||||
import com.taxi.servicemap.remote.TerminalClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TerminalService {
|
||||
@Autowired
|
||||
TerminalClient terminalClient;
|
||||
|
||||
public ResponseResult addTerminal(String name){
|
||||
return terminalClient.addTerminal(name);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue