diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index 09c41e8..da57228 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -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 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 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 map = new HashMap<>(); + map.put("location",location); + return monitorService.reverseGeocode(map); + } } diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index 83cbbed..e654517 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -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 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 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 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 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 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 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()); + } + } } diff --git a/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java b/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java index 7ff4910..0068739 100644 --- a/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java +++ b/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java @@ -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 map = new HashMap<>(); + map.put("location",location); + monitorService.reverseGeocode(map); + } + }