liujie
2026-02-27 22b93ccfeec3dfb036d7dbd9f3ba2662d964b091
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
package com.xiaopeng.operation.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaopeng.api.dto.operation.CruisePointDto;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
import com.xiaopeng.api.model.operation.XpCruisePlan;
import com.xiaopeng.api.model.operation.XpCruisePlanPoint;
import com.xiaopeng.api.model.operation.XpCruisePlanVehicle;
import com.xiaopeng.api.model.operation.XpPoint;
import com.xiaopeng.api.model.order.XpCruiseOrder;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.operation.dto.XpCruisePlanAddDTO;
import com.xiaopeng.operation.dto.XpCruisePlanEditDTO;
import com.xiaopeng.operation.query.CruisePlanQuery;
import com.xiaopeng.operation.service.IXpCruisePlanPointService;
import com.xiaopeng.operation.service.IXpCruisePlanService;
import com.xiaopeng.operation.service.IXpCruisePlanVehicleService;
import com.xiaopeng.operation.service.XpPointService;
import com.xiaopeng.operation.vo.XpCruisePlanDetailVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
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.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;
 
/**
 * <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;
 
    @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"})
    public R<?> add(@Valid @RequestBody XpCruisePlanAddDTO dto) {
        xpCruisePlanService.add(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "编辑巡游计划", tags = {"管理后台-巡游计划"})
    @PostMapping(value = {"/api/v1/xp-cruise-plan/edit"})
    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}"})
    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("/inner/cruise/getCruisePoint")
    public R<XpCruiseOrder> getCruisePoint(@RequestBody CruisePointDto dto) {
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, dto.getVehicleId()));
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>().eq(XpCruisePlanPoint::getCruisePlanId, plan.getCruisePlanId()).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;
            }
        }
        XpCruisePlanPoint xpCruisePlanPoint = null;
        //   判断是否是最后一个 是则往前一个  否找下一个
        if (index == planPointList.size() - 1) {
            // 最后一个 找上一个
            xpCruisePlanPoint = planPointList.get(index - 1);
        } else if (index == 0) {
            // 第一个 找下一个
            xpCruisePlanPoint = planPointList.get(index + 1);
        } else {
            // 中间点位
            if (dto.getOrderReverse() == 1) {
                // 正向 找下一个
                xpCruisePlanPoint = planPointList.get(index + 1);
            } else {
                // 反向找上一个
                xpCruisePlanPoint = planPointList.get(index - 1);
            }
        }
        Long pointId = xpCruisePlanPoint.getPointId();
        XpPoint point = pointService.getById(pointId);
        XpCruiseOrder newXpCruiseOrder = dto.getNewXpCruiseOrder();
        newXpCruiseOrder.setEndPointId(pointId);
        newXpCruiseOrder.setEndPointName(point.getPointName());
        newXpCruiseOrder.setEndLon(point.getPointLon());
        newXpCruiseOrder.setEndLat(point.getPointLat());
        newXpCruiseOrder.setMissionId(xpCruisePlanPoint.getCruisePlanId());
 
 
        return R.ok(newXpCruiseOrder);
    }
 
 
    @PostMapping("/inner/cruise/getNewCruiseOrder")
    public R<XpCruiseOrder> getNewCruiseOrder(@RequestParam Long vehicleId) {
 
        // 获取车辆的车队id
 
        // 先找计划
        XpCruisePlanVehicle plan = xpCruisePlanVehicleService.getOne(new LambdaQueryWrapper<XpCruisePlanVehicle>().eq(XpCruisePlanVehicle::getVehicleId, vehicleId));
        // 找对应的多个点位
        List<XpCruisePlanPoint> planPointList = xpCruisePlanPointService.list(new LambdaQueryWrapper<XpCruisePlanPoint>().eq(XpCruisePlanPoint::getCruisePlanId, plan.getCruisePlanId()).orderByAsc(XpCruisePlanPoint::getSortOrder));
 
        XpCruisePlanPoint xpCruisePlanPoint = planPointList.get(0);
        Long pointId = xpCruisePlanPoint.getPointId();
        XpPoint point = pointService.getById(pointId);
        XpCruiseOrder newXpCruiseOrder = new XpCruiseOrder();
        newXpCruiseOrder.setStartLon(point.getPointLon());
        newXpCruiseOrder.setStartLat(point.getPointLat());
        newXpCruiseOrder.setStartPointId(pointId);
        newXpCruiseOrder.setStartPointName(point.getPointName());
 
        newXpCruiseOrder.setMissionId(xpCruisePlanPoint.getCruisePlanId());
        return null;
    }
}