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