1、新增3个方法:地名地址搜索服务的Suggest操作/suggest,地名地址搜索服务的Geocode操作/geocode,地名地址搜索服务的reverseGeocode操作/reverseGeocode

This commit is contained in:
yitonglei 2022-05-06 17:20:01 +08:00
parent 9d4c9a9b3b
commit f5673ec512
3 changed files with 127 additions and 0 deletions

View File

@ -11,9 +11,12 @@ import com.hisense.monitormanage.mapper.ScenicMapper;
import com.hisense.monitormanage.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("api/project")
@ -79,4 +82,49 @@ public class Controller {
return "startScenic finish";
}
//根据用户已输入的文字请求输入建议信息
//text:用户输入的文字信息,必填
//maxSuggestions最大建议数量0~10默认2
@RequestMapping("suggest")
public Result suggest(
@RequestParam(value ="text") String text,
@RequestParam(value = "maxSuggestions",required = false,defaultValue = "2") Integer maxSuggestions
){
Map<String,Object> map = new HashMap<>();
map.put("text",text);
map.put("maxSuggestions",maxSuggestions);
return monitorService.suggest(map);
}
//根据用户已输入的文字请求匹配的地址信息
//singleLine:用户输入的文字性地名地址信息必填
//maxSuggestions最大建议数量0~10默认2
//magicKey:地名地址唯一ID,Suggest操作返回的JSON数组中包含的magicKey
//outSR:坐标系信息,包含"wkid"属性是表示空间参考的ID示例{ "wkid":4490 }
@RequestMapping("geocode")
public Result geocode(
@RequestParam(value="singleLine") String singleLine,
@RequestParam(value = "maxSuggestions",required = false,defaultValue = "2") Integer maxSuggestions,
@RequestParam(value = "magicKey",required = false,defaultValue = "") String magicKey,
@RequestParam(value = "outSR",required = false,defaultValue = "") String outSR
){
Map<String,Object> map = new HashMap<>();
map.put("SingleLine",singleLine);
map.put("maxSuggestions",maxSuggestions);
map.put("magicKey",magicKey);
map.put("outSR",outSR);
return monitorService.geocode(map);
}
//根据用户已输入的坐标请求附近的地址信息
//location:坐标,必填,请注意编码示例{"x":120.40632244540544,"y":36.08136665300961,"spatialReference":{"wkid":4490,"latestWkid":4490}}
@RequestMapping("reverseGeocode")
public Result reverseGeocode(
@RequestParam(value="location") String location
){
Map<String,Object> map = new HashMap<>();
map.put("location",location);
return monitorService.reverseGeocode(map);
}
}

View File

@ -4,6 +4,7 @@ import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
import com.hisense.monitormanage.entity.Camera;
import com.hisense.monitormanage.entity.CameraScenic;
import com.hisense.monitormanage.entity.Result;
import com.hisense.monitormanage.mapper.CameraMapper;
import com.hisense.monitormanage.mapper.CameraScenicMapper;
import com.hisense.monitormanage.mapper.ScenicMapper;
@ -51,6 +52,8 @@ public class MonitorService {
private String fileDir;
@Value("${hwx.file.pic-host}")
private String picHost;
@Value("iOgQotfgfyLvhj6WgfDTpq7F")
private String key;
// final private String userName = "chengshiyunnao";
// final private String password = "QDyjj@2021";
@ -289,6 +292,66 @@ public class MonitorService {
}
//地名地址搜索服务的Suggest操作
public Result suggest(Map<String,Object> map){
String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/suggest?"+"text={text}&key={key}";
map.put("key",key);
ResponseEntity<String> responseEntity;
try{
responseEntity = restTemplate.getForEntity(url, String.class,map);
HttpStatus statusCode = responseEntity.getStatusCode();
if(statusCode.is2xxSuccessful()){
return Result.success(responseEntity.getBody());
}else{
return Result.error(String.valueOf(statusCode.value()));
}
} catch (Exception e){
log.info("[suggest] exception:{}",e.getMessage());
return Result.error(e.getMessage());
}
}
//地名地址搜索服务的Geocode操作
public Result geocode(Map<String,Object> map){
String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/findAddressCandidates?"
+"SingleLine={SingleLine}&key={key}";
map.put("key",key);
ResponseEntity<String> responseEntity;
try{
responseEntity = restTemplate.getForEntity(url, String.class,map);
HttpStatus statusCode = responseEntity.getStatusCode();
if(statusCode.is2xxSuccessful()){
return Result.success(responseEntity.getBody());
}else{
return Result.error(String.valueOf(statusCode.value()));
}
} catch (Exception e){
log.info("[geocode] exception:{}",e.getMessage());
return Result.error(e.getMessage());
}
}
//地名地址搜索服务的reverseGeocode操作
public Result reverseGeocode(Map<String,Object> map){
String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/reverseGeocode?"
+"location={location}&key={key}";
map.put("key",key);
ResponseEntity<String> responseEntity;
try {
responseEntity = restTemplate.getForEntity(url, String.class, map);
HttpStatus statusCode = responseEntity.getStatusCode();
if(statusCode.is2xxSuccessful()){
return Result.success(responseEntity.getBody());
}else{
return Result.error(String.valueOf(statusCode.value()));
}
}catch (HttpClientErrorException e){
log.info("[reverseGeocode] exception:{}",e.getMessage());
return Result.error(e.getMessage());
}
}
}

View File

@ -1,13 +1,29 @@
package com.hisense.monitormanage;
import com.hisense.monitormanage.service.MonitorService;
import lombok.AllArgsConstructor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
import java.util.Map;
@SpringBootTest
class MonitorManageApplicationTests {
@Autowired
private MonitorService monitorService;
@Test
void contextLoads() {
}
@Test
public void reverseGeocodeTest(){
String location = "location";
Map<String,Object> map = new HashMap<>();
map.put("location",location);
monitorService.reverseGeocode(map);
}
}