parent
514bd7bb8c
commit
51dbb0826a
@ -0,0 +1,12 @@
|
|||||||
|
package com.internal.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PointDTO {
|
||||||
|
private String location;
|
||||||
|
private String locatetime;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.internal.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PointRequest {
|
||||||
|
|
||||||
|
private String tid;
|
||||||
|
private String trid;
|
||||||
|
private PointDTO[] points;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.taxi.servicemap.controller;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.request.PointRequest;
|
||||||
|
import com.taxi.servicemap.service.PointService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/point")
|
||||||
|
public class PointController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PointService pointService;
|
||||||
|
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public ResponseResult pointUpload(@RequestBody PointRequest pointRequest){
|
||||||
|
|
||||||
|
return pointService.pointUpload(pointRequest);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.taxi.servicemap.remote;
|
||||||
|
|
||||||
|
import com.internal.contant.AmapConfigConstant;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.dto.TrackResponse;
|
||||||
|
import com.internal.request.PointDTO;
|
||||||
|
import com.internal.request.PointRequest;
|
||||||
|
import net.sf.json.JSONArray;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PointClient {
|
||||||
|
@Value("${amap.key}")
|
||||||
|
private String amapKey;
|
||||||
|
|
||||||
|
@Value("${amap.sid}")
|
||||||
|
private String sid;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public ResponseResult pointUpload(@RequestBody PointRequest pointRequest){
|
||||||
|
|
||||||
|
//拼接请求的URL
|
||||||
|
StringBuilder url = new StringBuilder();
|
||||||
|
url.append(AmapConfigConstant.POINT_UPLOAD_MAP_ADD_URL);
|
||||||
|
url.append("?");
|
||||||
|
url.append("key="+amapKey);
|
||||||
|
url.append("&");
|
||||||
|
url.append("sid="+sid);
|
||||||
|
url.append("&");
|
||||||
|
url.append("tid="+pointRequest.getTid());
|
||||||
|
url.append("&");
|
||||||
|
url.append("trid="+pointRequest.getTrid());
|
||||||
|
PointDTO[] arryPoint = pointRequest.getPoints();
|
||||||
|
String arryPointJSON = JSONArray.fromObject(arryPoint).toString();
|
||||||
|
System.out.println(arryPointJSON);
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* "data": {
|
||||||
|
* "errorpoints": []
|
||||||
|
* },
|
||||||
|
* "errcode": 10000,
|
||||||
|
* "errdetail": null,
|
||||||
|
* "errmsg": "OK"
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
|
params.put("points",arryPoint);
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
//设置访问的Entity
|
||||||
|
HttpEntity requestEntity = new HttpEntity<>(params, headers);//params 请求体内容, headers请求头内容
|
||||||
|
System.out.println("高德地图请求:"+url.toString());
|
||||||
|
JSONObject jsonObject =
|
||||||
|
restTemplate.postForObject(url.toString(),requestEntity,JSONObject.class);
|
||||||
|
System.out.println("高德地图相应:"+jsonObject);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.taxi.servicemap.service;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.request.PointRequest;
|
||||||
|
import com.taxi.servicemap.remote.PointClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PointService {
|
||||||
|
@Autowired
|
||||||
|
private PointClient pointClient;
|
||||||
|
|
||||||
|
public ResponseResult pointUpload(@RequestBody PointRequest pointRequest){
|
||||||
|
return pointClient.pointUpload(pointRequest);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue