From 9da37c2c81926ac5c05e9aaf28036df1e858feee Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期六, 14 三月 2026 17:38:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpPointManagementController.java |  300 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 221 insertions(+), 79 deletions(-)

diff --git a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpPointManagementController.java b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpPointManagementController.java
index e0dfb4e..864b337 100644
--- a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpPointManagementController.java
+++ b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpPointManagementController.java
@@ -1,29 +1,37 @@
 package com.xiaopeng.map.controller;
 
 
-import cn.afterturn.easypoi.excel.ExcelExportUtil;
-import cn.afterturn.easypoi.excel.entity.ExportParams;
 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.feignClient.operation.XpPointClient;
+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.feignClient.operation.XpCruisePlanClient;
 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.common.security.service.TokenService;
-import com.xiaopeng.map.exportExcel.XpPointExportExcel;
 import com.xiaopeng.api.dto.map.XpPointExportExcelQuery;
-import io.seata.spring.annotation.GlobalTransactional;
+import com.xiaopeng.map.exportExcel.XpPointExportExcel;
+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 io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.springframework.util.StringUtils;
+import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.springframework.beans.BeanUtils;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -32,11 +40,18 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
+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.function.Function;
 import java.util.stream.Collectors;
+
 
 @Slf4j
 @RestController
@@ -44,90 +59,112 @@
 @Api(tags = "点位管理")
 public class XpPointManagementController extends BaseController {
 
-    @Resource
-    private XpPointClient xpPointClient;
+    private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
     @Resource
-    private TokenService tokenService;
+    private XpPointService xpPointService;
+    @Resource
+    private XpElectronicFenceAreaService xpElectronicFenceAreaService;
+    @Resource
+    private XpElectronicFenceService xpElectronicFenceService;
+    @Resource
+    private XpGeoFencingPolygonService xpGeoFencingPolygonService;
+    @Resource
+    private XpCruisePlanClient xpCruisePlanClient;
 
 
     @ApiOperation(value = "获取所有运营中的区域", response = XpElectronicFenceArea.class)
     @PostMapping("/listElectronicFenceArea")
     public R<List<XpElectronicFenceArea>> listElectronicFenceArea() {
-
-        return xpPointClient.listElectronicFenceArea();
-    }
-    @ApiOperation(value = "点位管理分页列表", response = XpPoint.class)
-    @PostMapping("/pageList")
-    public R<PageInfo<XpPoint>> pageList(@RequestBody PointPageListListQuery query) {
-        return xpPointClient.pageList(query);
-    }
-    @ApiOperation(value = "点位导出")
-    @PostMapping(value = "/exportExcel")
-    public void exportExcel(@RequestBody XpPointExportExcelQuery query) {
-        List<XpPoint> exportList = xpPointClient.getByIds(query).getData();
-        List<XpPointExportExcel> xpPointExportExcels = new ArrayList<>();
-        for (XpPoint xpPoint : exportList) {
-            XpPointExportExcel xpPointExportExcel = new XpPointExportExcel();
-            xpPointExportExcel.setPointNumber(xpPoint.getPointNumber());
-            xpPointExportExcel.setPointName(xpPoint.getPointName());
-            xpPointExportExcel.setStatus(xpPoint.getOperationStatus());
-            xpPointExportExcel.setParkingTimeLimit(xpPoint.getParkingTimeLimit()+"分钟");
-            xpPointExportExcel.setPointLon(xpPoint.getPointLon());
-            xpPointExportExcel.setPointLat(xpPoint.getPointLat());
-            xpPointExportExcel.setCreateBy(xpPoint.getCreateBy());
-            xpPointExportExcel.setCreateTime(xpPoint.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
-            xpPointExportExcels.add(xpPointExportExcel);
+        // 获取所有启用的电子围栏
+        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>());
         }
-        //1.获取excel模板
-        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpPointExportExcel.class, xpPointExportExcels);
-        HttpServletResponse response = WebUtils.response();
-        response.setContentType("application/vnd.ms-excel");
-        response.setCharacterEncoding("utf-8");
-        ServletOutputStream outputStream = null;
-        try {
-            String fileName = URLEncoder.encode("点位列表.csv", "utf-8");
-            response.setHeader("Content-dispodition", "attachment;filename=" + fileName);
-            outputStream = response.getOutputStream();
-            workbook.write(outputStream);
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                outputStream.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-
+        // 获取电子围栏下启用的运营区域
+        List<XpElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery().in(XpElectronicFenceArea::getElectronicId, electronicFenceIds)
+                .eq(XpElectronicFenceArea::getAreaStatus, 1).list();
+        return R.ok(electronicFenceAreaList);
     }
+
     @ApiOperation(value = "点位管理列表", response = XpPoint.class)
     @PostMapping("/list")
     public R<List<XpPoint>> list(@RequestBody PointListQuery query) {
-        if (StringUtils.hasLength(query.getOperationStatus())){
-            List<Integer> operationStatusIds = Arrays.stream(query.getOperationStatus().split(",")).map(Integer::parseInt).collect(Collectors.toList());
-            query.setOperationStatusIds(operationStatusIds);
-        }
-        return xpPointClient.list( query);
+        List<XpPoint> pageList = xpPointService.listAll(query);
+        return R.ok(pageList);
     }
+
+    @ApiOperation(value = "点位管理分页列表", response = XpPoint.class)
+    @PostMapping("/pageList")
+    public R<PageInfo<XpPoint>> pageList(@RequestBody PointPageListListQuery query) {
+        PageInfo<XpPoint> pageList = xpPointService.pageList(query);
+        return R.ok(pageList);
+    }
+
+    @PostMapping("/getByIds")
+    public R<List<XpPoint>> getByIds(@RequestBody XpPointExportExcelQuery query) {
+        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) {
+        List<Long> pointIds = query == null ? Collections.emptyList() : query.getPointIds();
+        List<Long> distinctIds = pointIds == null
+                ? Collections.emptyList()
+                : pointIds.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
+
+        List<XpPoint> points = distinctIds.isEmpty()
+                ? Collections.emptyList()
+                : xpPointService.lambdaQuery().in(XpPoint::getId, distinctIds).list();
+        Map<Long, XpPoint> pointById = points.stream()
+                .filter(p -> p.getId() != null)
+                .collect(Collectors.toMap(XpPoint::getId, Function.identity(), (a, b) -> a));
+
+        List<XpPointExportExcel> exportList = new ArrayList<>(points.size());
+        for (Long id : distinctIds) {
+            XpPoint xpPoint = pointById.get(id);
+            if (xpPoint == null) {
+                continue;
+            }
+            exportList.add(toExportRow(xpPoint));
+        }
+
+        HttpServletResponse response = WebUtils.response();
+        if (response == null) {
+            throw new ServiceException("导出失败:未获取到响应对象");
+        }
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
+        try {
+            String fileName = URLEncoder.encode("点位列表.xls", StandardCharsets.UTF_8.name());
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
+            try (Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpPointExportExcel.class, exportList);
+                 ServletOutputStream outputStream = response.getOutputStream()) {
+                workbook.write(outputStream);
+            }
+        } catch (IOException e) {
+            log.error("点位导出失败 pointIds={}", distinctIds, e);
+            throw new ServiceException("点位导出失败");
+        }
+    }
+
     /**
      * 新增点位
      */
