|
|
@@ -199,14 +199,76 @@ public class BBusInfoServiceImpl extends ServiceImpl<BBusInfoMapper,BBusInfoPo>
|
|
|
*/
|
|
|
@Override
|
|
|
public BBusTrackInfoDto getTrackInfo(String busId) {
|
|
|
- QueryWrapper<BCourseBusPo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("bus_id", busId);
|
|
|
- queryWrapper.eq("is_delete", 0);
|
|
|
- BCourseBusPo one = bCourseBusService.getOne(queryWrapper);
|
|
|
+ BBusTrackInfoDto dto = new BBusTrackInfoDto();
|
|
|
+ // 1. 查询车辆所在路线,获取最新分配的路线
|
|
|
+ QueryWrapper<BCourseBusPo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("bus_id", busId)
|
|
|
+ .eq("is_delete", 0)
|
|
|
+ .orderByDesc("create_time") // 按创建时间倒序
|
|
|
+ .last("LIMIT 1"); // 只取最新的一条记录
|
|
|
+ BCourseBusPo courseBus = bCourseBusService.getOne(queryWrapper);
|
|
|
+ if (courseBus == null) {
|
|
|
+ throw new BusinessException("该车辆未分配路线");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取路线信息
|
|
|
+ String courseId = courseBus.getCourseId();
|
|
|
+ BCourseInfoPo courseInfo = bCourseInfoService.getById(courseId);
|
|
|
+ if (courseInfo == null) {
|
|
|
+ throw new BusinessException("该路线不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取车辆信息
|
|
|
+ BBusInfoPo busInfo = this.getById(busId);
|
|
|
+ if (busInfo == null) {
|
|
|
+ throw new BusinessException("车辆不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 设置基本信息
|
|
|
+ dto.setBusId(busId);
|
|
|
+ dto.setBusNo(busInfo.getBusNo());
|
|
|
+ dto.setCourseName(courseInfo.getCourseName());
|
|
|
+ dto.setFirstStationName(courseInfo.getFirstStationName());
|
|
|
+ dto.setLastStationName(courseInfo.getLastStationName());
|
|
|
|
|
|
- return null;
|
|
|
+ // 5. 设置车辆追踪信息
|
|
|
+ BBusTrackByBusDto trackByBusDto = new BBusTrackByBusDto();
|
|
|
+ trackByBusDto.setDriverName(busInfo.getDriverName());
|
|
|
+ trackByBusDto.setDriverPhone(busInfo.getDriverPhone());
|
|
|
+ trackByBusDto.setStatus(busInfo.getStatus());
|
|
|
+ trackByBusDto.setCourseName(courseInfo.getCourseName());
|
|
|
+ // TODO: 这里需要集成实时定位服务来获取车辆的当前位置信息
|
|
|
+ dto.setBBusTrackByBusDto(trackByBusDto);
|
|
|
+
|
|
|
+ // 6. 获取路线站点信息
|
|
|
+ List<BCourseStationPo> stationList = bCourseStationService.getListByCourse(courseId);
|
|
|
+ if (CollectionUtil.isNotEmpty(stationList)) {
|
|
|
+ List<BCourseNameInfoDto> courseNameInfoList = new ArrayList<>();
|
|
|
+ List<String> stationIds = stationList.stream()
|
|
|
+ .map(BCourseStationPo::getStationId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ bStationInfoService.listByIds(stationIds).forEach(stationInfo -> {
|
|
|
+ BCourseNameInfoDto courseNameInfo = new BCourseNameInfoDto();
|
|
|
+ courseNameInfo.setId(stationInfo.getId());
|
|
|
+ List<BStationPointDto> pointList = new ArrayList<>();
|
|
|
+ BStationPointDto point = new BStationPointDto();
|
|
|
+ point.setId(stationInfo.getId());
|
|
|
+ point.setName(stationInfo.getName());
|
|
|
+ point.setLatitude(stationInfo.getLatitude());
|
|
|
+ point.setLongitude(stationInfo.getLongitude());
|
|
|
+ pointList.add(point);
|
|
|
+ courseNameInfo.setSlist(pointList);
|
|
|
+ courseNameInfoList.add(courseNameInfo);
|
|
|
+ });
|
|
|
+
|
|
|
+ dto.setBCourseNameInfoList(courseNameInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return dto;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public BTrackStationDto getPoint(String busId) {
|
|
|
BTrackStationDto dto = new BTrackStationDto();
|
|
|
QueryWrapper<BCourseBusPo> queryWrapper = new QueryWrapper();
|