地理算法优化
This commit is contained in:
parent
ef16256aaf
commit
d11da6ae13
@ -73,6 +73,12 @@
|
||||
<version>2025.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.locationtech.jts</groupId>
|
||||
<artifactId>jts-core</artifactId>
|
||||
<version>1.18.2</version> <!-- 请使用最新版本 -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -3,7 +3,7 @@ package com.ebike.feign.model.dto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -21,6 +21,6 @@ public class FeignEbikeDto implements Serializable {
|
||||
/**
|
||||
* 定位
|
||||
*/
|
||||
private PGpoint location;
|
||||
private Point location;
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -101,6 +101,6 @@ public class FeignEbikeUserBikeInfo implements Serializable {
|
||||
/**
|
||||
* 车辆运营区
|
||||
*/
|
||||
private PGpolygon regionPolygon;
|
||||
private Polygon regionPolygon;
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -33,7 +33,7 @@ public class EbikeLockVo implements Serializable {
|
||||
|
||||
|
||||
@NotNull(message = "车辆当前位置不能为空")
|
||||
private PGpoint point;
|
||||
private Point point;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -29,7 +29,7 @@ public class FeignEbikeBikeRadiusVo implements Serializable {
|
||||
* 用户所在坐标
|
||||
*/
|
||||
@NotNull(message = "用户所在坐标不能为空")
|
||||
private PGpoint point;
|
||||
private Point point;
|
||||
|
||||
/**
|
||||
* 用户所在坐标
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -47,7 +47,7 @@ public class FeignEbikeRegionVo implements Serializable {
|
||||
/**
|
||||
* 区域
|
||||
*/
|
||||
private PGpolygon regionPolygon;
|
||||
private Polygon regionPolygon;
|
||||
|
||||
/**
|
||||
* 站点数量
|
||||
|
||||
@ -19,7 +19,10 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.PrecisionModel;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -189,8 +192,10 @@ public class EbikeBikeInfoController {
|
||||
log.warn("中控未绑定车辆或不存在,SN={}", ecuSn);
|
||||
return JsonResult.failed();
|
||||
}else {
|
||||
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
|
||||
Point location = geometryFactory.createPoint(new Coordinate(longitude, latitude));
|
||||
UpdateChain.of(EbikeBikeInfo.class)
|
||||
.set(EBIKE_BIKE_INFO.LOCATION,new PGpoint(longitude,latitude))
|
||||
.set(EBIKE_BIKE_INFO.LOCATION,location)
|
||||
.where(EBIKE_BIKE_INFO.BIKE_INFO_ID.eq(bikeInfo.getBikeInfoId()))
|
||||
.update();
|
||||
log.info("更新车辆位置成功,SN={}", ecuSn);
|
||||
|
||||
@ -20,7 +20,10 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.PrecisionModel;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -262,8 +265,9 @@ public class EbikeRegionController {
|
||||
@GetMapping("getRegionByLocation")
|
||||
public JsonResult<?> getRegionByLocation(@RequestParam("lng") double lng,
|
||||
@RequestParam("lat") double lat) {
|
||||
PGpoint point = new PGpoint(lng, lat);
|
||||
EbikeRegion region = ebikeRegionService.getRegionByLocation(point);
|
||||
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
|
||||
Point location = geometryFactory.createPoint(new Coordinate(lng, lat));
|
||||
EbikeRegion region = ebikeRegionService.getRegionByLocation(location);
|
||||
return JsonResult.success(region);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@ import com.cdzy.operations.model.dto.EbikeDto;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.cdzy.operations.model.entity.EbikeBikeInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,7 +22,7 @@ public interface EbikeBikeInfoMapper extends BaseMapper<EbikeBikeInfo> {
|
||||
* @param polygon 多边形
|
||||
* @return 列表
|
||||
*/
|
||||
List<EbikeBikeInfo> selectPolygonGeometry(@Param("polygon") PGpolygon polygon);
|
||||
List<EbikeBikeInfo> selectPolygonGeometry(@Param("polygon") Polygon polygon);
|
||||
|
||||
/**
|
||||
* 查询半径范围内的车辆(带距离排序)
|
||||
@ -30,7 +30,7 @@ public interface EbikeBikeInfoMapper extends BaseMapper<EbikeBikeInfo> {
|
||||
* @param radiusMeters 半径距离(米)
|
||||
* @return 按距离排序的车辆列表
|
||||
*/
|
||||
List<EbikeDto> selectRadiusGeometryWithOrder(@Param("centerPoint") PGpoint centerPoint,
|
||||
List<EbikeDto> selectRadiusGeometryWithOrder(@Param("centerPoint") Point centerPoint,
|
||||
@Param("radius") double radiusMeters);
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package com.cdzy.operations.mapper;
|
||||
|
||||
import com.cdzy.operations.model.entity.EbikeRegion;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -28,7 +28,7 @@ public interface EbikeRegionMapper extends BaseMapper<EbikeRegion> {
|
||||
* @param point 用户当前位置
|
||||
* @return 列表
|
||||
*/
|
||||
List<EbikeRegion> findAllRegionsOrderByDistance(PGpoint point);
|
||||
List<EbikeRegion> findAllRegionsOrderByDistance(Point point);
|
||||
|
||||
/**
|
||||
* 根据当前位置查询当前运营区
|
||||
@ -36,5 +36,5 @@ public interface EbikeRegionMapper extends BaseMapper<EbikeRegion> {
|
||||
* @param point 用户当前位置
|
||||
* @return 运营区信息
|
||||
*/
|
||||
EbikeRegion findCurrentRegion(PGpoint point);
|
||||
EbikeRegion findCurrentRegion(Point point);
|
||||
}
|
||||
|
||||
@ -10,8 +10,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -41,10 +40,10 @@ public class EbikeReportRecord implements Serializable {
|
||||
/**
|
||||
* 上报位置
|
||||
*/
|
||||
@Column(typeHandler = PGpointTypeHandler.class)
|
||||
@JsonSerialize(using = PGpointSerializer.class)
|
||||
@JsonDeserialize(using = PGpointDeserializer.class)
|
||||
private PGpoint location;
|
||||
@Column(typeHandler = PointTypeHandler.class)
|
||||
@JsonSerialize(using = PointSerializer.class)
|
||||
@JsonDeserialize(using = PointDeserializer.class)
|
||||
private Point location;
|
||||
|
||||
/**
|
||||
* 上报原因
|
||||
|
||||
@ -12,7 +12,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -61,7 +61,7 @@ public class EbikeSite implements Serializable {
|
||||
@Column(typeHandler = PolygonTypeHandler.class)
|
||||
@JsonSerialize(using = PolygonSerializer.class)
|
||||
@JsonDeserialize(using = PolygonDeserializer.class)
|
||||
private PGpolygon sitePolygon;
|
||||
private Polygon sitePolygon;
|
||||
|
||||
/**
|
||||
* 站点类型:1-普通站点(停车) 2-禁停区 3-仓库区
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.postgresql.geometric.PGpolygon;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -49,7 +49,7 @@ public class EbikeSiteVo implements Serializable {
|
||||
* 站点区域
|
||||
*/
|
||||
@NotNull(message = "站点区域不能为空")
|
||||
private PGpolygon sitePolygon;
|
||||
private Polygon sitePolygon;
|
||||
|
||||
/**
|
||||
* 站点类型:1-普通站点(停车) 2-禁停区 3-仓库区
|
||||
|
||||
@ -4,7 +4,7 @@ import com.cdzy.operations.model.vo.EbikeOperationConfigVo;
|
||||
import com.cdzy.operations.model.vo.EbikeRegionVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.operations.model.entity.EbikeRegion;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
|
||||
/**
|
||||
* 运营区域表 服务层。
|
||||
@ -41,8 +41,8 @@ public interface EbikeRegionService extends IService<EbikeRegion> {
|
||||
|
||||
/**
|
||||
* 根据当前位置查询当前运营区信息
|
||||
* @param pGpoint 当前位置
|
||||
* @param point 当前位置
|
||||
* @return 运营区信息
|
||||
*/
|
||||
EbikeRegion getRegionByLocation(PGpoint pGpoint);
|
||||
EbikeRegion getRegionByLocation(Point point);
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -703,7 +703,7 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
|
||||
|
||||
@Override
|
||||
public List<EbikeRegion> regionList(OrderRegionVo orderRegionVo) {
|
||||
PGpoint point = orderRegionVo.getPoint();
|
||||
Point point = orderRegionVo.getPoint();
|
||||
if (point != null) {
|
||||
return regionMapper.findAllRegionsOrderByDistance(point);
|
||||
} else {
|
||||
|
||||
@ -11,7 +11,7 @@ import com.cdzy.operations.service.EbikeRegionService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.postgresql.geometric.PGpoint;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -145,7 +145,7 @@ public class EbikeRegionServiceImpl extends ServiceImpl<EbikeRegionMapper, Ebike
|
||||
}
|
||||
|
||||
@Override
|
||||
public EbikeRegion getRegionByLocation(PGpoint pGpoint) {
|
||||
return this.mapper.findCurrentRegion(pGpoint);
|
||||
public EbikeRegion getRegionByLocation(Point point) {
|
||||
return this.mapper.findCurrentRegion(point);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
<resultMap id="EbikeDtoMap" type="com.cdzy.operations.model.dto.EbikeDto">
|
||||
<result column="bike_code" property="bikeCode"/>
|
||||
<result column="location" property="location" typeHandler="com.cdzy.operations.handler.PGpointTypeHandler"/>
|
||||
<result column="location" property="location" typeHandler="com.cdzy.operations.handler.PointTypeHandler"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPolygonGeometry" resultType="com.cdzy.operations.model.entity.EbikeBikeInfo">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user