-    @GlobalTransactional(name = "add-point", rollbackFor = Exception.class)
     @PostMapping("/add")
+    @ResponseBody
     @ApiOperation(value = "新增点位")
-    public R add(@Validated  @RequestBody PointAddDto pointAddDto) {
-        return xpPointClient.add(pointAddDto);
+    public R<?> add(@Validated @RequestBody PointAddDto pointAddDto) {
+        if (xpGeoFencingPolygonService.isInFence(pointAddDto.getPointLon(), pointAddDto.getPointLat(), pointAddDto.getFenceId(), "prohibited_area")) {
+            return R.ok("in_prohibited_area");
+        }
+        return R.ok(xpPointService.addPointWithGeneratedNumber(pointAddDto));
     }
-    /**
-     * 编辑点位
-     */
-    @PostMapping("/edit")
-    @ApiOperation(value = "编辑点位")
-    public R edit(@Validated@RequestBody PointUpdateDto pointAddDto) {
 
-        return xpPointClient.edit(pointAddDto);
-    }
     /**
      * 批量删除点位
      */
@@ -135,25 +172,130 @@
     @ResponseBody
     @ApiOperation(value = "删除点位")
     public R deletePoint(@RequestParam("ids") String ids) {
-        xpPointClient.deletePoint(ids);
+        List<Long> pointIds = Arrays.stream(ids.split(","))
+                .map(String::trim)
+                .filter(s -> !s.isEmpty())
+                .map(Long::parseLong)
+                .distinct()
+                .collect(Collectors.toList());
+        if (pointIds.isEmpty()) {
+            return R.ok();
+        }
+        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();
     }
+
     /**
      * 编辑点位
      */
-    @GetMapping("/queryById")
-    @ResponseBody
-    @ApiOperation(value = "点位详情")
-    public R queryById(@RequestParam Long id) {
-        return xpPointClient.queryById( id);
+    @PostMapping("/edit")
+    @ApiOperation(value = "编辑点位")
+    @Transactional
+    @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);
+        }
+        return R.ok();
     }
