diff --git a/ebike-gather/src/main/resources/application-dev.yml b/ebike-gather/src/main/resources/application-dev.yml index 6f67831..ba92213 100644 --- a/ebike-gather/src/main/resources/application-dev.yml +++ b/ebike-gather/src/main/resources/application-dev.yml @@ -13,7 +13,7 @@ spring: username: nacos password: nacos kafka: - bootstrap-servers: 192.168.101.40:9092 + bootstrap-servers: 47.109.71.130:9092 producer: retries: 0 key-serializer: org.apache.kafka.common.serialization.StringSerializer diff --git a/ebike-operations/src/main/java/com/cdzy/operations/handler/PointDeserializer.java b/ebike-operations/src/main/java/com/cdzy/operations/handler/PointDeserializer.java index cf94861..cab7c60 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/handler/PointDeserializer.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/handler/PointDeserializer.java @@ -70,7 +70,7 @@ public class PointDeserializer extends JsonDeserializer { 4. 坐标数组: [lng,lat] 5. 简化格式: {"longitude":116.3974,"latitude":39.9093} 6. WKT字符串: "POINT(lng lat)" - 7. PostgreSQL点格式: "(lng,lat)" """); + 7. PostgreSQL点格式: "(lng,lat)\""""); } catch (Exception e) { log.error("!!! PointDeserializer 反序列化失败 !!!"); diff --git a/ebike-operations/src/main/resources/application-dev.yml b/ebike-operations/src/main/resources/application-dev.yml index bab96a6..e3e9f1f 100644 --- a/ebike-operations/src/main/resources/application-dev.yml +++ b/ebike-operations/src/main/resources/application-dev.yml @@ -14,7 +14,7 @@ spring: username: nacos password: nacos kafka: - bootstrap-servers: 192.168.101.40:9092 + bootstrap-servers: 47.109.71.130:9092 producer: retries: 0 key-serializer: org.apache.kafka.common.serialization.StringSerializer diff --git a/ebike-report/src/main/resources/application-dev.yml b/ebike-report/src/main/resources/application-dev.yml index 394f861..45ad499 100644 --- a/ebike-report/src/main/resources/application-dev.yml +++ b/ebike-report/src/main/resources/application-dev.yml @@ -14,7 +14,7 @@ spring: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 kafka: - bootstrap-servers: 192.168.101.40:9092 + bootstrap-servers: 47.109.71.130:9092 producer: retries: 0 key-serializer: org.apache.kafka.common.serialization.StringSerializer diff --git a/ebike-user/src/main/java/com/cdzy/user/handler/PointDeserializer.java b/ebike-user/src/main/java/com/cdzy/user/handler/PointDeserializer.java index 75b6633..86f5910 100644 --- a/ebike-user/src/main/java/com/cdzy/user/handler/PointDeserializer.java +++ b/ebike-user/src/main/java/com/cdzy/user/handler/PointDeserializer.java @@ -73,7 +73,7 @@ public class PointDeserializer extends JsonDeserializer { 4. 坐标数组: [lng,lat] 5. 简化格式: {"longitude":116.3974,"latitude":39.9093} 6. WKT字符串: "POINT(lng lat)" - 7. PostgreSQL点格式: "(lng,lat)" """); + 7. PostgreSQL点格式: "(lng,lat)\""""); } catch (Exception e) { log.error("!!! PointDeserializer 反序列化失败 !!!"); diff --git a/ebike-user/src/main/java/com/cdzy/user/handler/PointSerializer.java b/ebike-user/src/main/java/com/cdzy/user/handler/PointSerializer.java index 7a6f1a5..e0ae682 100644 --- a/ebike-user/src/main/java/com/cdzy/user/handler/PointSerializer.java +++ b/ebike-user/src/main/java/com/cdzy/user/handler/PointSerializer.java @@ -9,9 +9,6 @@ import org.locationtech.jts.geom.Point; import org.locationtech.jts.io.WKTWriter; import java.io.IOException; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Locale; /** * JTS Point 序列化器 - 将 Point 序列化为 JSON @@ -20,9 +17,6 @@ import java.util.Locale; @Slf4j public class PointSerializer extends JsonSerializer { - private static final DecimalFormat COORD_FORMAT = new DecimalFormat("#.##########", - DecimalFormatSymbols.getInstance(Locale.US)); - private final WKTWriter wktWriter = new WKTWriter(); @Override @@ -111,25 +105,4 @@ public class PointSerializer extends JsonSerializer { } } - /** - * 获取坐标的格式化字符串(用于文本表示) - */ - private String getFormattedCoordinateString(double value) { - synchronized (COORD_FORMAT) { - return COORD_FORMAT.format(value); - } - } - - /** - * 生成 PostgreSQL 点格式的字符串(兼容性) - */ - private String toPostgresPointFormat(Point point) { - if (point == null || point.isEmpty()) { - return ""; - } - - Coordinate coordinate = point.getCoordinate(); - return "(" + getFormattedCoordinateString(coordinate.x) + - "," + getFormattedCoordinateString(coordinate.y) + ")"; - } } \ No newline at end of file diff --git a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonDeserializer.java b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonDeserializer.java index f489634..6186bad 100644 --- a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonDeserializer.java +++ b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonDeserializer.java @@ -37,8 +37,6 @@ public class PolygonDeserializer extends JsonDeserializer { String type = node.get("type").asText().toLowerCase(); if ("polygon".equals(type)) { result = parseFromCustomFormat(node); - } else if ("polygon".equals(type)) { // GeoJSON 格式 - result = parseFromGeoJSON(node); } } // 格式2: 直接坐标数组 [[x1,y1], [x2,y2], ...] @@ -61,7 +59,7 @@ public class PolygonDeserializer extends JsonDeserializer { 2. GeoJSON格式: {"type":"Polygon","coordinates":[[[x1,y1],[x2,y2],...]]} 3. 坐标数组: [[x1,y1],[x2,y2],...] 4. WKT字符串: "POLYGON((x1 y1, x2 y2, ...))" - 5. PGpolygon格式: "((x1,y1),(x2,y2),...)" """); + 5. PGpolygon格式: "((x1,y1),(x2,y2),...)\""""); } return result; @@ -116,46 +114,6 @@ public class PolygonDeserializer extends JsonDeserializer { return createPolygonFromCoordinates(coordinates); } - /** - * 解析 GeoJSON 格式 - */ - private Polygon parseFromGeoJSON(JsonNode node) throws IOException { - JsonNode coordinatesNode = node.get("coordinates"); - if (coordinatesNode == null) { - throw new IOException("coordinates 字段缺失"); - } - - if (!coordinatesNode.isArray() || coordinatesNode.isEmpty()) { - throw new IOException("coordinates 字段必须是非空数组"); - } - - // GeoJSON 格式: coordinates 是三维数组 [[[x1,y1], [x2,y2], ...]] - JsonNode firstRing = coordinatesNode.get(0); - if (!firstRing.isArray()) { - throw new IOException("GeoJSON coordinates 第一环必须是数组"); - } - - List coordinates = new ArrayList<>(); - for (int i = 0; i < firstRing.size(); i++) { - JsonNode coordNode = firstRing.get(i); - if (!coordNode.isArray()) { - throw new IOException("GeoJSON 坐标 " + i + " 必须是数组格式"); - } - if (coordNode.size() < 2) { - throw new IOException("GeoJSON 坐标 " + i + " 至少需要2个值(经度和纬度)"); - } - try { - double x = coordNode.get(0).asDouble(); - double y = coordNode.get(1).asDouble(); - coordinates.add(new Coordinate(x, y)); - } catch (NumberFormatException e) { - throw new IOException("GeoJSON 坐标 " + i + " 格式错误: " + coordNode, e); - } - } - - return createPolygonFromCoordinates(coordinates); - } - /** * 解析坐标数组格式 */ diff --git a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonSerializer.java b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonSerializer.java index 86dd691..30dc976 100644 --- a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonSerializer.java +++ b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonSerializer.java @@ -10,9 +10,6 @@ import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.io.WKTWriter; import java.io.IOException; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Locale; /** * JTS Polygon 序列化器 - 将 Polygon 序列化为 JSON @@ -20,9 +17,6 @@ import java.util.Locale; */ @Slf4j public class PolygonSerializer extends JsonSerializer { - - private static final DecimalFormat COORD_FORMAT = new DecimalFormat("#.##########", - DecimalFormatSymbols.getInstance(Locale.US)); private final WKTWriter wktWriter = new WKTWriter(); @@ -103,7 +97,7 @@ public class PolygonSerializer extends JsonSerializer { try { // 获取外环 - LinearRing exteriorRing = (LinearRing) polygon.getExteriorRing(); + LinearRing exteriorRing = polygon.getExteriorRing(); if (exteriorRing == null) { throw new IOException("多边形外环为空"); } @@ -173,41 +167,4 @@ public class PolygonSerializer extends JsonSerializer { throw new IOException("Polygon 序列化失败", e); } } - - /** - * 获取坐标的格式化字符串 - */ - private String getFormattedCoordinateString(double value) { - synchronized (COORD_FORMAT) { - return COORD_FORMAT.format(value); - } - } - - /** - * 生成 PGpolygon 格式的字符串(兼容性) - */ - private String toPGpolygonFormat(Coordinate[] coordinates) { - if (coordinates == null || coordinates.length == 0) { - return ""; - } - - StringBuilder sb = new StringBuilder(); - sb.append("(("); - - for (int i = 0; i < coordinates.length; i++) { - Coordinate coord = coordinates[i]; - if (coord == null) continue; - - sb.append(getFormattedCoordinateString(coord.x)) - .append(",") - .append(getFormattedCoordinateString(coord.y)); - - if (i < coordinates.length - 1) { - sb.append("),("); - } - } - - sb.append("))"); - return sb.toString(); - } } \ No newline at end of file diff --git a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonTypeHandler.java b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonTypeHandler.java index 49628bd..dd82a8c 100644 --- a/ebike-user/src/main/java/com/cdzy/user/handler/PolygonTypeHandler.java +++ b/ebike-user/src/main/java/com/cdzy/user/handler/PolygonTypeHandler.java @@ -5,7 +5,9 @@ import com.cdzy.common.utils.CoordinateUtil; import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.locationtech.jts.geom.*; -import org.locationtech.jts.io.*; +import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKBReader; +import org.locationtech.jts.io.WKTReader; import org.postgresql.util.PGobject; import java.sql.*; @@ -23,9 +25,7 @@ public class PolygonTypeHandler implements TypeHandler { private static final int WGS84_SRID = 4326; private final GeometryFactory geometryFactory = new GeometryFactory(); private final WKTReader wktReader = new WKTReader(geometryFactory); - private final WKTWriter wktWriter = new WKTWriter(); private final WKBReader wkbReader = new WKBReader(geometryFactory); - private final WKBWriter wkbWriter = new WKBWriter(); @Override public void setParameter(PreparedStatement ps, int i, Polygon parameter, JdbcType jdbcType)