Browse Source

Merge branch 'master' into glx

master
glx 1 month ago
parent
commit
dc88e723a1
  1. 68
      pom.xml
  2. 2
      src/main/java/com/youlai/boot/auth/controller/AuthController.java
  3. 13
      src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java
  4. 15
      src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java
  5. 16
      src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml

68
pom.xml

@ -324,32 +324,72 @@
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins> <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration> <configuration>
<excludes> <excludes>
<!-- 只排除application相关的配置文件 -->
<exclude>**/application.yml</exclude> <exclude>**/application.yml</exclude>
<exclude>**/application-dev.yml</exclude> <exclude>**/application-dev.yml</exclude>
<exclude>**/application-prod.yml</exclude> <exclude>**/application-prod.yml</exclude>
</excludes> </excludes>
<archive>
<manifest>
<classpathPrefix>lib/</classpathPrefix>
<addClasspath>true</addClasspath>
<mainClass>com.youlai.boot.YouLaiBootApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- lib目录分离, 拷贝依赖到jar外面的lib目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 依赖包输出目录,将来不打进jar包里 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<!-- resource插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<useDefaultDelimiters>true</useDefaultDelimiters>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
<nonFilteredFileExtension>xdb</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build> </build>
</project> </project>

2
src/main/java/com/youlai/boot/auth/controller/AuthController.java

@ -67,7 +67,7 @@ public class AuthController {
} }
@Operation(summary = "退出登录") @Operation(summary = "退出登录")
@DeleteMapping("/logout") @PostMapping("/logout")
@Log(module = LogModuleEnum.LOGIN, value = ActionTypeEnum.LOGOUT) @Log(module = LogModuleEnum.LOGIN, value = ActionTypeEnum.LOGOUT)
public Result<Void> logout() { public Result<Void> logout() {
authService.logout(); authService.logout();

13
src/main/java/com/youlai/boot/common/handler/PointTypeHandler.java

@ -44,14 +44,21 @@ public class PointTypeHandler extends BaseTypeHandler<Point> {
} }
private Point toPoint(byte[] bytes) { private Point toPoint(byte[] bytes) {
if (bytes == null) { if (bytes == null || bytes.length <= 4) {
return null; return null;
} }
try { try {
WKBReader reader = new WKBReader(); 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) { } catch (ParseException e) {
throw new RuntimeException("Failed to parse WKB for Point", e); throw new RuntimeException("無法解析 MySQL 空間數據", e);
} }
} }
} }

15
src/main/java/com/youlai/boot/mini/service/impl/StrayAnimalServiceImpl.java

@ -319,14 +319,25 @@ public class StrayAnimalServiceImpl extends ServiceImpl<MiniStrayAnimalMapper, M
} }
private void handleLngLat(MiniStrayAnimal entity, Double lng, Double lat) { private void handleLngLat(MiniStrayAnimal entity, Double lng, Double lat) {
// 1. 初始化工厂
GeometryFactory geometryFactory = new GeometryFactory(); GeometryFactory geometryFactory = new GeometryFactory();
Point gdPoint = geometryFactory.createPoint(new Coordinate(lat, lng));
// 2. 高德/腾讯座标 (GCJ02)
// JTS 的 X 是经度,Y 是纬度
Point gdPoint = geometryFactory.createPoint(new Coordinate(lng, lat));
gdPoint.setSRID(4326); gdPoint.setSRID(4326);
// 3. 转换为 WGS84 座标
double[] wgs84 = CoordinateTransformUtils.gcj02ToWgs84(lng, lat); double[] wgs84 = CoordinateTransformUtils.gcj02ToWgs84(lng, lat);
Point wgsPoint = geometryFactory.createPoint(new Coordinate(wgs84[1], wgs84[0])); // 假设数组 wgs84[0] 是经度, wgs84[1] 是纬度
Point wgsPoint = geometryFactory.createPoint(new Coordinate(wgs84[0], wgs84[1]));
wgsPoint.setSRID(4326); wgsPoint.setSRID(4326);
// 4. 赋值给实体
entity.setGdLocationPoint(gdPoint); entity.setGdLocationPoint(gdPoint);
entity.setWgs84LocationPoint(wgsPoint); entity.setWgs84LocationPoint(wgsPoint);
// 5. GeoHash 计算 (注意:大多数 GeoHash 库的第一个参数是 Latitude)
entity.setWgs84Geohash(GeoHash.withCharacterPrecision(wgs84[1], wgs84[0], CommonConstants.GEOHASH_LEVEL).toBase32()); entity.setWgs84Geohash(GeoHash.withCharacterPrecision(wgs84[1], wgs84[0], CommonConstants.GEOHASH_LEVEL).toBase32());
} }

16
src/main/resources/mapper/mini/MiniStrayAnimalMapper.xml

@ -57,11 +57,11 @@
<if test="address != null">#{address},</if> <if test="address != null">#{address},</if>
<if test="gdLocationPoint != null"> <if test="gdLocationPoint != null">
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'),
</if> </if>
<if test="wgs84LocationPoint != null"> <if test="wgs84LocationPoint != null">
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'),
</if> </if>
<if test="wgs84Geohash != null">#{wgs84Geohash},</if> <if test="wgs84Geohash != null">#{wgs84Geohash},</if>
@ -100,12 +100,12 @@
<if test="gdLocationPoint != null"> <if test="gdLocationPoint != null">
gd_location_point = 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'),
</if> </if>
<if test="wgs84LocationPoint != null"> <if test="wgs84LocationPoint != null">
wgs84_location_point = 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'),
</if> </if>
<if test="wgs84Geohash != null">wgs84_geohash = #{wgs84Geohash},</if> <if test="wgs84Geohash != null">wgs84_geohash = #{wgs84Geohash},</if>
@ -250,8 +250,8 @@
a.province, a.province,
a.city, a.city,
a.district, a.district,
ST_X(a.gd_location_point) AS lng, ST_Longitude(a.gd_location_point) AS lng,
ST_Y(a.gd_location_point) AS lat, ST_Latitude(a.gd_location_point) AS lat,
a.address a.address
FROM FROM
mini_stray_animal a mini_stray_animal a
@ -267,8 +267,8 @@
animal_type, animal_type,
color, color,
size, size,
ST_X(gd_location_point) AS lng, ST_Longitude(gd_location_point) AS lng,
ST_Y(gd_location_point) AS lat ST_Latitude(gd_location_point) AS lat
FROM FROM
mini_stray_animal mini_stray_animal
WHERE is_deleted = 0 WHERE is_deleted = 0

Loading…
Cancel
Save