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;
|
|
@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_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);
|
}
|
}
|