suerprisePlus
2024-09-27 53ae0215de46b9bb68d9aa5d5a3e83dde7cb3986
src/main/java/com/yb/service/XzService.java
@@ -7,6 +7,7 @@
import com.yb.helper.RsaHelper;
import com.yb.util.EntityHttpUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.locationtech.jts.geom.*;
@@ -24,6 +25,7 @@
import org.locationtech.proj4j.CoordinateTransform;
import org.locationtech.proj4j.CoordinateTransformFactory;
import org.locationtech.proj4j.ProjCoordinate;
import java.util.HashMap;
@Service
@@ -34,28 +36,28 @@
    private EntityHttpUtil entityHttpUtil;
    @Autowired
    private AgentService agentService;
    int num = 40;
    // 关键字查询
    public String getQueryFiled(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
        String query = "";
        String querySQL = "";
        String valSql = " like '%" + place + "%'";
        String key = getPublickey();
        if (filed.indexOf(",") > -1) {
            String[] fileds = filed.split(",");
            for (int i = 0; i < fileds.length; i++) {
                String name = fileds[i];
                if (i > 0) {
                    query += " or ";
        String query = getQuerySql(valSql, filed);
//        int num = 40;
        if (query.length() > num) {
            String[] sbuString = getSqlSubStr(query, num);
            for (int w = 0; w < sbuString.length; w++) {
                if (w > 0) {
                    querySQL += ",";
                }
                query += name + valSql;
                querySQL += RsaHelper.encrypt(key, sbuString[w]);
            }
        } else {
            query += filed + valSql;
            querySQL += RsaHelper.encrypt(key, query);
        }
        query += "";
        System.out.println("rec getQueryFiled:" + query);
        String encrypt = RsaHelper.encrypt(key, query);
        HashMap formData = getHashMap(layerId, dbId, "1", "0", encrypt, null);
        System.out.println("rec getQueryFiled:" + querySQL);
        HashMap formData = getHashMap(layerId, dbId, "1", "0", querySQL, null);
        String jsonString = entityHttpUtil.getPostMessage(queryEntity, formData);
        System.out.println("rec getQueryFiled:" + jsonString);
        JSONObject jsonObject = JSON.parseObject(jsonString);
@@ -67,11 +69,19 @@
        return "";
    }
    // 关键字查询
    public String getQueryEntity(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
    public String[] getSqlSubStr(String str, int chunkSize) {
        int numChunks = (str.length() + chunkSize - 1) / chunkSize;
        String[] chunks = new String[numChunks];
        for (int i = 0; i < numChunks; i++) {
            int start = i * chunkSize;
            int end = Math.min(start + chunkSize, str.length());
            chunks[i] = str.substring(start, end);
        }
        return chunks;
    }
    public String getQuerySql(String valSql, String filed) {
        String query = "";
        String valSql = " like '%" + place + "%'";
        String key = getPublickey();
        if (filed.indexOf(",") > -1) {
            String[] fileds = filed.split(",");
            for (int i = 0; i < fileds.length; i++) {
@@ -81,12 +91,32 @@
                }
                query += name + valSql;
            }
            query += "";
        } else {
            query += filed + valSql;
            query = filed + valSql + "";
        }
        query += "";
        String encrypt = RsaHelper.encrypt(key, query);
        HashMap formData = getHashMap(layerId, dbId, "1", "100", encrypt, null);
        return query;
    }
    // 关键字查询
    public String getQueryEntity(String place, String filed, String layerId, String dbId, String queryEntity) throws Exception {
        String valSql = " like '%" + place + "%'";
        String key = getPublickey();
        String query = getQuerySql(valSql, filed);
        String querySQL = "";
//        int num = 40;
        if (query.length() > num) {
            String[] sbuString = getSqlSubStr(query, num);
            for (int w = 0; w < sbuString.length; w++) {
                if (w > 0) {
                    querySQL += ",";
                }
                querySQL += RsaHelper.encrypt(key, sbuString[w]);
            }
        } else {
            querySQL += RsaHelper.encrypt(key, query);
        }
        HashMap formData = getHashMap(layerId, dbId, "1", "100", querySQL, null);
        formData.put("querytype", "entity");
        String jsonString1 = entityHttpUtil.getPostMessage(queryEntity, formData);
        System.out.println("rec getQueryFiled:" + jsonString1);
@@ -104,9 +134,12 @@
    //  范围查询
    public String getQueryAround(String type, String wkt, String filed, String layerId, String dbid, String entity) throws Exception {
        String query = filed + " like '%" + type + "%'" + "";
        if (type.contains("全部目标")) {
            query = filed + " like '%目标%'" + "";
        }
        String encrypt = RsaHelper.encrypt(getPublickey(), query);
        HashMap formData = getHashMap(layerId, dbid, "1", "0", encrypt, wkt);
        formData.put("querytype","entity");
        formData.put("querytype", "entity");
        String jsonString = entityHttpUtil.getPostMessage(entity, formData);
        JSONObject jsonObject = JSON.parseObject(jsonString);
        JSONObject dataObj = jsonObject.getJSONObject("data");
@@ -170,7 +203,6 @@
    }
    //生成WKT
    public String getWKt(double lon, double lat, int radius) throws Exception {
        // 创建一个坐标点
@@ -182,9 +214,9 @@
        // 创建BufferOp实例,用于生成缓冲区
        BufferOp bufferOp = new BufferOp(point);
        int dis = 500;
//        if (radius != 0) {
//            dis = radius;
//        }
        if (radius != 0) {
            dis = radius;
        }
        // 设置缓冲区距离为500米
        Geometry bufferedGeometry = bufferOp.getResultGeometry(dis / 111319.9);
        // 创建WKTWriter实例,用于将Geometry转换为WKT格式
@@ -226,15 +258,16 @@
        CoordinateTransform transform = ctFactory.createTransform(src, dest);
        // 定义一个源坐标点(经度,纬度)
        ProjCoordinate srcgetMin = new ProjCoordinate( envelope.getMinX(),  envelope.getMinY()); // 例如:北京的经纬度
        ProjCoordinate srcgetMax = new ProjCoordinate( envelope.getMaxX(),  envelope.getMaxY()); // 例如:北京的经纬度
        ProjCoordinate srcgetMin = new ProjCoordinate(envelope.getMinX(), envelope.getMinY(), 0); // 例如:北京的经纬度
        ProjCoordinate srcgetMax = new ProjCoordinate(envelope.getMaxX(), envelope.getMaxY(), 0); // 例如:北京的经纬度
        // 执行转换
        ProjCoordinate destgetMin = new ProjCoordinate();
        ProjCoordinate destgetMax = new ProjCoordinate();
        System.out.println("转换后的坐标:X = " + srcgetMin);
        transform.transform(srcgetMin, destgetMin);
        transform.transform(srcgetMax, destgetMax);
        String wkt =destgetMin.x+","+destgetMin.y+","+destgetMax.x+","+destgetMax.y;
        System.out.println("转换后的坐标:X = " +wkt);
        String wkt = destgetMin.x + "," + destgetMin.y + "," + destgetMax.x + "," + destgetMax.y;
        System.out.println("转换后的坐标:X = " + wkt);
        return wkt;
    }