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
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.XpTestElectronicFence;
import com.xiaopeng.api.model.operation.XpTestElectronicFenceArea;
import com.xiaopeng.api.model.operation.XpTestElectronicFenceArea;
import com.xiaopeng.api.query.operation.PointListQuery;
import com.xiaopeng.api.query.operation.PointPageListListQuery;
import com.xiaopeng.api.vo.map.QueryTestPoint;
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.common.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
import com.xiaopeng.map.dto.XpPointSpecialDto;
import com.xiaopeng.map.service.*;
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;
import com.xiaopeng.common.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
 
@Slf4j
@RestController
@RequestMapping("")
@Api(tags = "测试demo-点位管理")
public class XpTestPointManagementController extends BaseController {
 
    @Resource
    private XpTestPointService xpTestPointService;
    @Resource
    private XpTestElectronicFenceAreaService xpElectronicFenceAreaService;
    @Resource
    private XpTestElectronicFenceService xpElectronicFenceService;
 
 
    @ApiOperation(value = "获取所有运营中的区域", response = XpTestElectronicFenceArea.class)
    @PostMapping("/api/v1/testPoint/listElectronicFenceArea")
    public R<List<XpTestElectronicFenceArea>> listElectronicFenceArea() {
        // 获取所有启用的电子围栏
        List<XpTestElectronicFence> electronicFences = xpElectronicFenceService.lambdaQuery().eq(XpTestElectronicFence::getStatus, 2).list();
        List<Long> electronicFenceIds = electronicFences.stream().map(XpTestElectronicFence::getId).collect(Collectors.toList());
        if (electronicFenceIds.isEmpty()) {
            return R.ok(new ArrayList<XpTestElectronicFenceArea>());
        }
        // 获取电子围栏下启用的运营区域
        List<XpTestElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery().in(XpTestElectronicFenceArea::getTestElectronicId, electronicFenceIds)
                .eq(XpTestElectronicFenceArea::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/addPoint")
    @ResponseBody
    @ApiOperation(value = "新增点位")
    @AdminOperationLog(
            businessType = AdminBusinessType.TEST_POINT_MANAGEMENT,
            operationType = AdminOperationType.ADD,
            content = "新增测试demo点位",
            appendRequestData = true
    )
    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 = "删除点位")
    @AdminOperationLog(
            businessType = AdminBusinessType.TEST_POINT_MANAGEMENT,
            operationType = AdminOperationType.DELETE,
            contentExpression = "'删除测试demo点位,ids=' + #p0",
            appendRequestData = false
    )
    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 = "编辑点位")
    @AdminOperationLog(
            businessType = AdminBusinessType.TEST_POINT_MANAGEMENT,
            operationType = AdminOperationType.EDIT,
            content = "编辑测试demo点位",
            appendRequestData = true
    )
    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 = "启用/禁用")
    @AdminOperationLog(
            businessType = AdminBusinessType.TEST_POINT_MANAGEMENT,
            operationType = AdminOperationType.SWITCH_STATUS,
            content = "启用/禁用测试demo点位",
            appendRequestData = true
    )
    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 = "后台管理-特殊点位")
    @AdminOperationLog(
            businessType = AdminBusinessType.TEST_SPECIAL_POINT_MANAGEMENT,
            operationType = AdminOperationType.EDIT,
            content = "设置测试demo特殊点位",
            appendRequestData = true
    )
    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("/logan/inner/v1/testPoint/nowInTimePoint")
    public R<Boolean> nowInTimePoint(@RequestParam Long pointId){
        return R.ok(xpTestPointService.nowInTimePoint(pointId));
    }
 
 
 
    /**
     * 点位详情
     */
    @PostMapping("/api/v1/testPoint/queryPointByIds")
    public R<List<XpTestPoint>> queryPointByIds(@RequestBody QueryTestPoint query){
        List<XpTestPoint> xpTestPoints = xpTestPointService.listByIds(query.getIds());
        return R.ok(xpTestPoints);
    }
 
 
    /**
     * 编辑点位
     * @param xpPoint
     * @return
     */
    @PostMapping("/logan/inner/v1/testPoint/editTestPoint")
    public R<?> editXpPoint(@RequestBody XpTestPoint xpPoint){
        xpTestPointService.updateById(xpPoint);
        return R.ok();
    }
}