liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
package com.xiaopeng.operation.controller;
 
 
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaopeng.api.dto.map.OrderRouteAndFareDto;
import com.xiaopeng.api.dto.operation.CruisePointDto;
import com.xiaopeng.api.dto.operation.LonLatDto;
import com.xiaopeng.api.dto.operation.NewCruiseOrderDto;
import com.xiaopeng.api.feignClient.map.XpMapClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
import com.xiaopeng.api.model.operation.*;
import com.xiaopeng.api.model.order.XpCruiseOrder;
import com.xiaopeng.api.vo.operation.RouteVo;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
import com.xiaopeng.common.redis.service.RedisService;
import com.xiaopeng.operation.dto.XpCruisePlanAddDTO;
import com.xiaopeng.operation.dto.XpCruisePlanEditDTO;
import com.xiaopeng.operation.query.CruisePlanQuery;
import com.xiaopeng.operation.service.*;
import com.xiaopeng.operation.vo.XpCruisePlanDetailVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
 
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.validation.Valid;
 
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.ApiParam;
 
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.xiaopeng.common.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
 
/**
 * <p>
 * 巡游计划 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2026-02-26
 */
@Validated
@RestController
@RequiredArgsConstructor(onConstructor_ = @Lazy)
public class XpCruisePlanController {
    private final IXpCruisePlanService xpCruisePlanService;
    private final IXpCruisePlanVehicleService xpCruisePlanVehicleService;
    private final IXpCruisePlanPointService xpCruisePlanPointService;
    private final XpPointService pointService;
    private final XpVehicleClient xpVehicleClient;
 
    @Resource
    private XpTargetedServiceVehicleService xpTargetedServiceVehicleService;
 
    @Resource
    private XpTargetedServiceService xpTargetedServiceService;
 
    @Resource
    private XpMapClient xpMapClient;
 
    @Resource
    private RedisService redisService;
 
    @Resource(name = "hutoolSnowflake")
    private Snowflake snowflake;
 
    @ApiOperation(value = "获取巡游计划分页列表", tags = {"管理后台-巡游计划"})
    @PostMapping(value = {"/api/v1/xp-cruise-plan/pageList"})
    public R<PageInfo<XpCruisePlan>> getPageList(@RequestBody CruisePlanQuery query) {
        return R.ok(xpCruisePlanService.getPageList(query));
    }
 
