From d4e4ea6405756d495806a609e24ae85ebd7345ef Mon Sep 17 00:00:00 2001 From: suerprisePlus <15810472099@163.com> Date: 星期二, 17 十二月 2024 09:30:12 +0800 Subject: [PATCH] 代码更新 --- src/main/java/com/yb/service/XzService.java | 165 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 146 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/yb/service/XzService.java b/src/main/java/com/yb/service/XzService.java index 7f08fdc..d9dc8f0 100644 --- a/src/main/java/com/yb/service/XzService.java +++ b/src/main/java/com/yb/service/XzService.java @@ -7,15 +7,25 @@ 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.*; 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 org.geotools.geometry.jts.JTS; +import org.geotools.referencing.CRS; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; +//import org.opengis.referencing.FactoryException; +//import org.opengis.referencing.crs.CoordinateReferenceSystem; +//import org.opengis.referencing.operation.MathTransform; +import org.locationtech.proj4j.CRSFactory; +import org.locationtech.proj4j.CoordinateReferenceSystem; +import org.locationtech.proj4j.CoordinateTransform; +import org.locationtech.proj4j.CoordinateTransformFactory; +import org.locationtech.proj4j.ProjCoordinate; -import java.util.*; import java.util.HashMap; @Service @@ -26,16 +36,30 @@ 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 = filed + " like '%" + place + "%'" + ""; + String querySQL = ""; + String valSql = " like '%" + place + "%'"; String key = getPublickey(); - String encrypt = RsaHelper.encrypt(key, query); - HashMap formData = getHashMap(layerId, dbId, "1", "0", encrypt, null); + 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 += ","; + } + querySQL += RsaHelper.encrypt(key, sbuString[w]); + } + } else { + querySQL += RsaHelper.encrypt(key, query); + } + 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); JSONObject dataObjject = jsonObject.getJSONObject("data"); JSONArray dataArray = dataObjject.getJSONArray("items"); @@ -45,11 +69,77 @@ return ""; } + 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 = ""; + 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 "; + } + query += name + valSql; + } + query += ""; + } else { + query = filed + valSql + ""; + } + 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); + JSONObject jsonObject = JSON.parseObject(jsonString1); + JSONObject dataObjject = jsonObject.getJSONObject("data"); + JSONArray dataArray = dataObjject.getJSONArray("items"); + if (dataArray.size() <= 0) { + return null; + } + return dataArray.getJSONObject(0).toString(); + + + } + // 鑼冨洿鏌ヨ 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"); String jsonString = entityHttpUtil.getPostMessage(entity, formData); JSONObject jsonObject = JSON.parseObject(jsonString); JSONObject dataObj = jsonObject.getJSONObject("data"); @@ -69,7 +159,8 @@ 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); + String meta = entityHttpUtil.getPostMessage(entity, formData); + return meta; } // 鑾峰彇杩斿洖淇℃伅Map @@ -106,14 +197,15 @@ hashMap.put("where", where); } if (box != null && box != "") { - hashMap.put("box", box); + hashMap.put("bbox", box); } return hashMap; } + //鐢熸垚WKT - public String getWKt(double lon, double lat, int radius) { + public String getWKt(double lon, double lat, int radius) throws Exception { // 鍒涘缓涓�涓潗鏍囩偣 Coordinate coord = new Coordinate(lon, lat); // 鍒涘缓GeometryFactory瀹炰緥锛屽苟鎸囧畾鍧愭爣鍙傝�冪郴缁熶负WGS84 @@ -136,14 +228,49 @@ // 杈撳嚭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; + +// double[] wkt = new double[4]; +// wkt[0] = ; +// wkt[1] =; +// wkt[2] = envelope.getMaxX(); +// wkt[3] = envelope.getMaxY(); +// +// wkt += envelope.getMinX(); +// wkt += ","+envelope.getMinY(); +// wkt += ","+envelope.getMaxX(); +// wkt += ","+envelope.getMaxY(); +// System.out.println("WKT: " + wkt); +// String arrayAsString = Arrays.toString(wkt); +// System.out.println("wkt: " + wkt); + + CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); + + // 瀹氫箟婧愬潗鏍囩郴锛圵GS 84锛� + String srcCRS = "EPSG:4326"; + // 瀹氫箟鐩爣鍧愭爣绯伙紙涓浗澶у湴鍧愭爣绯伙級 + String destCRS = "EPSG:4550"; + + // 鍒涘缓鍧愭爣鍙傝�冪郴缁� + CRSFactory crsFactory = new CRSFactory(); + CoordinateReferenceSystem src = crsFactory.createFromName(srcCRS); + CoordinateReferenceSystem dest = crsFactory.createFromName(destCRS); + + // 鍒涘缓鍧愭爣杞崲鍣� + CoordinateTransform transform = ctFactory.createTransform(src, dest); + + // 瀹氫箟涓�涓簮鍧愭爣鐐癸紙缁忓害锛岀含搴︼級 + 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("杞崲鍚庣殑鍧愭爣锛歑 = " + srcgetMin); + transform.transform(srcgetMin, destgetMin); + transform.transform(srcgetMax, destgetMax); + String wkt = destgetMin.x + "," + destgetMin.y + "," + destgetMax.x + "," + destgetMax.y; + System.out.println("杞崲鍚庣殑鍧愭爣锛歑 = " + wkt); + return wkt; + } -- Gitblit v1.9.3