zhouy 7 bulan lalu
induk
melakukan
54b7b07417

+ 2 - 5
bus-biz/src/main/java/bus/mapper/BCourseInfoMapper.java

@@ -1,6 +1,7 @@
 package bus.mapper;
 
 import bus.model.dto.BStationInfoDto;
+import bus.model.dto.NearbyRoutesDto;
 import bus.model.dto.page.BCourseInfoPageDto;
 import bus.model.vo.BCourseInfoVo;
 import bus.model.po.*;
@@ -22,11 +23,7 @@ public interface BCourseInfoMapper extends BaseMapper<BCourseInfoPo> {
 
     List<BCourseInfoVo> list(BCourseInfoPageDto dto);
 
-    List<BStationInfoDto> findNearbyStations(@Param("longitude") BigDecimal longitude,
-                                             @Param("latitude") BigDecimal latitude,
-                                             @Param("radius") Integer radius,
-                                             @Param("BigDistance") Integer BigDistance
-    );
+    List<BStationInfoDto> findNearbyStations(NearbyRoutesDto nearbyRoutesDto);
     List<BCourseInfoVo> findRoutesByStations(@Param("stationIds") List<String> stationIds);
 
     List<BCourseInfoVo> findRoutesByStationId(@Param("stationIds") List<String> stationIds);

+ 4 - 5
bus-biz/src/main/java/bus/service/impl/BCourseInfoServiceImpl.java

@@ -359,16 +359,15 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
     @Override
     public List<WBusTrackInfoDto> getNearbyRoutes(NearbyRoutesDto nearbyRoutesDto) {
         Integer radius = nearbyRoutesDto.getRadius();
-        Integer bigDistance = nearbyRoutesDto.getBigDistance();
-        BigDecimal latitude = nearbyRoutesDto.getLatitude();
-        BigDecimal longitude = nearbyRoutesDto.getLongitude();
+        String latitude = nearbyRoutesDto.getLatitude();
+        String longitude = nearbyRoutesDto.getLongitude();
         // 参数验证
-        if (latitude == null || longitude == null || radius == null || bigDistance == null) {
+        if (latitude == null || longitude == null || radius == null ) {
             return Collections.emptyList();
         }
 
         // 1. 查询附近站点
-        List<BStationInfoDto> nearbyStations = bCourseInfoMapper.findNearbyStations(latitude, longitude, radius,bigDistance);
+        List<BStationInfoDto> nearbyStations = bCourseInfoMapper.findNearbyStations(nearbyRoutesDto);
         if (CollectionUtil.isEmpty(nearbyStations)) {
             return Collections.emptyList();
         }

+ 29 - 21
bus-biz/src/main/resources/mapper/BCourseInfoMapper.xml

@@ -44,30 +44,38 @@
  </select>
 
     <!-- 查询附近站点 -->
-    <select id="findNearbyStations" resultType="bus.model.dto.BStationInfoDto">
+    <select id="findNearbyStations" resultType="bus.model.dto.BStationInfoDto"
+            parameterType="bus.model.dto.NearbyRoutesDto" >
         SELECT
-            id,
-            name,
-            latitude,
-            longitude,
-            ROUND(
-                6378.137 * 2 * ASIN(
-                    SQRT(
-                        POW(SIN((#{latitude} - latitude) * PI() / 180 / 2), 2) +
-                        COS(#{latitude} * PI() / 180) * COS(latitude * PI() / 180) *
-                        POW(SIN((#{longitude} - longitude) * PI() / 180 / 2), 2)
-                    )
-                ) * 1000
-            , 2) AS distance
+        id,
+        name,
+        latitude,
+        longitude,
+        ROUND(
+        6378.137 * 2 * ASIN(
+        SQRT(
+        POW(SIN((#{latitude} - latitude) * PI() / 180 / 2), 2) +
+        COS(#{latitude} * PI() / 180) * COS(latitude * PI() / 180) *
+        POW(SIN((#{longitude} - longitude) * PI() / 180 / 2), 2)
+        )
+        ) * 1000
+        , 2) AS distance
         FROM b_station_info
-        WHERE 
-            is_delete = 0
-            AND latitude BETWEEN #{latitude} - #{radius} / 111300 AND #{latitude} + #{radius} / 111300
-            AND longitude BETWEEN #{longitude} - #{radius} / (111300 * COS(#{latitude} * PI() / 180))
-                                AND #{longitude} + #{radius} / (111300 * COS(#{latitude} * PI() / 180))
-        HAVING distance  &lt; #{radius}
+        WHERE
+        is_delete = 0
+        AND latitude BETWEEN #{latitude} -  #{radius} / 111300 AND #{latitude} + #{radius} / 111300
+        AND longitude BETWEEN #{longitude} - #{radius} / (111300 * COS(#{latitude} * PI() / 180))
+        AND #{longitude} + #{radius} / (111300 * COS(#{latitude} * PI() / 180))
+        AND (
+        6378.137 * 2 * ASIN(
+        SQRT(
+        POW(SIN((#{latitude} - latitude) * PI() / 180 / 2), 2) +
+        COS(#{latitude} * PI() / 180) * COS(latitude * PI() / 180) *
+        POW(SIN((#{longitude} - longitude) * PI() / 180 / 2), 2)
+        )
+        ) * 1000
+        ) &lt;= #{radius}
         ORDER BY distance
-        LIMIT #{BigDistance}
     </select>
 
     <!-- 查询经过指定站点的路线 -->

+ 3 - 4
bus-common/src/main/java/bus/model/dto/NearbyRoutesDto.java

@@ -8,11 +8,10 @@ import java.math.BigDecimal;
 @Data
 public class NearbyRoutesDto {
     @ApiModelProperty("纬度")
-    private BigDecimal latitude;
+    private String latitude;
     @ApiModelProperty("经度")
-    private BigDecimal longitude;
+    private String longitude;
     @ApiModelProperty("半径米")
     private Integer radius;
-    @ApiModelProperty("最大距离米")
-    private Integer bigDistance;
+
 }