parent
c76981e2e2
commit
08c2365411
@ -0,0 +1,18 @@
|
|||||||
|
package com.internal.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* "code": 1,
|
||||||
|
* "message": "success",
|
||||||
|
* "data": {
|
||||||
|
* "trid": "20",
|
||||||
|
* "trname": null
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TrackResponse {
|
||||||
|
private String trid;
|
||||||
|
private String trname;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.taxi.servicemap.controller;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.taxi.servicemap.service.TrackService;
|
||||||
|
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("/track")
|
||||||
|
public class TrackController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TrackService trackService;
|
||||||
|
|
||||||
|
@PostMapping("/addTrack")
|
||||||
|
public ResponseResult addTrack(String tid){
|
||||||
|
return trackService.addTrack(tid);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.taxi.servicemap.remote;
|
||||||
|
|
||||||
|
import com.internal.contant.AmapConfigConstant;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.dto.TrackResponse;
|
||||||
|
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 TrackClient {
|
||||||
|
@Value("${amap.key}")
|
||||||
|
private String amapKey;
|
||||||
|
|
||||||
|
@Value("${amap.sid}")
|
||||||
|
private String sid;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
public ResponseResult addTrack(String tid){
|
||||||
|
//拼接请求的URL
|
||||||
|
StringBuilder url = new StringBuilder();
|
||||||
|
url.append(AmapConfigConstant.TRACK_MAP_ADD_URL);
|
||||||
|
url.append("?");
|
||||||
|
url.append("key="+amapKey);
|
||||||
|
url.append("&");
|
||||||
|
url.append("sid="+sid);
|
||||||
|
url.append("&");
|
||||||
|
url.append("tid="+tid);
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* "data": {
|
||||||
|
* "trname": "测试轨迹",
|
||||||
|
* "trid": 80
|
||||||
|
* },
|
||||||
|
* "errcode": 10000,
|
||||||
|
* "errdetail": null,
|
||||||
|
* "errmsg": "OK"
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
ResponseEntity<String> forEntity =
|
||||||
|
restTemplate.postForEntity(url.toString(),null,String.class);
|
||||||
|
String bodyStr = forEntity.getBody();
|
||||||
|
TrackResponse terminalResponse = new TrackResponse();
|
||||||
|
JSONObject result = JSONObject.fromObject(bodyStr);
|
||||||
|
if(result.has("data")){
|
||||||
|
JSONObject data = result.getJSONObject("data");
|
||||||
|
if(!data.isNullObject() && data.has("trid")){
|
||||||
|
String trid = data.getString("trid");
|
||||||
|
terminalResponse.setTrid(trid);
|
||||||
|
}
|
||||||
|
if(!data.isNullObject() && data.has("trname")){
|
||||||
|
String trname = data.getString("trname");
|
||||||
|
terminalResponse.setTrname(trname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResponseResult.success(terminalResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.taxi.servicemap.service;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.taxi.servicemap.remote.TrackClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TrackService {
|
||||||
|
@Autowired
|
||||||
|
private TrackClient trackClient;
|
||||||
|
|
||||||
|
public ResponseResult addTrack(String tid){
|
||||||
|
return trackClient.addTrack(tid);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue