Compare commits

...

2 Commits

@ -20,4 +20,8 @@ public class AmapConfigConstant {
*
*/
public static final String SERVICE_MAP_ADD_URL = "https://tsapi.amap.com/v1/track/service/add";
/**
*
*/
public static final String TERMINAL_MAP_ADD_URL = "https://tsapi.amap.com/v1/track/terminal/add";
}

@ -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;
}

@ -45,6 +45,16 @@
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies>
</project>

@ -3,8 +3,10 @@ package com.taxi.servicedriveruser;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients
@MapperScan("com.taxi.servicedriveruser.mapper")
public class ServiceDriverUserApplication {

@ -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);
}

@ -2,7 +2,9 @@ package com.taxi.servicedriveruser.service;
import com.internal.dto.Car;
import com.internal.dto.ResponseResult;
import com.internal.dto.TerminalResponse;
import com.taxi.servicedriveruser.mapper.CarMapper;
import com.taxi.servicedriveruser.remote.ServiceMapClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -13,13 +15,22 @@ public class CarService {
@Autowired
private CarMapper carMapper;
@Autowired
private ServiceMapClient serviceMapClient;
public ResponseResult addCar(Car car) {
LocalDateTime localDateTime = LocalDateTime.now();
car.setGmtCreate(localDateTime);
car.setGmtModified(localDateTime);
//获取此车辆对应的tid
ResponseResult<TerminalResponse> responseResult = serviceMapClient.addTerminal(car.getVehicleNo());
String tid = responseResult.getData().getTid();
car.setTid(tid);
carMapper.insert(car);
return ResponseResult.success();
}
}

@ -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);
}
}

@ -16,3 +16,4 @@ spring:
amap:
key: 01d85ea8f7db65efc370cfec18ff6397
sid: 936137

@ -16,3 +16,4 @@ spring:
amap:
key: 01d85ea8f7db65efc370cfec18ff6397
sid: 936137
Loading…
Cancel
Save