+
+    /**
+     * 点位详情
+     */
+    @GetMapping("/api/v1/point/queryById")
+    @ApiOperation(value = "点位详情")
+    public R<XpPoint> queryById(@RequestParam Long id) {
+        return R.ok(xpPointService.getById(id));
+    }
+
     /**
      * 启用/禁用
      */
     @PostMapping("/enableDisable")
-    @ResponseBody
     @ApiOperation(value = "启用/禁用")
     public R enableDisable(@RequestBody XpPointEnableDisableDto dto) {
-        return xpPointClient.enableDisable(dto);
+        XpPoint xpPoint = xpPointService.getById(dto.getId());
+        xpPoint.setOperationStatus(dto.getOperationStatus());
+        xpPoint.setVerificationStatus(dto.getVerificationStatus());
+        xpPoint.setFpElectronicAreaId(null);
+        xpPointService.updateById(xpPoint);
+        return R.ok();
     }
+
+    private static XpPointExportExcel toExportRow(XpPoint xpPoint) {
+        XpPointExportExcel exportExcel = new XpPointExportExcel();
+        exportExcel.setPointNumber(xpPoint.getPointNumber());
+        exportExcel.setPointName(xpPoint.getPointName());
+        exportExcel.setStatus(calcExportStatus(xpPoint.getOperationStatus(), xpPoint.getVerificationStatus()));
+        exportExcel.setParkingTimeLimit(xpPoint.getParkingTimeLimit() == null ? null : String.valueOf(xpPoint.getParkingTimeLimit()));
+        exportExcel.setPointLon(xpPoint.getPointLon());
+        exportExcel.setPointLat(xpPoint.getPointLat());
+        exportExcel.setCreateBy(xpPoint.getCreateBy());
+        exportExcel.setCreateTime(formatExportTime(xpPoint.getCreateTime()));
+        return exportExcel;
+    }
+
+    private static String formatExportTime(LocalDateTime time) {
+        return time == null ? null : EXPORT_TIME_FORMATTER.format(time);
+    }
+
+    private static Integer calcExportStatus(Integer operationStatus, Integer verificationStatus) {
+        if (operationStatus == null) {
+            return null;
+        }
+        if (verificationStatus == 1) {
+            return 1;
+        }
+        if (verificationStatus == 2) {
+            return 2;
+        }
+        if (verificationStatus == 4) {
+            return 3;
+        }
+        if (verificationStatus == 3 && operationStatus == 1) {
+            return 4;
+        }
+        if (verificationStatus == 5 && operationStatus == 1) {
+            return 5;
+        }
+        if (operationStatus == 2) {
+            return 6;
+        }
+        if (operationStatus == 3) {
+            return 7;
+        }
+        if (operationStatus == 4) {
+            return 8;
+        }
+        if (operationStatus != 1 || verificationStatus == null) {
+            return null;
+        }
+
+        return null;
+    }
+
 }

--
Gitblit v1.7.1