service-map集成终端搜索服务

main
topsun 2 years ago
parent 3aabf0c7f7
commit c15224eb51

@ -28,8 +28,8 @@ public class TerminalAroundSearch {
* } * }
*/ */
private String desc;
private String tid; private String tid;
private Long carId;
private String name; private String name;
private LocalDateTime locatetime; private LocalDateTime locatetime;
private LocalDateTime createtime; private LocalDateTime createtime;

@ -1,6 +1,7 @@
package com.taxi.servicemap.controller; package com.taxi.servicemap.controller;
import com.internal.dto.ResponseResult; import com.internal.dto.ResponseResult;
import com.internal.dto.TerminalAroundSearch;
import com.internal.dto.TerminalResponse; import com.internal.dto.TerminalResponse;
import com.taxi.servicemap.service.TerminalService; import com.taxi.servicemap.service.TerminalService;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
@RequestMapping("/terminal") @RequestMapping("/terminal")
public class TerminalController { public class TerminalController {
@ -20,7 +23,7 @@ public class TerminalController {
@PostMapping("/aroundsearch") @PostMapping("/aroundsearch")
public ResponseResult aroundsearch(String center,Integer radius){ public ResponseResult<List<TerminalAroundSearch>> aroundsearch(String center, Integer radius){
return terminalService.aroundsearch(center,radius); return terminalService.aroundsearch(center,radius);
} }

@ -12,6 +12,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
@ -33,7 +34,7 @@ public class TerminalClient {
* @param radius * @param radius
* @return * @return
*/ */
public ResponseResult aroundsearch(String center,Integer radius){ public ResponseResult<List<TerminalAroundSearch>> aroundsearch(String center,Integer radius){
//拼接请求的URL //拼接请求的URL
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
url.append(AmapConfigConstant.TERMINAL_AROUND_SEARCH_URL); url.append(AmapConfigConstant.TERMINAL_AROUND_SEARCH_URL);
@ -52,15 +53,19 @@ public class TerminalClient {
String bodyStr = forEntity.getBody(); String bodyStr = forEntity.getBody();
JSONObject result = JSONObject.fromObject(bodyStr); JSONObject result = JSONObject.fromObject(bodyStr);
System.out.println("周边搜索终端的结果:"+bodyStr); System.out.println("周边搜索终端的结果:"+bodyStr);
List<TerminalAroundSearch> list = new ArrayList<>();
if(result.has("data")){ if(result.has("data")){
JSONObject data = result.getJSONObject("data"); JSONObject data = result.getJSONObject("data");
// int count = data.getInt("count"); JSONArray jsonArray = data.getJSONArray("results");
TerminalAroundSearch terminalAroundSearch = new TerminalAroundSearch(); for (int index = 0 ;index < jsonArray.size();index++){
List<TerminalAroundSearch> jsonArray = data.getJSONArray("results"); JSONObject jsonObject = jsonArray.getJSONObject(index);
ResponseResult.success(ResponseResult.success()); TerminalAroundSearch terminalAroundSearch = new TerminalAroundSearch();
terminalAroundSearch.setTid(jsonObject.getString("tid"));
terminalAroundSearch.setCarId(jsonObject.getLong("desc"));
list.add(terminalAroundSearch);
}
return ResponseResult.success(list);
} }
return ResponseResult.success(); return ResponseResult.success();
} }

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

Loading…
Cancel
Save