liujie
2026-03-27 54760fb417be457f532596b8d3b3ceed87414418
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
package com.xiaopeng.map.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xiaopeng.api.dto.map.XpPointExportExcelQuery;
import com.xiaopeng.api.dto.operation.PointAddDto;
import com.xiaopeng.api.dto.operation.PointUpdateDto;
import com.xiaopeng.api.dto.operation.XpPointEnableDisableDto;
import com.xiaopeng.api.model.map.XpTestPoint;
import com.xiaopeng.api.model.operation.XpElectronicFence;
import com.xiaopeng.api.model.operation.XpElectronicFenceArea;
import com.xiaopeng.api.query.operation.PointListQuery;
import com.xiaopeng.api.query.operation.PointPageListListQuery;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.controller.BaseController;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.map.dto.XpPointSpecialDto;
import com.xiaopeng.map.service.XpElectronicFenceAreaService;
import com.xiaopeng.map.service.XpElectronicFenceService;
import com.xiaopeng.map.service.XpTestPointService;
import com.xiaopeng.map.vo.SpecialPointListVo;
import com.xiaopeng.map.vo.SpecialPointVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
@Slf4j
@RestController
@RequestMapping("")
@Api(tags = "测试demo-点位管理")
public class XpTestPointManagementController extends BaseController {
 
    @Resource
    private XpTestPointService xpTestPointService;
    @Resource
    private XpElectronicFenceAreaService xpElectronicFenceAreaService;
    @Resource
    private XpElectronicFenceService xpElectronicFenceService;
 
 
    @ApiOperation(value = "获取所有运营中的区域", response = XpElectronicFenceArea.class)
    @PostMapping("/api/v1/testPoint/listElectronicFenceArea")
    public R<List<XpElectronicFenceArea>> listElectronicFenceArea() {
        // 获取所有启用的电子围栏
        List<XpElectronicFence> electronicFences = xpElectronicFenceService.lambdaQuery().eq(XpElectronicFence::getStatus, 2).list();
        List<Long> electronicFenceIds = electronicFences.stream().map(XpElectronicFence::getId).collect(Collectors.toList());
        if (electronicFenceIds.isEmpty()) {
            return R.ok(new ArrayList<XpElectronicFenceArea>());
        }
        // 获取电子围栏下启用的运营区域
        List<XpElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery().in(XpElectronicFenceArea::getElectronicId, electronicFenceIds)
                .eq(XpElectronicFenceArea::getAreaStatus, 1).list();
        return R.ok(electronicFenceAreaList);
    }
 
    @ApiOperation(value = "点位管理列表", response = XpTestPoint.class)
    @PostMapping("/api/v1/testPoint/listPoint")
    public R<List<XpTestPoint>> list(@RequestBody PointListQuery query) {
        List<XpTestPoint> pageList = xpTestPointService.listAll(query);
        return R.ok(pageList);
    }
 
    @ApiOperation(value = "点位管理分页列表", response = XpTestPoint.class)
    @PostMapping("/api/v1/testPoint/pageList")
    public R<PageInfo<XpTestPoint>> pageList(@RequestBody PointPageListListQuery query) {
        PageInfo<XpTestPoint> pageList = xpTestPointService.pageList(query);
        return R.ok(pageList);
    }
 
    @PostMapping("/api/v1/testPoint/getByIds")
    public R<List<XpTestPoint>> getByIds(@RequestBody XpPointExportExcelQuery query) {
        List<XpTestPoint> list = xpTestPointService.lambdaQuery().in(XpTestPoint::getId, query.getPointIds()).list();
        return R.ok(list);
    }
 
    /**
     * 新增点位
     */
    @PostMapping("/api/v1/testPoint/addPoint")
    @ResponseBody
    @ApiOperation(value = "新增点位")
    public R add(@Validated @RequestBody PointAddDto pointAddDto) {
        XpTestPoint xpPoint = new XpTestPoint();
        BeanUtils.copyProperties(pointAddDto, xpPoint);
        xpPoint.setFpElectronicAreaId(xpPoint.getElectronicAreaId());
        xpTestPointService.save(xpPoint);
        return R.ok();
    }
 
    /**
     * 批量删除点位
     */
    @GetMapping("/api/v1/testPoint/deletePoint")
    @ResponseBody
    @ApiOperation(value = "删除点位")
    public R deletePoint(@RequestParam("ids") String ids) {
        xpTestPointService.removeBatchByIds(Arrays.stream(ids.split(","))
                .map(Long::parseLong).collect(Collectors.toList()));
        return R.ok();
    }
 
