| | |
| | | package com.xiaopeng.map.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | 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.operation.XpCruisePlanPoint; |
| | | import com.xiaopeng.api.feignClient.operation.XpCruisePlanClient; |
| | | import com.xiaopeng.api.model.operation.XpElectronicFence; |
| | | import com.xiaopeng.api.model.operation.XpElectronicFenceArea; |
| | | import com.xiaopeng.api.model.operation.XpPoint; |
| | | import com.xiaopeng.api.query.operation.PointListQuery; |
| | | import com.xiaopeng.api.query.operation.PointPageListListQuery; |
| | | import com.xiaopeng.map.constant.I18nKeyConstant; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.web.controller.BaseController; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.api.dto.map.XpPointExportExcelQuery; |
| | | import com.xiaopeng.map.constant.I18nKeyConstant; |
| | | import com.xiaopeng.map.exportExcel.XpPointExportExcel; |
| | | import com.xiaopeng.map.mapper.XpCruisePlanPointMapper; |
| | | import com.xiaopeng.map.mangodb.service.XpGeoFencingPolygonService; |
| | | import com.xiaopeng.map.service.XpElectronicFenceAreaService; |
| | | import com.xiaopeng.map.service.XpElectronicFenceService; |
| | | import com.xiaopeng.map.service.XpPointService; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Resource |
| | | private XpGeoFencingPolygonService xpGeoFencingPolygonService; |
| | | @Resource |
| | | private XpCruisePlanPointMapper xpCruisePlanPointMapper; |
| | | private XpCruisePlanClient xpCruisePlanClient; |
| | | |
| | | |
| | | @ApiOperation(value = "获取所有运营中的区域", response = XpElectronicFenceArea.class) |
| | | @PostMapping("/listElectronicFenceArea") |
| | | public R<List<XpElectronicFenceArea>> listElectronicFenceArea() { |
| | | public R<List<XpElectronicFenceArea>> listElectronicFenceArea(@RequestParam(required = false) String cityCode) { |
| | | // 获取所有启用的电子围栏 |
| | | List<XpElectronicFence> electronicFences = xpElectronicFenceService.lambdaQuery() |
| | | .eq(XpElectronicFence::getStatus, 2).list(); |
| | | |
| | | LambdaQueryWrapper<XpElectronicFence> queryWrapper= new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(XpElectronicFence::getStatus, 2); |
| | | if(StrUtil.isNotBlank(cityCode)){ |
| | | queryWrapper.eq(XpElectronicFence::getCityCode, cityCode); |
| | | } |
| | | |
| | | List<XpElectronicFence> electronicFences = xpElectronicFenceService.list(queryWrapper); |
| | | List<Long> electronicFenceIds = electronicFences.stream().map(XpElectronicFence::getId).collect(Collectors.toList()); |
| | | if (electronicFenceIds.isEmpty()) { |
| | | return R.ok(new ArrayList<XpElectronicFenceArea>()); |
| | |
| | | List<XpPoint> list = xpPointService.lambdaQuery().in(XpPoint::getId, query.getPointIds()).list(); |
| | | return R.ok(list); |
| | | } |
| | | // "2029885249115987970" "2029883649798512642" |
| | | |
| | | @ApiOperation(value = "点位导出") |
| | | @PostMapping("/exportExcel") |
| | | public void exportExcel(@RequestBody XpPointExportExcelQuery query) { |
| | |
| | | if (pointIds.isEmpty()) { |
| | | return R.ok(); |
| | | } |
| | | Long relatedCount = xpCruisePlanPointMapper.selectCount( |
| | | new LambdaQueryWrapper<XpCruisePlanPoint>().in(XpCruisePlanPoint::getPointId, pointIds) |
| | | ); |
| | | if (relatedCount != null && relatedCount > 0) { |
| | | throw new ServiceException("操作失败,该点位有关联的巡游点位", I18nKeyConstant.POINT_DELETE_HAS_CRUISE_PLAN_POINT); |
| | | R<Boolean> existsResult = xpCruisePlanClient.existsCruisePlanPointByPointIds(pointIds); |
| | | if (existsResult == null || existsResult.getData() == null) { |
| | | throw new ServiceException("系统异常", I18nKeyConstant.SYSTEM_EXCEPTION); |
| | | } |
| | | if (Boolean.TRUE.equals(existsResult.getData())) { |
| | | throw new ServiceException("操作失败,该点位有关联的巡游计划点位", I18nKeyConstant.POINT_DELETE_HAS_CRUISE_PLAN_POINT); |
| | | } |
| | | xpPointService.removeBatchByIds(pointIds); |
| | | return R.ok(); |
| | |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R edit(@Validated @RequestBody PointUpdateDto pointAddDto) { |
| | | XpPoint xpPoint = xpPointService.getById(pointAddDto.getId()); |
| | | if (!xpPoint.getElectronicAreaId().equals(pointAddDto.getElectronicAreaId())) { |
| | | BeanUtils.copyProperties(pointAddDto, xpPoint); |
| | | |
| | | if (xpGeoFencingPolygonService.isInFence(pointAddDto.getPointLon(), pointAddDto.getPointLat(), pointAddDto.getFenceId(), "prohibited_area")) { |
| | | return R.ok("in_prohibited_area"); |
| | | } |
| | | |
| | | xpPointService.updateById(xpPoint); |
| | | } else { |
| | | if (xpGeoFencingPolygonService.isInFence(pointAddDto.getPointLon(), pointAddDto.getPointLat(), pointAddDto.getFenceId(), "prohibited_area")) { |
| | | return R.ok("in_prohibited_area"); |
| | | } |
| | | |
| | | //先删除原有的数据,因为会存在点位的从属区域变化的情况,所以先删除原有的数据后添加新的数据重新分片到新的库中 |
| | | BeanUtils.copyProperties(pointAddDto, xpPoint); |
| | | xpPointService.removeById(pointAddDto.getId()); |
| | | xpPoint.setId(null); |
| | | xpPointService.save(xpPoint); |
| | | if (xpPoint == null) { |
| | | throw new ServiceException("系统异常", I18nKeyConstant.SYSTEM_EXCEPTION); |
| | | } |
| | | xpPointService.validatePointNameUnique(pointAddDto.getPointName(), pointAddDto.getId()); |
| | | BeanUtils.copyProperties(pointAddDto, xpPoint); |
| | | if (Integer.valueOf(2).equals(pointAddDto.getOperationStatus()) && Integer.valueOf(5).equals(pointAddDto.getVerificationStatus())) { |
| | | Long electronicAreaId = xpPoint.getElectronicAreaId(); |
| | | if (electronicAreaId == null) { |
| | | throw new ServiceException("当前点位不在围栏运营区域内,不能启用。", I18nKeyConstant.POINT_ENABLE_NOT_IN_OPERATING_AREA); |
| | | } |
| | | XpElectronicFenceArea electronicFenceArea = xpElectronicFenceAreaService.getById(electronicAreaId); |
| | | if (electronicFenceArea == null || electronicFenceArea.getElectronicId() == null) { |
| | | throw new ServiceException("运营区域不存在", I18nKeyConstant.POINT_ELECTRONIC_AREA_NOT_EXIST); |
| | | } |
| | | if (xpPoint.getPointLon() == null || xpPoint.getPointLat() == null) { |
| | | throw new ServiceException("系统异常", I18nKeyConstant.SYSTEM_EXCEPTION); |
| | | } |
| | | String fenceId = String.valueOf(electronicFenceArea.getElectronicId()); |
| | | boolean inOperatingArea = xpGeoFencingPolygonService.isInFence(xpPoint.getPointLon(), xpPoint.getPointLat(), fenceId, "operating_area"); |
| | | if (!inOperatingArea) { |
| | | throw new ServiceException("当前点位不在围栏运营区域内,不能启用。", I18nKeyConstant.POINT_ENABLE_NOT_IN_OPERATING_AREA); |
| | | } |
| | | boolean inProhibitedArea = xpGeoFencingPolygonService.isInFence(xpPoint.getPointLon(), xpPoint.getPointLat(), fenceId, "prohibited_area"); |
| | | if (inProhibitedArea) { |
| | | throw new ServiceException("当前点位在禁行区内,不能启用。", I18nKeyConstant.POINT_ENABLE_IN_PROHIBITED_AREA); |
| | | } |
| | | } |
| | | xpPoint.setFpElectronicAreaId(null); |
| | | |
| | | Long stationId = pointAddDto.getStationId(); |
| | | Integer stationSortNo = pointAddDto.getStationSortNo(); //点位在场站内排序 |
| | | if(stationId != null && stationId > 0){ |
| | | if(stationSortNo == null){ |
| | | stationSortNo = 0; |
| | | } |
| | | } |
| | | |
| | | // 使用 lambdaUpdate 确保 pointPictures 为 null 时也能将数据库字段清空 |
| | | // (updateById 默认策略 NOT_NULL 会跳过 null 值,导致删除图片后数据库仍保留旧图片) |
| | | xpPointService.lambdaUpdate() |
| | | .eq(XpPoint::getId, xpPoint.getId()) |
| | | .set(XpPoint::getPointName, xpPoint.getPointName()) |
| | | .set(XpPoint::getPointPoi, xpPoint.getPointPoi()) |
| | | .set(XpPoint::getPointNumber, xpPoint.getPointNumber()) |
| | | .set(XpPoint::getOperationStatus, xpPoint.getOperationStatus()) |
| | | .set(XpPoint::getPointType, xpPoint.getPointType()) |
| | | .set(XpPoint::getVerificationStatus, xpPoint.getVerificationStatus()) |
| | | .set(XpPoint::getParkingTimeLimit, xpPoint.getParkingTimeLimit()) |
| | | .set(XpPoint::getOperationType, xpPoint.getOperationType()) |
| | | .set(XpPoint::getEffectivePeriod, xpPoint.getEffectivePeriod()) |
| | | .set(XpPoint::getEffectiveTimePeriod, xpPoint.getEffectiveTimePeriod()) |
| | | .set(XpPoint::getPointAddress, xpPoint.getPointAddress()) |
| | | .set(XpPoint::getRemarks, xpPoint.getRemarks()) |
| | | .set(XpPoint::getPointPictures, xpPoint.getPointPictures()) |
| | | .set(XpPoint::getPointLon, xpPoint.getPointLon()) |
| | | .set(XpPoint::getPointLat, xpPoint.getPointLat()) |
| | | .set(XpPoint::getElectronicAreaId, xpPoint.getElectronicAreaId()) |
| | | .set(XpPoint::getChargePoint, xpPoint.getChargePoint()) |
| | | .set(XpPoint::getParkingPoint, xpPoint.getParkingPoint()) |
| | | .set(XpPoint::getProvinceName, xpPoint.getProvinceName()) |
| | | .set(XpPoint::getProvinceCode, xpPoint.getProvinceCode()) |
| | | .set(XpPoint::getCityCode, xpPoint.getCityCode()) |
| | | .set(XpPoint::getCityName, xpPoint.getCityName()) |
| | | .set(XpPoint::getDistrictName, xpPoint.getDistrictName()) |
| | | .set(XpPoint::getDistrictCode, xpPoint.getDistrictCode()) |
| | | .set(XpPoint::getStationId, stationId) |
| | | .set(XpPoint::getStationSortNo, stationSortNo) |
| | | .update(); |
| | | |
| | | //场站点位排序 后添加的点位 排第一个。 |
| | | xpPointService.setStationSortNo(xpPoint.getStationId(),stationSortNo); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | XpPoint xpPoint = xpPointService.getById(dto.getId()); |
| | | xpPoint.setOperationStatus(dto.getOperationStatus()); |
| | | xpPoint.setVerificationStatus(dto.getVerificationStatus()); |
| | | xpPoint.setElectronicAreaId(null); |
| | | xpPoint.setFpElectronicAreaId(null); |
| | | xpPointService.updateById(xpPoint); |
| | | return R.ok(); |
| | | } |