suerprisePlus
2024-09-05 cc3a00f52f356c893d9f21798e9e941bb9533d10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.yb.service;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yb.config.XzConfig;
import com.yb.helper.RsaHelper;
import com.yb.util.EntityHttpUtil;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.locationtech.jts.geom.*;
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.*;
import java.util.HashMap;
 
@Service
public class XzService {
    @Autowired
    private XzConfig xzConfig;
    @Autowired
    private EntityHttpUtil entityHttpUtil;
    @Autowired
    private AgentService agentService;
 
    // 关键字查询
    public String getQueryFiled(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
        String query = filed + " like '%" + place + "%'" + "";
        String key = getPublickey();
        String encrypt = RsaHelper.encrypt(key, query);
        HashMap formData = getHashMap(layerId, dbId, "1", "0", encrypt, null);
        String jsonString = entityHttpUtil.getPostMessage(queryEntity, formData);
        System.out.println("rec getQueryFiled:" + jsonString);
 
        JSONObject jsonObject = JSON.parseObject(jsonString);
        JSONObject dataObjject = jsonObject.getJSONObject("data");
        JSONArray dataArray = dataObjject.getJSONArray("items");
        if (dataArray.size() > 0) {
            return dataArray.getJSONObject(0).toString();
        }
        return "";
    }
 
    //  范围查询
    public String getQueryAround(String type, String wkt, String filed, String layerId, String dbid, String entity) throws Exception {
        String query = filed + " like '%" + type + "%'" + "";
        String encrypt = RsaHelper.encrypt(getPublickey(), query);
        HashMap formData = getHashMap(layerId, dbid, "1", "0", encrypt, wkt);
        String jsonString = entityHttpUtil.getPostMessage(entity, formData);
        JSONObject jsonObject = JSON.parseObject(jsonString);
        JSONObject dataObj = jsonObject.getJSONObject("data");
        JSONArray dataArray = dataObj.getJSONArray("items");
        return dataArray.toString();
 
    }
 
    //元信息查询
    public String getQueryMeta(String layerId, String dbid, String filed, String entity) {
        HashMap<String, Object> staticField = new HashMap<>();
        JSONArray jsonArray = new JSONArray();
        staticField.put("type", "count");
        staticField.put("field", filed);
        staticField.put("outfield", "count_" + filed);
        jsonArray.add(staticField);
        HashMap<String, String> formData = getHashMap(layerId, dbid, null, null, null, null);
        formData.put("statistics", jsonArray.toString());
        formData.put("groupby", filed);
        return entityHttpUtil.getPostMessage(entity, formData);
    }
 
    // 获取返回信息Map
    public HashMap<String, Object> getFuncMap(String func, String mid) {
        HashMap<String, Object> hash = new HashMap<String, Object>();
        hash.put("func", func);
        hash.put("mid", mid);
        return hash;
    }
 
    //获取秘钥接口
    public String getPublickey() {
        HashMap<String, String> map = new HashMap<>();
        map.put("token", xzConfig.token);
        String jsonString = entityHttpUtil.getPostMessage(xzConfig.publickey, map);
        JSONObject jsonObject = JSON.parseObject(jsonString);
        return jsonObject.getString("data");
    }
 
    // 传参
    public HashMap<String, String> getHashMap(String layerId, String dbid, String start, String count, String where, String box) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", xzConfig.token);
        hashMap.put("containCount", "true");
        hashMap.put("layerid", layerId);
        hashMap.put("dbid", dbid);
        if (start != null && start != "") {
            hashMap.put("start", start);
        }
        if (count != null && count != "") {
            hashMap.put("count", count);
        }
        if (where != null && where != "") {
            hashMap.put("where", where);
        }
        if (box != null && box != "") {
            hashMap.put("box", box);
        }
 
        return hashMap;
    }
 
    //生成WKT
    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 / 111319.9);
        // 创建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;
    }
 
 
}