    @ApiOperation(value = "新增巡游计划", tags = {"管理后台-巡游计划"})
    @PostMapping(value = {"/api/v1/xp-cruise-plan/add"})
    @AdminOperationLog(
            businessType = AdminBusinessType.CRUISE_PLAN,
            operationType = AdminOperationType.ADD,
            content = "新增巡游计划",
            appendRequestData = true
    )
    public R<?> add(@Valid @RequestBody XpCruisePlanAddDTO dto) {
        xpCruisePlanService.add(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "编辑巡游计划", tags = {"管理后台-巡游计划"})
    @PostMapping(value = {"/api/v1/xp-cruise-plan/edit"})
    @AdminOperationLog(
            businessType = AdminBusinessType.CRUISE_PLAN,
            operationType = AdminOperationType.EDIT,
            content = "编辑巡游计划",
            appendRequestData = true
    )
    public R<?> edit(@Valid @RequestBody XpCruisePlanEditDTO dto) {
        xpCruisePlanService.edit(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "删除巡游计划", tags = {"管理后台-巡游计划"})
    @DeleteMapping(value = {"/api/v1/xp-cruise-plan/deleteById/{id}"})
    @AdminOperationLog(
            businessType = AdminBusinessType.CRUISE_PLAN,
            operationType = AdminOperationType.DELETE,
            contentExpression = "'删除巡游计划,id=' + #p0",
            appendRequestData = false
    )
    public R<?> deleteById(@ApiParam(name = "id", value = "巡游计划ID") @PathVariable Long id) {
        xpCruisePlanService.deleteById(id);
        return R.ok();
    }
 
    @ApiOperation(value = "巡游计划详情", tags = {"管理后台-巡游计划"})
    @GetMapping(value = {"/api/v1/xp-cruise-plan/detail"})
    public R<XpCruisePlanDetailVO> detail(@ApiParam(name = "id", value = "巡游计划ID") @RequestParam Long id) {
        return R.ok(xpCruisePlanService.detail(id));
    }
 
 
    /**
     * 获取车辆下个点位
     * @return
     */
    @PostMapping("/logan/inner/cruise/getCruisePoint")
    public R<XpCruiseOrder> getCruisePoint(@RequestBody CruisePointDto dto) {
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, dto.getVehicleId()));
        Long cruisePlanId = null;
        if (plan == null) {
            //没有巡游计划,判断是否在定向服务里面
            List<XpTargetedService> targetedServices = xpTargetedServiceService.list(new QueryWrapper<XpTargetedService>().eq("status", 1));
            if(targetedServices.isEmpty()){
                return R.fail("没有巡游计划");
            }
            List<Long> collect1 = targetedServices.stream().map(XpTargetedService::getId).collect(Collectors.toList());
            List<XpTargetedServiceVehicle> list = xpTargetedServiceVehicleService.list(new QueryWrapper<XpTargetedServiceVehicle>().in("targeted_service_id", collect1)
                    .eq("vehicle_id", dto.getVehicleId()));
            if(list.isEmpty()){
                return R.fail("没有巡游计划");
            }
            cruisePlanId = list.get(0).getCruisePlanId();
        }else{
            cruisePlanId = plan.getCruisePlanId();
        }
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>().eq(XpCruisePlanPoint::getCruisePlanId, cruisePlanId).orderByAsc(XpCruisePlanPoint::getSortOrder));
        // 找到现在这个点位
        // 根据dto的pointId 是第几个
        int index = 0;
        for (int i = 0; i < planPointList.size(); i++) {
            if (planPointList.get(i).getPointId().equals(dto.getPointId())) {
                index = i;
                break;
            }
        }
        XpCruiseOrder newXpCruiseOrder = dto.getNewXpCruiseOrder();
        XpCruisePlanPoint xpCruisePlanPoint = null;
        //   判断是否是最后一个 是则往前一个  否找下一个
        if (index == planPointList.size() - 1) {
            // 最后一个 找上一个
            xpCruisePlanPoint = planPointList.get(index - 1);
            newXpCruiseOrder.setOrderReverse(2);
        } else if (index == 0) {
            // 第一个 找下一个
            xpCruisePlanPoint = planPointList.get(index + 1);
            newXpCruiseOrder.setOrderReverse(1);
        } else {
            // 中间点位
            if (dto.getOrderReverse() == 1) {
                // 正向 找下一个
                xpCruisePlanPoint = planPointList.get(index + 1);
                newXpCruiseOrder.setOrderReverse(1);
            } else {
                // 反向找上一个
                xpCruisePlanPoint = planPointList.get(index - 1);
                newXpCruiseOrder.setOrderReverse(2);
            }
        }
        Long pointId = xpCruisePlanPoint.getPointId();
        XpPoint point = pointService.getById(pointId);
 
        newXpCruiseOrder.setEndPointId(pointId);
        newXpCruiseOrder.setEndPointName(point.getPointName());
        newXpCruiseOrder.setEndLon(point.getPointLon());
        newXpCruiseOrder.setEndLat(point.getPointLat());
        newXpCruiseOrder.setMissionId(xpCruisePlanPoint.getCruisePlanId());
 
