|
|
@@ -202,39 +202,55 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
|
|
|
@Override
|
|
|
// @DynamicCache 有参接口有bug,例如搜索接口,会缓存历史搜索的结果返回,与预期不符
|
|
|
public PageBean<SimpleStationVo> listStationForApp(StationQueryParam params) {
|
|
|
- PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
- // 站点列表
|
|
|
- LambdaQueryWrapper<Station> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.select(Station::getStationId, Station::getStationName, Station::getAddress, Station::getLocation,
|
|
|
- Station::getStationStatus, Station::getParkingNum, Station::getElectricityFee, Station::getServiceFee, Station::getParkFee);
|
|
|
- queryWrapper.in(CommUtil.isNotEmptyAndNull(params.getStationIdList()), Station::getStationId, params.getStationIdList());
|
|
|
- var stationVoList = list(queryWrapper).stream()
|
|
|
- .map(station -> buildSimpleStationVo(station, params))
|
|
|
- .collect(Collectors.toCollection(ArrayList::new));
|
|
|
- // 按照距离由近到远排序
|
|
|
- stationVoList.sort(Comparator.comparing(SimpleStationVo::getDistance));
|
|
|
+ var stationVoList = listSortedStations(params);
|
|
|
+ var page = pageOf(stationVoList, params);
|
|
|
// 计算并填充站点空闲数量
|
|
|
- fillAvailableParkingNum(stationVoList);
|
|
|
+ fillAvailableParkingNum(page.getList());
|
|
|
// 填充站点活动信息
|
|
|
- fillActivityList(stationVoList);
|
|
|
- return new PageBean<>(stationVoList);
|
|
|
+ fillActivityList(page.getList());
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageBean<SimpleStationVo> listStationForMap(StationQueryParam params) {
|
|
|
- PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
- // 站点列表(仅查询地图展示所需的基础字段)
|
|
|
+ // 不查询枪统计与活动信息,由前端点击站点时通过 listStationCard 按需查询
|
|
|
+ return pageOf(listSortedStations(params), params);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 全量查询未下线站点并按距离由近到远排序(先排序后分页,保证跨页距离有序)
|
|
|
+ */
|
|
|
+ private List<SimpleStationVo> listSortedStations(StationQueryParam params) {
|
|
|
+ // 站点列表(仅查询展示所需的基础字段)
|
|
|
LambdaQueryWrapper<Station> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.select(Station::getStationId, Station::getStationName, Station::getAddress, Station::getLocation,
|
|
|
Station::getStationStatus, Station::getParkingNum, Station::getElectricityFee, Station::getServiceFee, Station::getParkFee);
|
|
|
queryWrapper.in(CommUtil.isNotEmptyAndNull(params.getStationIdList()), Station::getStationId, params.getStationIdList());
|
|
|
- var stationVoList = list(queryWrapper).stream()
|
|
|
+ // 过滤已下线站点
|
|
|
+ queryWrapper.ne(Station::getStationStatus, Station.STATION_STATUS_关闭下线);
|
|
|
+ return list(queryWrapper).stream()
|
|
|
.map(station -> buildSimpleStationVo(station, params))
|
|
|
+ .sorted(Comparator.comparing(SimpleStationVo::getDistance))
|
|
|
.collect(Collectors.toCollection(ArrayList::new));
|
|
|
- // 按照距离由近到远排序
|
|
|
- stationVoList.sort(Comparator.comparing(SimpleStationVo::getDistance));
|
|
|
- // 不查询枪统计与活动信息,由前端点击站点时通过 listStationCard 按需查询
|
|
|
- return new PageBean<>(stationVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内存分页:站点数量有限,全量排序后截取当前页;分页参数加上限,防止一次拉取全表
|
|
|
+ */
|
|
|
+ private PageBean<SimpleStationVo> pageOf(List<SimpleStationVo> stationVoList, StationQueryParam params) {
|
|
|
+ int pageNum = Math.max(params.getPageNum(), 1);
|
|
|
+ int pageSize = Math.min(Math.max(params.getPageSize(), 1), 50);
|
|
|
+ int from = (pageNum - 1) * pageSize;
|
|
|
+ List<SimpleStationVo> pageList = from >= stationVoList.size()
|
|
|
+ ? List.of()
|
|
|
+ : new ArrayList<>(stationVoList.subList(from, Math.min(from + pageSize, stationVoList.size())));
|
|
|
+ var pageBean = new PageBean<>(pageList);
|
|
|
+ pageBean.setTotal(stationVoList.size());
|
|
|
+ pageBean.setPageNum(pageNum);
|
|
|
+ pageBean.setPageSize(pageSize);
|
|
|
+ pageBean.setSize(pageList.size());
|
|
|
+ pageBean.setPages(pageSize > 0 ? (stationVoList.size() + pageSize - 1) / pageSize : 0);
|
|
|
+ return pageBean;
|
|
|
}
|
|
|
|
|
|
@Override
|