kafka配置、序列化warn修复

This commit is contained in:
attiya 2026-01-06 09:12:07 +08:00
parent fb9787fec1
commit 61a99a6ca6
9 changed files with 10 additions and 122 deletions

View File

@ -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

View File

@ -70,7 +70,7 @@ public class PointDeserializer extends JsonDeserializer<Point> {
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 反序列化失败 !!!");

View File

@ -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

View File

@ -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

View File

@ -73,7 +73,7 @@ public class PointDeserializer extends JsonDeserializer<Point> {
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 反序列化失败 !!!");

View File

@ -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<Point> {
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<Point> {
}
}
/**
* 获取坐标的格式化字符串用于文本表示
*/
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) + ")";
}
}

View File

@ -37,8 +37,6 @@ public class PolygonDeserializer extends JsonDeserializer<Polygon> {
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<Polygon> {
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<Polygon> {
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<Coordinate> 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);
}
/**
* 解析坐标数组格式
*/

View File

@ -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<Polygon> {
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<Polygon> {
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<Polygon> {
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();
}
}

View File

@ -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<Polygon> {
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)