| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xiaopeng.api.model.operation.XpCruisePlan; |
| | | import com.xiaopeng.api.model.operation.XpCruisePlanPoint; |
| | | import com.xiaopeng.api.model.operation.XpCruisePlanVehicle; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.mapper.XpCruisePlanMapper; |
| | | import com.xiaopeng.operation.query.CruisePlanQuery; |
| | | import com.xiaopeng.operation.service.IXpCruisePlanPointService; |
| | | import com.xiaopeng.operation.service.IXpCruisePlanService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.operation.service.IXpCruisePlanVehicleService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2026-02-26 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor(onConstructor_ = @Lazy) |
| | | public class XpCruisePlanServiceImpl extends ServiceImpl<XpCruisePlanMapper, XpCruisePlan> implements IXpCruisePlanService { |
| | | |
| | | private final IXpCruisePlanPointService xpCruisePlanPointService; |
| | | private final IXpCruisePlanVehicleService xpCruisePlanVehicleService; |
| | | |
| | | @Override |
| | | public PageInfo<XpCruisePlan> getPageList(CruisePlanQuery query) { |
| | | PageInfo<XpCruisePlan> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | Page<XpCruisePlan> page = lambdaQuery() |
| | | .like(StringUtils.isNotBlank(query.getPlanName()), XpCruisePlan::getPlanName, query.getPlanName()) |
| | | .orderByDesc(XpCruisePlan::getCreateTime) |
| | | .page(pageInfo); |
| | | |
| | | //收集巡游计划ID |
| | | List<Long> planIds = page.getRecords().stream().map(XpCruisePlan::getId).collect(Collectors.toList()); |
| | | // 批量查询巡游计划点位和车辆信息,并组装到巡游计划对象中 |
| | | Map<Long, List<XpCruisePlanPoint>> pointMap = CollUtil.isNotEmpty(planIds) ? xpCruisePlanPointService.lambdaQuery().in(XpCruisePlanPoint::getCruisePlanId, planIds) |
| | | .list().stream().collect(Collectors.groupingBy(XpCruisePlanPoint::getCruisePlanId)) : Collections.emptyMap(); |
| | | Map<Long, List<XpCruisePlanVehicle>> vehicleMap = CollUtil.isNotEmpty(planIds) ? xpCruisePlanVehicleService.lambdaQuery().in(XpCruisePlanVehicle::getCruisePlanId, planIds) |
| | | .list().stream().collect(Collectors.groupingBy(XpCruisePlanVehicle::getCruisePlanId)) : Collections.emptyMap(); |
| | | page.getRecords().forEach(plan -> { |
| | | plan.setPointNum(pointMap.get(plan.getId()).size()); |
| | | plan.setVehicleNum(vehicleMap.get(plan.getId()).size()); |
| | | }); |
| | | pageInfo.setRecords(page.getRecords()); |
| | | return pageInfo; |
| | | } |
| | | } |