|
|
@@ -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));
|
|
|
|