From 523188f00bf2d1c98fbeabfc10c69fcbecfb4bd5 Mon Sep 17 00:00:00 2001 From: "review512jwy@163.com" <“review512jwy@163.com”> Date: Thu, 23 Apr 2026 11:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=9C=E7=BB=8F=E7=BA=AC=E5=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/common/handler/PointTypeHandler.java | 13 ++++++++++--- .../service/impl/StrayAnimalServiceImpl.java | 17 ++++++++++++++--- .../mapper/mini/MiniStrayAnimalMapper.xml | 16 ++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java b/src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java index ad694c2..7f3ad89 100644 --- a/src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java +++ b/src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java @@ -44,14 +44,21 @@ public class PointTypeHandler extends BaseTypeHandler { } private Point toPoint(byte[] bytes) { - if (bytes == null) { + if (bytes == null || bytes.length <= 4) { return null; } try { WKBReader reader = new WKBReader(); - return (Point) reader.read(bytes); + // MySQL 返回的数据前 4 个字节是 SRID (Little Endian 存储的 4326) + // 我们需要跳过这 4 个字节才能获取标准的 WKB 内容 + byte[] wkbBytes = new byte[bytes.length - 4]; + System.arraycopy(bytes, 4, wkbBytes, 0, wkbBytes.length); + + Point point = (Point) reader.read(wkbBytes); + point.setSRID(4326); + return point; } catch (ParseException e) { - throw new RuntimeException("Failed to parse WKB for Point", e); + throw new RuntimeException("無法解析 MySQL 空間數據", e); } } } diff --git a/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java b/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java index ecd244c..877c31b 100644 --- a/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java +++ b/src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java @@ -319,15 +319,26 @@ public class StrayAnimalServiceImpl extends ServiceImpl images, List videos) { diff --git a/src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml b/src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml index 712a2c4..e4f96ae 100644 --- a/src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml +++ b/src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml @@ -57,11 +57,11 @@ #{address}, - ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326), + ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'), - ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326), + ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'), #{wgs84Geohash}, @@ -100,12 +100,12 @@ gd_location_point = - ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326), + ST_GeomFromWKB(#{gdLocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'), wgs84_location_point = - ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326), + ST_GeomFromWKB(#{wgs84LocationPoint, typeHandler=com.youlai.boot.common.handler.PointTypeHandler}, 4326, 'axis-order=long-lat'), wgs84_geohash = #{wgs84Geohash}, @@ -250,8 +250,8 @@ a.province, a.city, a.district, - ST_X(a.gd_location_point) AS lng, - ST_Y(a.gd_location_point) AS lat, + ST_Longitude(a.gd_location_point) AS lng, + ST_Latitude(a.gd_location_point) AS lat, a.address FROM mini_stray_animal a @@ -267,8 +267,8 @@ animal_type, color, size, - ST_X(gd_location_point) AS lng, - ST_Y(gd_location_point) AS lat + ST_Longitude(gd_location_point) AS lng, + ST_Latitude(gd_location_point) AS lat FROM mini_stray_animal WHERE is_deleted = 0