From c6f298dc2f39673891eb90f219f610cdde20ef24 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期日, 15 三月 2026 20:32:38 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java |   72 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java
index effc1d7..6edb987 100644
--- a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java
+++ b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java
@@ -22,6 +22,7 @@
 import com.xiaopeng.map.job.base.QuartzManager;
 import com.xiaopeng.map.job.base.TimeJobType;
 import com.xiaopeng.map.job.jobs.ElectronicEffectJob;
+import com.xiaopeng.map.mangodb.service.XpGeoFencingPolygonService;
 import com.xiaopeng.map.mapper.XpElectronicFenceAreaMapper;
 import com.xiaopeng.map.mapper.XpElectronicFenceMapper;
 import com.xiaopeng.map.mapper.XpPointMapper;
@@ -78,6 +79,9 @@
 
     @Autowired
     private XpPointService xpPointService;
+
+    @Resource
+    private XpGeoFencingPolygonService xpGeoFencingPolygonService;
 
     @Autowired
     private XpRegionMapper xpRegionMapper;
@@ -667,17 +671,71 @@
                 }
             }
         }
-        //如果区域状态从停用改为启用,需将区域内的点位全部启用
-        if (status ==3 && dto.getStatus() == 2 && !xpPoints.isEmpty()){
-            for (XpPoint xpPoint : xpPoints) {
-                xpPoint.setOperationStatus(2);
-                xpPointMapper.updateById(xpPoint);
+        // 围栏从已停用(3)改为启用中(2)时:同步启用点位需校验点位在运营区内且不在禁行区内
+        Integer newFenceStatus = xpElectronicFence.getStatus();
+        if (status != null && status == 3 && newFenceStatus != null && newFenceStatus == 2) {
+            XpElectronicFenceArea operationAreaToEnable = xpElectronicFenceAreaService.lambdaQuery()
+                    .eq(XpElectronicFenceArea::getElectronicId, dto.getId())
+                    .eq(XpElectronicFenceArea::getAreaType, 1)
+                    .orderByDesc(XpElectronicFenceArea::getId)
+                    .last("limit 1")
+                    .one();
+            if (operationAreaToEnable == null || operationAreaToEnable.getId() == null) {
+                log.warn("围栏启用同步启用点位跳过:未查询到运营区 fenceId={}", dto.getId());
+            } else {
+                Long operationAreaIdToEnable = operationAreaToEnable.getId();
+                LambdaQueryWrapper<XpPoint> pendingEnableQuery = new LambdaQueryWrapper<>();
+                pendingEnableQuery.eq(XpPoint::getElectronicAreaId, operationAreaIdToEnable)
+                        .eq(XpPoint::getPointType, 1)
+                        .eq(XpPoint::getOperationStatus, 3);
+                List<XpPoint> pendingEnablePoints = xpPointMapper.selectList(pendingEnableQuery);
+                int pendingCount = pendingEnablePoints == null ? 0 : pendingEnablePoints.size();
+                if (pendingCount == 0) {
+                    log.info("围栏启用同步启用点位:无待启用点位 fenceId={}, operationAreaId={}", dto.getId(), operationAreaIdToEnable);
+                } else {
+                    String fenceId = String.valueOf(dto.getId());
+                    List<Long> enableIds = new ArrayList<>();
+                    for (XpPoint pointItem : pendingEnablePoints) {
+                        if (pointItem == null || pointItem.getId() == null) {
+                            continue;
+                        }
+                        Double lon = pointItem.getPointLon();
+                        Double lat = pointItem.getPointLat();
+                        if (lon == null || lat == null) {
+                            continue;
+                        }
+                        try {
+                            boolean inOperatingArea = xpGeoFencingPolygonService.isInFence(lon, lat, fenceId, "operating_area");
+                            if (!inOperatingArea) {
+                                continue;
+                            }
+                            boolean inProhibitedArea = xpGeoFencingPolygonService.isInFence(lon, lat, fenceId, "prohibited_area");
+                            if (inProhibitedArea) {
+                                continue;
+                            }
+                        } catch (Exception e) {
+                            log.error("围栏启用同步启用点位校验失败 fenceId={}, pointId={}", dto.getId(), pointItem.getId(), e);
+                            throw new ServiceException("系统异常", I18nKeyConstant.SYSTEM_EXCEPTION);
+                        }
+                        enableIds.add(pointItem.getId());
+                    }
+                    if (CollUtil.isNotEmpty(enableIds)) {
+                        xpPointService.lambdaUpdate()
+                                .in(XpPoint::getId, enableIds)
+                                .eq(XpPoint::getOperationStatus, 3)
+                                .set(XpPoint::getOperationStatus, 2)
+                                .update();
+                    }
+                    log.info("围栏启用同步启用点位完成 fenceId={}, pendingCount={}, enableCount={}, skipCount={}",
+                            dto.getId(), pendingCount, enableIds.size(), Math.max(0, pendingCount - enableIds.size()));
+                }
             }
         }
 
         OperationStrategyIndex oldIndex = OperationStrategyIndex.parse(oldOperationStrategy);
         OperationStrategyIndex newIndex = OperationStrategyIndex.parse(newOperationStrategy);
-        boolean needAutoDisableByUnion = !oldIndex.equalsNormalized(newIndex) && oldIndex.hasAnyShrinkComparedTo(newIndex);
+        // boolean needAutoDisableByUnion = !oldIndex.equalsNormalized(newIndex) && oldIndex.hasAnyShrinkComparedTo(newIndex);
+        boolean needAutoDisableByUnion = true;
 
         List<Long> addPointIds = normalizePointIds(dto.getAddPointIdList());
         List<Long> delPointIds = normalizePointIds(dto.getDelPointIdList());
@@ -729,7 +787,7 @@
         }
 
         // 围栏运营时间缩短校验:若缩短后点位时间段不在新范围内,则更新为已停用(operation_status=3)
-        if (needAutoDisableByUnion && operationAreaId != null) {
+        if (operationAreaId != null) {
             LambdaQueryWrapper<XpPoint> pointQuery = new LambdaQueryWrapper<>();
             pointQuery.eq(XpPoint::getElectronicAreaId, operationAreaId)
                     .eq(XpPoint::getPointType, 1)

--
Gitblit v1.7.1