|
|
@@ -132,9 +132,7 @@ export class RouteService extends GenericCrudService<RouteEntity> {
|
|
|
.leftJoinAndSelect('endLocation.city', 'endLocation_city')
|
|
|
.leftJoinAndSelect('endLocation.district', 'endLocation_district')
|
|
|
.leftJoinAndSelect('route.activity', 'activity')
|
|
|
- .where(where)
|
|
|
- .skip((page - 1) * pageSize)
|
|
|
- .take(pageSize);
|
|
|
+ .where(where);
|
|
|
|
|
|
// 添加排序
|
|
|
if (sortBy === 'price') {
|
|
|
@@ -143,10 +141,11 @@ export class RouteService extends GenericCrudService<RouteEntity> {
|
|
|
query.orderBy('route.departureTime', sortOrder);
|
|
|
}
|
|
|
|
|
|
- const [routes] = await query.getManyAndCount();
|
|
|
+ // 先获取所有符合条件的路线进行内存筛选
|
|
|
+ const allRoutes = await query.getMany();
|
|
|
|
|
|
// 根据省市区筛选(如果提供了省市区ID)
|
|
|
- let filteredRoutes = routes;
|
|
|
+ let filteredRoutes = allRoutes;
|
|
|
|
|
|
if (startAreaIds && startAreaIds.length > 0) {
|
|
|
filteredRoutes = filteredRoutes.filter(route => {
|
|
|
@@ -167,6 +166,12 @@ export class RouteService extends GenericCrudService<RouteEntity> {
|
|
|
filteredRoutes = filteredRoutes.filter(route => route.routeType === routeType);
|
|
|
}
|
|
|
|
|
|
+ // 应用分页
|
|
|
+ const total = filteredRoutes.length;
|
|
|
+ const startIndex = (page - 1) * pageSize;
|
|
|
+ const endIndex = startIndex + pageSize;
|
|
|
+ const paginatedRoutes = filteredRoutes.slice(startIndex, endIndex);
|
|
|
+
|
|
|
// 获取去重后的活动列表
|
|
|
const activityIds = Array.from(new Set(filteredRoutes.map(route => route.activityId)));
|
|
|
const activities = activityIds.length > 0
|
|
|
@@ -177,13 +182,13 @@ export class RouteService extends GenericCrudService<RouteEntity> {
|
|
|
: [];
|
|
|
|
|
|
return {
|
|
|
- routes: filteredRoutes,
|
|
|
+ routes: paginatedRoutes,
|
|
|
activities,
|
|
|
pagination: {
|
|
|
page,
|
|
|
pageSize,
|
|
|
- total: filteredRoutes.length,
|
|
|
- totalPages: Math.ceil(filteredRoutes.length / pageSize)
|
|
|
+ total,
|
|
|
+ totalPages: Math.ceil(total / pageSize)
|
|
|
}
|
|
|
};
|
|
|
}
|