zy 8 bulan lalu
induk
melakukan
f27368abc6

+ 3 - 1
bus-biz/src/main/java/bus/mapper/BCourseInfoMapper.java

@@ -24,6 +24,8 @@ public interface BCourseInfoMapper extends BaseMapper<BCourseInfoPo> {
 
     List<BStationInfoDto> findNearbyStations(@Param("longitude") BigDecimal longitude,
                                              @Param("latitude") BigDecimal latitude,
-                                             @Param("distance") Integer distance);
+                                             @Param("radius") Integer radius);
     List<BCourseInfoVo> findRoutesByStations(@Param("stationIds") List<String> stationIds);
+
+    List<BCourseInfoVo> findRoutesByStationId(@Param("stationIds") List<String> stationIds);
 }

+ 17 - 2
bus-biz/src/main/java/bus/service/BCourseInfoService.java

@@ -54,7 +54,14 @@ public interface BCourseInfoService extends IService<BCourseInfoPo> {
      */
     void delete(String id);
 
-    List<BBusTrackInfoDto> getNearbyRoutes(BigDecimal latitude, BigDecimal longitude, Integer radius);
+    /**
+     * 根据经纬度和半径(米)获取附近的路线
+     * @param latitude
+     * @param longitude
+     * @param radius
+     * @return
+     */
+    List<WBusTrackInfoDto> getNearbyRoutes(BigDecimal latitude, BigDecimal longitude, Integer radius);
 
     List<BCourseTrackTreeDto> getTreeList();
 
@@ -69,5 +76,13 @@ public interface BCourseInfoService extends IService<BCourseInfoPo> {
      * @param stationType
      * @return
      */
-    List<WCourseInfoByTypeDto> getAllCourseByType(String stationType);
+    List<WStationNameDto> getAllCourseByType(String stationType);
+
+
+    /**
+     * 根据站点类型获取路线信息
+     * @param
+     * @return
+     */
+    List<WCourseInfoByTypeDto> getMapAllCourse();
 }

+ 122 - 43
bus-biz/src/main/java/bus/service/impl/BCourseInfoServiceImpl.java

@@ -352,58 +352,85 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
 		bCourseInfoMapper.deleteById(id);
     }
 
+    /**
+     * 根据经纬度和半径(米)获取附近的路线
+     * @param latitude 纬度
+     * @param longitude 经度
+     * @param radius 半径(米)
+     * @return 附近的路线列表
+     */
     @Override
