Compare commits
2 Commits
1b66257c05
...
c76981e2e2
Author | SHA1 | Date |
---|---|---|
|
c76981e2e2 | 2 years ago |
|
693e397ec5 | 2 years ago |
@ -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,15 @@
|
|||||||
|
package com.taxi.servicedriveruser.remote;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.dto.TerminalResponse;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
@FeignClient("service-map")
|
||||||
|
public interface ServiceMapClient {
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST,value = "/terminal/addTerminal")
|
||||||
|
ResponseResult<TerminalResponse> addTerminal(@RequestParam String name);
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.taxi.servicemap.controller;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.dto.TerminalResponse;
|
||||||
|
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<TerminalResponse> 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<TerminalResponse> 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,17 @@
|
|||||||
|
package com.taxi.servicemap.service;
|
||||||
|
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.dto.TerminalResponse;
|
||||||
|
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<TerminalResponse> addTerminal(String name){
|
||||||
|
return terminalClient.addTerminal(name);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue