suerprisePlus
2024-08-28 5b14811aaeb72e828d948068e899c65877aaca9a
API名称:[周边属性查询] 接口添加
已修改5个文件
133 ■■■■ 文件已修改
pom.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yb/controller/XzController.java 127 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
target/classes/com/yb/controller/XzController.class 补丁 | 查看 | 原始文档 | blame | 历史
target/ollama-ai-0.0.1-SNAPSHOT.jar 补丁 | 查看 | 原始文档 | blame | 历史
target/ollama-ai-0.0.1-SNAPSHOT.jar.original 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -84,7 +84,11 @@
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.locationtech.jts</groupId>
            <artifactId>jts-core</artifactId>
            <version>1.18.2</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
src/main/java/com/yb/controller/XzController.java
@@ -13,12 +13,16 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.io.WKTWriter;
import org.locationtech.jts.operation.buffer.BufferOp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -46,6 +50,9 @@
    @Value("${spring.geographical.token}")
    String token;
    private JSONObject jsonObject;
    private JSONObject dataObjject;
    private Coordinate coord;
    private Object filObj;
    @PostMapping("/poiMap")
    @Operation(summary = "显示地点")
@@ -55,6 +62,109 @@
        hash.put("func", "poiMap");
        hash.put("mid", mid);
        ReqEntity reqEntity = new ReqEntity();
        String item = getQueryFiled(place);
        JSONObject obj = JSONObject.parseObject(item);
        reqEntity.setX(obj.getString("lon"));
        reqEntity.setY(obj.getString("lat"));
//        System.out.print(obj);
        reqEntity.setPlace(obj.getString("enti_name"));
        System.out.println("rec message:" +reqEntity);
        hash.put("poi", reqEntity);
        String message = JSON.toJSONString(hash);
        webSocketController.sendAllMessage(message);
        return R.ok(hash);
    }
    @PostMapping("/aroundPoi")
    @Operation(summary = "显示地点")
    public R aroundPoi(@Parameter String place, @Parameter String mid, @Parameter String type, @Parameter int radius) throws Exception {
        System.out.println("rec message:" + place + "  mid:" + mid + "  type:" + type + "  radius:" + radius);
        HashMap<String, Object> hash = new HashMap<>();
        hash.put("func", "aroundpoi");
        hash.put("mid", mid);
        String item = getQueryFiled(place);
        JSONObject obj = JSONObject.parseObject(item);
        Double lon = Double.parseDouble(obj.getString("lon"));
        Double lat = Double.parseDouble(obj.getString("lat"));
        String wkt = getWKt(lon,lat,radius);
        String itemList = getQueryAround(type,wkt);
//        System.out.print("ces: "+itemList);
        JSONArray dataArray =JSONArray.parseArray(itemList);
      ArrayList<ReqEntity> arrayList= new ArrayList<>();
        for(int i =0;i< dataArray.size();i++ ){
            Object element = dataArray.get(i);
            if (element instanceof JSONObject) {
                JSONObject jsonObject = (JSONObject) element;
                ReqEntity reqEntity= new ReqEntity();
                reqEntity.setX(jsonObject.getString("lon"));
                reqEntity.setY(jsonObject.getString("lat"));
                reqEntity.setPlace(jsonObject.getString("enti_name"));
                arrayList.add(reqEntity);
            }
        }
        System.out.println("rec message:" +arrayList);
        hash.put("poi", arrayList);
        String message = JSON.toJSONString(hash);
        webSocketController.sendAllMessage(message);
        return R.ok(hash);
    }
    public String getWKt(double lon, double lat, int radius) {
        // 创建一个坐标点
        Coordinate coord = new Coordinate(lon, lat);
        // 创建GeometryFactory实例,并指定坐标参考系统为WGS84
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
        // 使用坐标创建一个点
        Point point = geometryFactory.createPoint(coord);
        // 创建BufferOp实例,用于生成缓冲区
        BufferOp bufferOp = new BufferOp(point);
        int dis = 500;
        if (radius != 0) {
            dis = radius;
        }
        // 设置缓冲区距离为500米
        Geometry bufferedGeometry = bufferOp.getResultGeometry(dis);
        // 创建WKTWriter实例,用于将Geometry转换为WKT格式
//        WKTWriter wktWriter = new WKTWriter();
        // 将缓冲区Geometry转换为WKT格式
//        String wkt = wktWriter.write(bufferedGeometry);
        // 输出WKT
//        System.out.println("WKT: " + wkt);
        Envelope envelope = bufferedGeometry.getEnvelopeInternal();
        double [] wkt = new double[4];
        wkt[0]=envelope.getMinX();
        wkt[1]=envelope.getMinY();
        wkt[2]=envelope.getMaxX();
        wkt[3]=envelope.getMaxY();
        String arrayAsString = Arrays.toString(wkt);
        System.out.println("arrayAsString: " + arrayAsString);
        return arrayAsString;
    }
    public  String getQueryAround(String type,String wkt) throws Exception {
        String query = "sjnr  like '%" + type + "%'" + "";
        String key = getPublickey();
        String encrypt = RsaHelper.encrypt(key, query);
        HashMap formData = new HashMap<>();
        formData.put("token", token);
        formData.put("start", "1");
        formData.put("count", "0");
        formData.put("containCount", "true");
        formData.put("layerid", layerId);
        formData.put("dbid", dbid);
        formData.put("where", encrypt);
        formData.put("box", wkt);
        String jsonString = entityHttpUtil.getPostMessage(queryEntity, formData);
        JSONObject jsonObject = JSON.parseObject(jsonString);
        JSONObject dataObjject = jsonObject.getJSONObject("data");
        JSONArray dataArray = dataObjject.getJSONArray("items");
        return dataArray.toString();
    }
    //关键字查询
    public String getQueryFiled(String place) throws Exception {
        String query = "enti_name like '%" + place + "%'" + "";
        String key = getPublickey();
        String encrypt = RsaHelper.encrypt(key, query);
@@ -70,15 +180,8 @@
        JSONObject jsonObject = JSON.parseObject(jsonString);
        JSONObject dataObjject = jsonObject.getJSONObject("data");
        JSONArray dataArray = dataObjject.getJSONArray("items");
        JSONObject item = dataArray.getJSONObject(0);
        reqEntity.setX(item.getString("lon"));
        reqEntity.setY(item.getString("lat"));
        System.out.print(item);
        reqEntity.setPlace(item.getString("enti_name"));
        hash.put("poi", reqEntity);
        return R.ok(hash);
        return dataArray.getJSONObject(0).toString();
    }
    //获取秘钥接口
    public String getPublickey() {
@@ -90,9 +193,9 @@
    }
    @PostMapping("/aroundPoi")
    @PostMapping("/aroundPoi2")
    @Operation(summary = "周边查询")
    public R aroundPoi(@RequestBody ReqEntity reqEntity) {
    public R aroundPoi2(@RequestBody ReqEntity reqEntity) {
        System.out.println("rec message:" + reqEntity);
        HashMap<String, Object> hash = new HashMap<>();
        hash.put("func", "aroundPoi");
@@ -135,9 +238,7 @@
        hash.put("func", "queryMeta");
        hash.put("mid", mid);
        List<ReqEntity> list = new ArrayList<>();
        hash.put("meta", list);
        String message = JSON.toJSONString(hash);
        webSocketController.sendAllMessage(message);
target/classes/com/yb/controller/XzController.class
Binary files differ
target/ollama-ai-0.0.1-SNAPSHOT.jar
Binary files differ
target/ollama-ai-0.0.1-SNAPSHOT.jar.original
Binary files differ