Compare commits

...

2 Commits

@ -32,4 +32,8 @@ public class AmapConfigConstant {
*
*/
public static final String POINT_UPLOAD_MAP_ADD_URL = "https://tsapi.amap.com/v1/track/point/upload";
/**
*
*/
public static final String TERMINAL_AROUND_SEARCH_URL = "https://tsapi.amap.com/v1/track/terminal/aroundsearch";
}

@ -0,0 +1,36 @@
package com.internal.dto;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class TerminalAroundSearch {
/**
* {
* "createtime": 1683779426299,
* "desc": "1656517091884187650",
* "locatetime": 1683799295000,
* "location": {
* "accuracy": 550.0,
* "direction": 511.0,
* "distance": 0,
* "height": null,
* "latitude": 39.90923,
* "longitude": 116.397428,
* "speed": 255.0,
* "trackProps": null
* },
* "name": "京N86555",
* "props": null,
* "tid": 686521656
* }
*/
private String tid;
private Long carId;
private String name;
private LocalDateTime locatetime;
private LocalDateTime createtime;
}

@ -1,6 +1,7 @@
package com.taxi.servicemap.controller;
import com.internal.dto.ResponseResult;
import com.internal.dto.TerminalAroundSearch;
import com.internal.dto.TerminalResponse;
import com.taxi.servicemap.service.TerminalService;
import org.springframework.beans.factory.annotation.Autowired;
@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/terminal")
public class TerminalController {
@ -18,4 +21,10 @@ public class TerminalController {
return terminalService.addTerminal(name,desc);
}
@PostMapping("/aroundsearch")
public ResponseResult<List<TerminalAroundSearch>> aroundsearch(String center, Integer radius){
return terminalService.aroundsearch(center,radius);
}
}

@ -2,8 +2,9 @@ package com.taxi.servicemap.remote;
import com.internal.contant.AmapConfigConstant;
import com.internal.dto.ResponseResult;
import com.internal.dto.ServiceMapResponse;
import com.internal.dto.TerminalAroundSearch;
import com.internal.dto.TerminalResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -11,6 +12,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
@Service
public class TerminalClient {
@Value("${amap.key}")
@ -22,15 +26,54 @@ public class TerminalClient {
@Autowired
private RestTemplate restTemplate;
/**
* https://lbs.amap.com/api/track/lieying-kaifa/api/terminal_search
*
* @param center
* @param radius
* @return
*/
public ResponseResult<List<TerminalAroundSearch>> aroundsearch(String center,Integer radius){
//拼接请求的URL
StringBuilder url = new StringBuilder();
url.append(AmapConfigConstant.TERMINAL_AROUND_SEARCH_URL);
url.append("?");
url.append("key="+amapKey);
url.append("&");
url.append("sid="+sid);
url.append("&");
url.append("center="+center);
url.append("&");
url.append("radius="+radius);
System.out.println("周边搜索终端URL"+url.toString());
ResponseEntity<String> forEntity =
restTemplate.postForEntity(url.toString(),null,String.class);
String bodyStr = forEntity.getBody();
JSONObject result = JSONObject.fromObject(bodyStr);
System.out.println("周边搜索终端的结果:"+bodyStr);
List<TerminalAroundSearch> list = new ArrayList<>();
if(result.has("data")){
JSONObject data = result.getJSONObject("data");
JSONArray jsonArray = data.getJSONArray("results");
for (int index = 0 ;index < jsonArray.size();index++){
JSONObject jsonObject = jsonArray.getJSONObject(index);
TerminalAroundSearch terminalAroundSearch = new TerminalAroundSearch();
terminalAroundSearch.setTid(jsonObject.getString("tid"));
terminalAroundSearch.setCarId(jsonObject.getLong("desc"));
list.add(terminalAroundSearch);
}
return ResponseResult.success(list);
}
return ResponseResult.success();
}
/**
* {
* "code": 1,
* "message": "success",
* "data": {
* "tid": "685651163"
* }
* }
*
* @param name
* @param desc
* @return
*/
public ResponseResult<TerminalResponse> addTerminal(String name,String desc){

@ -1,11 +1,14 @@
package com.taxi.servicemap.service;
import com.internal.dto.ResponseResult;
import com.internal.dto.TerminalAroundSearch;
import com.internal.dto.TerminalResponse;
import com.taxi.servicemap.remote.TerminalClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TerminalService {
@Autowired
@ -14,4 +17,8 @@ public class TerminalService {
public ResponseResult<TerminalResponse> addTerminal(String name,String desc){
return terminalClient.addTerminal(name,desc);
}
public ResponseResult<List<TerminalAroundSearch>> aroundsearch(String center, Integer radius){
return terminalClient.aroundsearch(center,radius);
}
}

@ -15,5 +15,5 @@ spring:
name: service-map
amap:
key:
key: 01d85ea8f7db65efc370cfec18ff6397
sid: 936137
Loading…
Cancel
Save