-    public List<BBusTrackInfoDto> getNearbyRoutes(BigDecimal latitude, BigDecimal longitude, Integer radius) {
+    public List<WBusTrackInfoDto> getNearbyRoutes(BigDecimal latitude, BigDecimal longitude, Integer radius) {
+        // 参数验证
+        if (latitude == null || longitude == null || radius == null) {
+            return Collections.emptyList();
+        }
+        
+        // 限制查询半径,最大10公里
+        int maxRadius = 10000;
+        if (radius <= 0 || radius > maxRadius) {
+            radius = maxRadius;
+        }
+
         // 1. 查询附近站点
         List<BStationInfoDto> nearbyStations = bCourseInfoMapper.findNearbyStations(latitude, longitude, radius);
         if (CollectionUtil.isEmpty(nearbyStations)) {
             return Collections.emptyList();
         }
+
         // 2. 查询经过这些站点的路线
         List<String> stationIds = nearbyStations.stream()
                 .map(BStationInfoDto::getId)
                 .collect(Collectors.toList());
 
-        List<BCourseInfoVo> routes = bCourseInfoMapper.findRoutesByStations(stationIds);
-
-        for (BCourseInfoVo route : routes) {
-            BBusTrackInfoDto dto = new BBusTrackInfoDto();
-           // vo.setRouteId(route.getId());
-//            vo.setRouteName(route.getName());
-//            vo.setStartStation(route.getStartStation());
-//            vo.setEndStation(route.getEndStation());
-//            vo.setFirstTime(route.getFirstTime());
-//            vo.setLastTime(route.getLastTime());
-//            vo.setPrice(route.getPrice());
+        // 3. 查询包含这些站点的路线信息
+        List<BCourseInfoVo> bUserCoursePos = bCourseInfoMapper.findRoutesByStationId(stationIds);
+        if (CollectionUtil.isEmpty(bUserCoursePos)) {
+            return Collections.emptyList();
         }
 
-        return null;
-
-//        // 3. 转换并返回结果
-//        return routes.stream().map(route -> {
-//            RouteVO vo = new RouteVO();
-//            vo.setRouteId(route.getId());
-//            vo.setRouteName(route.getName());
-//            vo.setStartStation(route.getStartStation());
-//            vo.setEndStation(route.getEndStation());
-//            vo.setFirstTime(route.getFirstTime());
-//            vo.setLastTime(route.getLastTime());
-//            vo.setPrice(route.getPrice());
-//            // 计算距离最近的站点
-//            StationDTO nearestStation = findNearestStation(
-//                    nearbyStations,
-//                    latitude,
-//                    longitude
-//            );
-//            vo.setNearestStation(nearestStation.getName());
-//            vo.setDistance(calculateDistance(
-//                    latitude,
-//                    longitude,
-//                    nearestStation.getLatitude(),
-//                    nearestStation.getLongitude()
-//            ));
-//            return vo;
-//        }).collect(Collectors.toList());
+        // 获取路线ID列表(去重)
+        List<String> courseIdList = bUserCoursePos.stream()
+                .map(BCourseInfoVo::getId)
+                .distinct()
+                .collect(Collectors.toList());
+
+        // 获取每个路线的详细信息
+        List<WBusTrackInfoDto> result = new ArrayList<>();
+        for(String courseId : courseIdList) {
+            BCourseInfoDto courseInfo = getDetailById(courseId);
+            if(courseInfo != null) {
+                // 构建路线追踪信息
+                WBusTrackInfoDto trackInfo = new WBusTrackInfoDto();
+                trackInfo.setCourseId(courseInfo.getId());
+                trackInfo.setCourseName(courseInfo.getCourseName());
+                trackInfo.setFirstStationName(courseInfo.getFirstStationName());
+                trackInfo.setLastStationName(courseInfo.getLastStationName());
+                trackInfo.setFirstBusSpace(courseInfo.getFirstBusSpace());
+                trackInfo.setTicketAmount(courseInfo.getTicketAmount());
+                
+                // 处理路线站点信息
+                List<BCoursePointDto> stationInfoList = courseInfo.getMapPointList();
+                trackInfo.setClist(stationInfoList);
+
+                // 车辆经纬度
+                List<BCourseBusDto> bCourseBusList = courseInfo.getBCourseBusList();
+                if (CollectionUtil.isNotEmpty(bCourseBusList)) {
+                    List<BCoursePointDto> bStationInfoList = new ArrayList<>();
+                    for(BCourseBusDto bCourseBus : bCourseBusList) {
+                        if (bCourseBus.getLocalLatitude() != null && bCourseBus.getLocalLongitude() != null) {
+                            BCoursePointDto bCoursePointDto = new BCoursePointDto();
+                            bCoursePointDto.setLongitude(bCourseBus.getLocalLongitude());
+                            bCoursePointDto.setLatitude(bCourseBus.getLocalLatitude());
+                            bStationInfoList.add(bCoursePointDto);
+                        }
+                    }
+                    trackInfo.setBlist(bStationInfoList);
+                }
+                result.add(trackInfo);
+            }
+        }
+        return result;
     }
 
     /**
@@ -529,11 +556,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
     /**
      * 根据站点类型获取路线信息
      *
-     * @param stationType
-     * @return
+     * @param stationType 站点类型
+     * @return 站点及其关联路线信息列表
      */
     @Override
-    public List<WCourseInfoByTypeDto> getAllCourseByType(String stationType) {
+    public List<WStationNameDto> getAllCourseByType(String stationType) {
         // 1. 查询指定类型的所有站点
         QueryWrapper<BStationInfoPo> stationWrapper = new QueryWrapper<>();
         stationWrapper.eq("station_type", stationType)
@@ -544,6 +571,58 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
             return Collections.emptyList();
         }
 
+        // 2. 获取站点ID集合
+        List<String> stationIds = stations.stream()
+                .map(BStationInfoPo::getId)
+                .collect(Collectors.toList());
+        // 3. 查询包含这些站点的路线信息
+        List<BCourseInfoVo> courses = bCourseInfoMapper.findRoutesByStations(stationIds);
+        // 4. 构建站点与路线的映射关系
+        Map<String, List<BCourseInfoVo>> courseMap = courses.stream()
+                .collect(Collectors.groupingBy(course -> course.getStationId()));
+
+        List<WStationNameDto>  newList = new ArrayList<>();
+
+        for (BStationInfoPo station : stations) {
+            List<BCourseInfoVo> course = courseMap.get(station.getId());
+            if (course != null) {
+                WStationNameDto dto =  new WStationNameDto();
+                dto.setId(station.getId());
+                dto.setStationName(station.getName());
+                List<WCourseInfoByTypeDto> list1 = new ArrayList<>();
+                for (BCourseInfoVo bCourseInfoVo : course) {
+                    WCourseInfoByTypeDto wCourseInfoByTypeDto = BeanUtil.toBean(bCourseInfoVo, WCourseInfoByTypeDto.class);
+                    String mapPoint = bCourseInfoVo.getMapPoint();
+                    if (StrUtil.isNotBlank(mapPoint)) {
+                        List<BCoursePointDto> fileJsons = JSONUtil.toList(mapPoint, BCoursePointDto.class);
+                        wCourseInfoByTypeDto.setMapPointList(fileJsons);
+                    }
+                    list1.add(wCourseInfoByTypeDto);
+                }
+                dto.setList(list1);
+                newList.add(dto);
+            }
+        }
+
+      return newList;
+    }
+
+    /**
+     * 根据站点类型获取路线信息
+     *
+     * @return
+     */
+    @Override
+    public List<WCourseInfoByTypeDto> getMapAllCourse() {
+        // 1. 查询指定类型的所有站点
+        QueryWrapper<BStationInfoPo> stationWrapper = new QueryWrapper<>();
+        stationWrapper.eq("is_delete", 0);
+        List<BStationInfoPo> stations = bStationInfoService.list(stationWrapper);
+
+        if (CollectionUtil.isEmpty(stations)) {
+            return Collections.emptyList();
+        }
+
         // 2. 获取站点ID集合
         List<String> stationIds = stations.stream()
                 .map(BStationInfoPo::getId)
@@ -555,7 +634,7 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
         // 4. 去重处理(基于线路ID)
         Map<String, BCourseInfoVo> uniqueCourses = courses.stream()
                 .collect(Collectors.toMap(
-                        BCourseInfoVo::getId, 
+                        BCourseInfoVo::getId,
                         course -> course,
                         (existing, replacement) -> existing));
 

+ 50 - 16
bus-biz/src/main/resources/mapper/BCourseInfoMapper.xml

@@ -46,23 +46,28 @@
     <!-- 查询附近站点 -->
     <select id="findNearbyStations" resultType="bus.model.dto.BStationInfoDto">
         SELECT
-        id,
-        name,
-        latitude,
-        longitude,
-        (
-        6378137 * acos(
-        cos(radians(#{latitude})) *
-        cos(radians(latitude)) *
-        cos(radians(longitude) - radians(#{longitude})) +
-        sin(radians(#{latitude})) *
-        sin(radians(latitude))
-        )
-        ) 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
-        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))
+        HAVING distance  &lt; #{radius}
         ORDER BY distance
+        LIMIT 50
     </select>
 
     <!-- 查询经过指定站点的路线 -->
@@ -76,14 +81,43 @@
         r.last_station_name as lastStationName,
         r.first_bus_space as firstBusSpace,
         r.area as area,
-        r.map_point as mapPoint
+        r.map_point as mapPoint,
+        rs.station_id as stationId
+        FROM
+        b_course_info r
+        INNER JOIN
+        b_course_station rs ON r.id = rs.course_id
+        WHERE
+        r.is_delete = 0
+        and rs.is_delete = 0
+        AND rs.station_id IN
+        <foreach collection="stationIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        ORDER BY
+        rs.id
+    </select>
 
+    <!-- 查询经过指定站点的路线 -->
+    <select id="findRoutesByStationId" resultType="bus.model.vo.BCourseInfoVo">
+        SELECT DISTINCT
+        r.id,
+        r.course_name as courseName,
+        r.course_code as courseCode,
+        r.map_pic_url as mapPicUrl,
+        r.first_station_name as firstStationName,
+        r.last_station_name as lastStationName,
+        r.first_bus_space as firstBusSpace,
+        r.area as area,
+        r.map_point as mapPoint,
+        rs.station_id as stationId
         FROM
         b_course_info r
         INNER JOIN
         b_course_station rs ON r.id = rs.course_id
         WHERE
         r.is_delete = 0
+        and rs.is_delete = 0
         AND rs.station_id IN
         <foreach collection="stationIds" item="id" open="(" separator="," close=")">
             #{id}

+ 0 - 1
bus-biz/src/main/resources/mapper/BNoticeInfoMapper.xml

@@ -9,7 +9,6 @@
    content,
    type,
    pub_time,
-   is_read,
    status
    from
    b_notice_info

+ 12 - 0
bus-common/src/main/java/bus/model/dto/WStationNameDto.java

@@ -0,0 +1,12 @@
+package bus.model.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class WStationNameDto {
+    private String id;
+    private String stationName;
+    private List<WCourseInfoByTypeDto> list;
+}

+ 1 - 1
bus-common/src/main/java/bus/model/dto/page/WChatUserPageDto.java

@@ -17,7 +17,7 @@ import java.util.Date;
 **/
 @Data
 public class WChatUserPageDto extends BaseEntity{
-
+    private String id;
     @ApiModelProperty("微信昵称")
     private String wxName;
     @ApiModelProperty("微信号码")

+ 3 - 0
bus-common/src/main/java/bus/model/vo/BCourseInfoVo.java

@@ -15,6 +15,9 @@ import java.util.Date;
 **/
 @Data
 public class BCourseInfoVo extends AbstractBaseVO{
+
+    @ApiModelProperty("站点id")
+    private String stationId;
     @ApiModelProperty("id")
     private String id;
     @ApiModelProperty("线路名称")

+ 31 - 1
bus-web/src/main/java/bus/controller/biz/BCourseInfoController.java

@@ -1,6 +1,8 @@
 package bus.controller.biz;
 
+import bus.model.dto.WBusTrackInfoDto;
 import bus.model.dto.WCourseInfoByTypeDto;
+import bus.model.dto.WStationNameDto;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageSerializable;
 import bus.model.dto.BCourseInfoDto;
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
 import com.qzwisdom.qzframework.core.tool.base.controller.BaseController;
 
 import javax.validation.Valid;
+import java.math.BigDecimal;
 import java.util.List;
 
 
@@ -103,8 +106,35 @@ public class BCourseInfoController implements BaseController {
      */
     @ApiOperation("根据站点类型获取路线信息")
     @GetMapping(value = "getAllCourseByType")
-    List<WCourseInfoByTypeDto> getAllCourseByType(@RequestParam String stationType){
+    List<WStationNameDto> getAllCourseByType(@RequestParam String stationType){
         return bCourseInfoService.getAllCourseByType(stationType);
     }
 
+    /**
+     * 根据站点类型获取路线信息
+     * @param
+     * @return
+     */
+    @ApiOperation("地图所有线路信息")
+    @GetMapping(value = "getMapAllCourse")
+    List<WCourseInfoByTypeDto> getMapAllCourse(){
+        return bCourseInfoService.getMapAllCourse();
+    }
+
+
+    /**
+     * 根据经纬度和半径(米)获取附近的路线
+     * @param latitude
+     * @param longitude
+     * @param radius
+     * @return
+     */
+    @ApiOperation("根据经纬度和半径(米)获取附近的路线")
+    @GetMapping(value = "getNearbyRoutes")
+    List<WBusTrackInfoDto> getNearbyRoutes(@RequestParam BigDecimal latitude,
+                                           @RequestParam BigDecimal longitude,
+                                           @RequestParam Integer radius){
+        return bCourseInfoService.getNearbyRoutes(latitude,longitude,radius);
+    }
+
 }