    /**
     * 编辑点位
     */
    @PostMapping("/api/v1/testPoint/editPoint")
    @ApiOperation(value = "编辑点位")
    public R edit(@Validated @RequestBody PointUpdateDto pointAddDto) {
        XpTestPoint xpPoint = new XpTestPoint();
        BeanUtils.copyProperties(pointAddDto, xpPoint);
        xpPoint.setFpElectronicAreaId(null);
        xpTestPointService.updateById(xpPoint);
        return R.ok();
    }
 
    /**
     * 点位详情
     */
    @GetMapping("/api/v1/testPoint/queryPointById")
    @ApiOperation(value = "点位详情")
    public R<XpTestPoint> queryById(@RequestParam Long id) {
        return R.ok(xpTestPointService.getById(id));
    }
 
    /**
     * 启用/禁用
     */
    @PostMapping("/api/v1/testPoint/enableDisablePoint")
    @ApiOperation(value = "启用/禁用")
    public R enableDisable(@RequestBody XpPointEnableDisableDto dto) {
        XpTestPoint xpPoint = xpTestPointService.getById(dto.getId());
        xpPoint.setOperationStatus(dto.getOperationStatus());
        xpPoint.setFpElectronicAreaId(null);
        xpTestPointService.updateById(xpPoint);
        return R.ok();
    }
 
 
    /**
     * 设置特殊点位
     */
    @PostMapping("/api/v1/testPoint/setSpecialPoint")
    @ApiOperation(value = "设置特殊点位", tags = "后台管理-特殊点位")
    public R setSpecialPoint(@RequestBody XpPointSpecialDto dto) {
        xpTestPointService.update(new LambdaUpdateWrapper<XpTestPoint>().set(XpTestPoint::getChargePoint, 0)
                .set(XpTestPoint::getParkingPoint, 0));
        List<XpTestPoint> list = xpTestPointService.list(new LambdaQueryWrapper<XpTestPoint>()
                .in(XpTestPoint::getId, dto.getChargePoints()));
        list.forEach(e -> {
            e.setChargePoint(1);
            e.setFpElectronicAreaId(null);
        });
        xpTestPointService.updateBatchById(list);
        List<XpTestPoint> list1 = xpTestPointService.list(new LambdaQueryWrapper<XpTestPoint>()
                .in(XpTestPoint::getId, dto.getParkingPoints()));
        list1.forEach(e -> {
            e.setParkingPoint(1);
            e.setFpElectronicAreaId(null);
        });
        xpTestPointService.updateBatchById(list1);
        return R.ok();
    }
 
 
    @GetMapping("/api/v1/testPoint/listSpecialPoint")
    @ApiOperation(value = "获取特殊点位", tags = "后台管理-特殊点位")
    public R<SpecialPointVo> getSpecialPoint() {
        List<XpTestPoint> chargePoints = xpTestPointService.list(new LambdaQueryWrapper<XpTestPoint>().eq(XpTestPoint::getChargePoint, 1));
        List<XpTestPoint> parkingPoints = xpTestPointService.list(new LambdaQueryWrapper<XpTestPoint>().eq(XpTestPoint::getParkingPoint, 1));
 
        SpecialPointVo specialPointVo = new SpecialPointVo();
        ArrayList<SpecialPointListVo> chargePointsList = new ArrayList<>();
        for (XpTestPoint chargePoint : chargePoints) {
            SpecialPointListVo specialPointListVo = new SpecialPointListVo();
            specialPointListVo.setPointName(chargePoint.getPointName());
            specialPointListVo.setPointAddress(chargePoint.getPointAddress());
            specialPointListVo.setPointId(chargePoint.getId());
            chargePointsList.add(specialPointListVo);
        }
        specialPointVo.setChargePoints(chargePointsList);
 
 
        ArrayList<SpecialPointListVo> parkingPointsList = new ArrayList<>();
        for (XpTestPoint parkingPoint : parkingPoints) {
            SpecialPointListVo specialPointListVo = new SpecialPointListVo();
            specialPointListVo.setPointName(parkingPoint.getPointName());
            specialPointListVo.setPointAddress(parkingPoint.getPointAddress());
            specialPointListVo.setPointId(parkingPoint.getId());
            parkingPointsList.add(specialPointListVo);
        }
        specialPointVo.setParkingPoints(parkingPointsList);
 
        return R.ok(specialPointVo);
    }
 
 
    /**
     * 判断点位是在有效期内
     * @param pointId
     * @return
     */
    @GetMapping("/inner/v1/testPoint/nowInTimePoint")
    public R<Boolean> nowInTimePoint(@RequestParam Long pointId){
        return R.ok(xpTestPointService.nowInTimePoint(pointId));
    }
 
 
 
    /**
     * 点位详情
     */
    @GetMapping("/api/v1/testPoint/queryPointById1")
    public R<List<XpTestPoint>> queryByIds(@RequestParam List<Long> ids){
        List<XpTestPoint> xpTestPoints = xpTestPointService.listByIds(ids);
        return R.ok(xpTestPoints);
    }
}