        //获取巡游导航数据,如果无法获取到有效的导航,则继续用下一个点位作为终点
        LonLatDto destination = new LonLatDto();
        LonLatDto origin = new LonLatDto();
        boolean ROUTE_FLAG = false;
        boolean start = false;
        if(newXpCruiseOrder.getOrderReverse() == 1){
            for (XpCruisePlanPoint xpCruisePlanPoint1 : planPointList) {
                if (start || xpCruisePlanPoint1.getPointId().equals(newXpCruiseOrder.getEndPointId())) {
                    start = true;
                    origin.setLongitude(newXpCruiseOrder.getStartLon());
                    origin.setLatitude(newXpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + newXpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }else{
            for (int i = planPointList.size() - 1; i >= 0; i--) {
                XpCruisePlanPoint xpCruisePlanPoint1 = planPointList.get(i);
                if(start || xpCruisePlanPoint1.getPointId().equals(newXpCruiseOrder.getEndPointId())){
                    start = true;
                    origin.setLongitude(newXpCruiseOrder.getStartLon());
                    origin.setLatitude(newXpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + newXpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }
        if(!ROUTE_FLAG){
            return R.fail("巡游计划获取导航信息失败");
        }
        return R.ok(newXpCruiseOrder);
    }
 
    /**
     * 获取巡游计划
     * @param vehicleId
     * @return
     */
    @PostMapping("/logan/inner/cruise/getCruisePlan")
    public R<XpCruisePlanVehicle> getCruisePlan(@RequestParam Long vehicleId) {
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, vehicleId));
        return R.ok(plan);
    }
 
 
    /**
     * 获取巡游计划点位列表
     * @param vehicleId
     * @return
     */
    @PostMapping("/logan/inner/cruise/getCruisePlanPointList")
    public R<List<XpCruisePlanPoint>> getCruisePlanPointList(@RequestParam Long vehicleId) {
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, vehicleId));
        Long cruisePlanId = null;
        if(null == plan){
            //没有巡游计划,判断是否在定向服务里面
            List<XpTargetedService> targetedServices = xpTargetedServiceService.list(new QueryWrapper<XpTargetedService>().eq("status", 1));
            if(targetedServices.isEmpty()){
                return R.fail("没有巡游计划,执行收车失败");
            }
            List<Long> collect1 = targetedServices.stream().map(XpTargetedService::getId).collect(Collectors.toList());
            List<XpTargetedServiceVehicle> list = xpTargetedServiceVehicleService.list(new QueryWrapper<XpTargetedServiceVehicle>().in("targeted_service_id", collect1)
                    .eq("vehicle_id", vehicleId));
            if(list.isEmpty()){
                return R.fail("没有巡游计划,执行收车失败");
            }
            cruisePlanId = list.get(0).getCruisePlanId();
        }else{
            cruisePlanId = plan.getCruisePlanId();
        }
 
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>()
                .eq(XpCruisePlanPoint::getCruisePlanId, cruisePlanId).orderByAsc(XpCruisePlanPoint::getSortOrder));
        return R.ok(planPointList);
    }
 
 
 
 
    /**
     * 获取巡游订单数据
     * @return
     */
    @PostMapping("/logan/inner/cruise/getNewCruiseOrder")
    public R<XpCruiseOrder> getNewCruiseOrder(@RequestBody NewCruiseOrderDto dto) {
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, dto.getVehicleId()));
        if(null == plan){
            //没有巡游计划,判断是否在定向服务里面
            List<XpTargetedService> targetedServices = xpTargetedServiceService.list(new QueryWrapper<XpTargetedService>().eq("status", 1));
            if(targetedServices.isEmpty()){
                return R.ok(null);
            }
            List<Long> collect1 = targetedServices.stream().map(XpTargetedService::getId).collect(Collectors.toList());
            List<XpTargetedServiceVehicle> list = xpTargetedServiceVehicleService.list(new QueryWrapper<XpTargetedServiceVehicle>().in("targeted_service_id", collect1)
                    .eq("vehicle_id", dto.getVehicleId()));
            if(list.isEmpty()){
                return R.ok(null);
            }
            plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>()
                    .eq(XpCruisePlanVehicle::getCruisePlanId, list.get(0).getCruisePlanId()).eq(XpCruisePlanVehicle::getVehicleId, dto.getVehicleId()));
        }
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>().eq(XpCruisePlanPoint::getCruisePlanId, plan.getCruisePlanId()).orderByAsc(XpCruisePlanPoint::getSortOrder));
 
        XpCruiseOrder newXpCruiseOrder = new XpCruiseOrder();
        newXpCruiseOrder.setFleetId(dto.getFleetId());
        newXpCruiseOrder.setVehicleId(dto.getVehicleId());
        newXpCruiseOrder.setVehicleVin(dto.getVehicleVin());
        newXpCruiseOrder.setOrderType(1);
        newXpCruiseOrder.setMissionId(plan.getCruisePlanId());
        newXpCruiseOrder.setStatus(1);
        newXpCruiseOrder.setOrderReverse(1);
        newXpCruiseOrder.setXpuTaskId(snowflake.nextId() + "");
 
        GeoJsonPoint point = dto.getPoint();
 
        // 起点
        newXpCruiseOrder.setStartLon(point.getX());
        newXpCruiseOrder.setStartLat(point.getY());
 
        // 终点
        XpCruisePlanPoint endCruisePlanPoint = planPointList.get(0);
        Long endPointId = endCruisePlanPoint.getPointId();
        XpPoint endPoint = pointService.getById(endPointId);
        newXpCruiseOrder.setEndPointId(endPointId);
        newXpCruiseOrder.setEndPointName(endPoint.getPointName());
        newXpCruiseOrder.setEndLon(endPoint.getPointLon());
        newXpCruiseOrder.setEndLat(endPoint.getPointLat());
 
        //获取巡游导航数据,如果无法获取到有效的导航,则继续用下一个点位作为终点
        LonLatDto destination = new LonLatDto();
        LonLatDto origin = new LonLatDto();
        boolean ROUTE_FLAG = false;
        boolean start = false;
        if(newXpCruiseOrder.getOrderReverse() == 1){
            for (XpCruisePlanPoint xpCruisePlanPoint1 : planPointList) {
                if (start || xpCruisePlanPoint1.getPointId().equals(newXpCruiseOrder.getEndPointId())) {
                    start = true;
                    origin.setLongitude(newXpCruiseOrder.getStartLon());
                    origin.setLatitude(newXpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + newXpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }else{
            for (int i = planPointList.size() - 1; i >= 0; i--) {
                XpCruisePlanPoint xpCruisePlanPoint1 = planPointList.get(i);
                if(start || xpCruisePlanPoint1.getPointId().equals(newXpCruiseOrder.getEndPointId())){
                    start = true;
                    origin.setLongitude(newXpCruiseOrder.getStartLon());
                    origin.setLatitude(newXpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + newXpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }
        if(!ROUTE_FLAG){
            return R.fail("巡游计划获取导航信息失败");
        }
 
 
        return R.ok(newXpCruiseOrder);
    }
 
 
    /**
     * 获取车辆返回点位
     * @param xpCruiseOrder
     * @return
     */
    @PostMapping("/logan/inner/cruise/findReturnCruisePoint")
    public R<XpCruiseOrder> findReturnCruisePoint(@RequestBody XpCruiseOrder xpCruiseOrder) {
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, xpCruiseOrder.getVehicleId()));
        if(null == plan){
            //没有巡游计划,判断是否在定向服务里面
            List<XpTargetedService> targetedServices = xpTargetedServiceService.list(new QueryWrapper<XpTargetedService>().eq("status", 1));
            if(targetedServices.isEmpty()){
                return R.fail("没有巡游计划,执行收车失败");
            }
            List<Long> collect1 = targetedServices.stream().map(XpTargetedService::getId).collect(Collectors.toList());
            List<XpTargetedServiceVehicle> list = xpTargetedServiceVehicleService.list(new QueryWrapper<XpTargetedServiceVehicle>().in("targeted_service_id", collect1)
                    .eq("vehicle_id", xpCruiseOrder.getVehicleId()));
            if(list.isEmpty()){
                return R.fail("没有巡游计划,执行收车失败");
            }
            plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>()
                    .eq(XpCruisePlanVehicle::getCruisePlanId, list.get(0).getCruisePlanId()).eq(XpCruisePlanVehicle::getVehicleId, xpCruiseOrder.getVehicleId()));
        }
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>().eq(XpCruisePlanPoint::getCruisePlanId, plan.getCruisePlanId()).orderByAsc(XpCruisePlanPoint::getSortOrder));
 
        XpPoint xpPoint = pointService.list(new LambdaQueryWrapper<XpPoint>().eq(XpPoint::getParkingPoint, 1).in(XpPoint::getId, planPointList.stream().map(XpCruisePlanPoint::getPointId).collect(Collectors.toList()))).get(0);
        xpCruiseOrder.setEndPointId(xpPoint.getId());
        xpCruiseOrder.setEndPointName(xpPoint.getPointName());
        xpCruiseOrder.setEndLon(xpPoint.getPointLon());
        xpCruiseOrder.setEndLat(xpPoint.getPointLat());
        xpCruiseOrder.setMissionId(plan.getCruisePlanId());
 
        //获取巡游导航数据,如果无法获取到有效的导航,则继续用下一个点位作为终点
        LonLatDto destination = new LonLatDto();
        LonLatDto origin = new LonLatDto();
        boolean ROUTE_FLAG = false;
        boolean start = false;
        if(xpCruiseOrder.getOrderReverse() == 1){
            for (XpCruisePlanPoint xpCruisePlanPoint1 : planPointList) {
                if (start || xpCruisePlanPoint1.getPointId().equals(xpCruiseOrder.getEndPointId())) {
                    start = true;
                    origin.setLongitude(xpCruiseOrder.getStartLon());
                    origin.setLatitude(xpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + xpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }else{
            for (int i = planPointList.size() - 1; i >= 0; i--) {
                XpCruisePlanPoint xpCruisePlanPoint1 = planPointList.get(i);
                if(start || xpCruisePlanPoint1.getPointId().equals(xpCruiseOrder.getEndPointId())){
                    start = true;
                    origin.setLongitude(xpCruiseOrder.getStartLon());
                    origin.setLatitude(xpCruiseOrder.getStartLat());
                    XpPoint xpPoint1 = pointService.getById(xpCruisePlanPoint1.getPointId());
                    destination.setLongitude(xpPoint1.getPointLon());
                    destination.setLatitude(xpPoint1.getPointLat());
                    OrderRouteAndFareDto dto1 = new OrderRouteAndFareDto();
                    dto1.setOrigin(origin);
                    dto1.setDestination(destination);
                    dto1.setRouteType(3);
                    R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto1);
                    if (200 != routeVoR.getCode()) {
                        continue;
                    }
                    RouteVo routeVo = routeVoR.getData();
                    redisService.setCacheObject("CRUISE_ROUTE:" + xpCruiseOrder.getVehicleId(), JSON.toJSONString(routeVo), 24L, TimeUnit.DAYS);
                    ROUTE_FLAG = true;
                    break;
                }
            }
        }
        if(!ROUTE_FLAG){
            return R.fail("巡游计划获取导航信息失败");
        }
        return R.ok(xpCruiseOrder);
    }
 
    /**
     * 判断点位ID列表是否存在关联的巡游计划点位(内部接口)
     */
    @PostMapping("/logan/inner/cruise/existsCruisePlanPointByPointIds")
    public R<Boolean> existsCruisePlanPointByPointIds(@RequestBody List<Long> pointIds) {
        List<Long> distinctPointIds = pointIds == null
                ? java.util.Collections.emptyList()
                : pointIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
        if (distinctPointIds.isEmpty()) {
            return R.ok(Boolean.FALSE);
        }
        XpCruisePlanPoint exists = xpCruisePlanPointService.getOne(
                new LambdaQueryWrapper<XpCruisePlanPoint>()
                        .in(XpCruisePlanPoint::getPointId, distinctPointIds)
                        .last("limit 1")
        );
        return R.ok(exists != null);
    }
}