From 20eb98994ee1c89eb4ef453037a48d5e357ade5c Mon Sep 17 00:00:00 2001
From: yyy <1083599556@qq.com>
Date: 星期五, 24 四月 2026 21:53:12 +0800
Subject: [PATCH] 1.围栏、点位、场站接口修改和添加 2.发送微信通知 优惠卷、活动、改派/车接单

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java |   92 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 69 insertions(+), 23 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 a92477b..f28c5a2 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
@@ -31,6 +31,7 @@
 import com.xiaopeng.map.service.XpElectronicFenceAreaService;
 import com.xiaopeng.map.service.XpElectronicFenceService;
 import com.xiaopeng.map.service.XpPointService;
+import com.xiaopeng.map.service.XpStationService;
 import com.xiaopeng.map.utils.OperationStrategyIndex;
 import com.xiaopeng.map.utils.GDMapGeocodingUtil;
 import com.xiaopeng.map.utils.PolygonOverlapService;
@@ -44,6 +45,7 @@
 import org.locationtech.jts.geom.Polygon;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.data.geo.Point;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
@@ -92,6 +94,9 @@
     private XpElectronicFenceAreaService xpElectronicFenceAreaService;
     @Autowired
     private ApplicationEventPublisher applicationEventPublisher;
+    @Autowired
+    @Lazy
+    protected XpStationService xpStationService;
 
     @Override
     public PageInfo<XpElectronicFence> pageList(ElectronicPageListQuery query) {
@@ -100,10 +105,13 @@
         }
         normalizeProhibitedAreaCountFilter(query);
         PageInfo<XpElectronicFence> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<XpElectronicFence> list = this.baseMapper.pageList(pageInfo, query);
-        if (list.isEmpty()) {
+        pageInfo.setSearchCount(false);
+        Long total = baseMapper.pageListCount(query);
+        pageInfo.setTotal(total);
+        if (total == 0L) {
             return new PageInfo<>();
         }
+        List<XpElectronicFence> list = this.baseMapper.pageList(pageInfo, query);
         List<Long> electronicIds = list.stream().map(XpElectronicFence::getId).collect(Collectors.toList());
         Map<Long, List<XpElectronicFenceArea>> electronicFenceAreaMap = xpElectronicFenceAreaMapper.selectList(new LambdaQueryWrapper<XpElectronicFenceArea>()
                         .in(XpElectronicFenceArea::getElectronicId, electronicIds)).stream()
@@ -258,21 +266,23 @@
         }
 
         //根据经纬度获取当前城市code
-        XpElectronicFenceArea xpElectronicFenceArea = dto.getElectronicFenceAreas().get(0);
-        String[] split = xpElectronicFenceArea.getFencePoints().split(",");
-        Coordinate[] coordinates = new Coordinate[split.length + 1];
-        for (int i = 0; i < split.length; i++) {
-            String[] split1 = split[i].split("_");
-            coordinates[i] = new Coordinate(Double.parseDouble(split1[0]), Double.parseDouble(split1[1]));
-        }
-        org.locationtech.jts.geom.Point point = calculateCentroid(coordinates);
-        Map<String, String> geocode = gdMapGeocodingUtil.geocode(point.getX() + "", point.getY() + "");
-        if (null == geocode) {
-            return R.fail("经纬度转换城市code失败");
-        }
-        String cityCode = geocode.get("cityCode");
-        dto.setCityCode(cityCode);
+//        XpElectronicFenceArea xpElectronicFenceArea = dto.getElectronicFenceAreas().get(0);
+//        String[] split = xpElectronicFenceArea.getFencePoints().split(",");
+//        Coordinate[] coordinates = new Coordinate[split.length + 1];
+//        for (int i = 0; i < split.length; i++) {
+//            String[] split1 = split[i].split("_");
+//            coordinates[i] = new Coordinate(Double.parseDouble(split1[0]), Double.parseDouble(split1[1]));
+//        }
+//        org.locationtech.jts.geom.Point point = calculateCentroid(coordinates);
+//        Map<String, String> geocode = gdMapGeocodingUtil.geocode(point.getX() + "", point.getY() + "");
+//        if (null == geocode) {
+//            return R.fail("经纬度转换城市code失败");
+//        }
+//        String cityCode = geocode.get("cityCode");
+//        dto.setCityCode(cityCode);
+
         xpElectronicFence.setCityCode(dto.getCityCode());
+
         // 生成围栏id 规则:城市首字母-类型简写-4位自增流水号(如 SZ-OP-001),支持复制;数据停用或删除后,流水号不回收
         XpRegion xpRegion = xpRegionMapper.selectOne(new LambdaQueryWrapper<XpRegion>()
                 .eq(XpRegion::getCode, dto.getCityCode()));
@@ -405,6 +415,7 @@
             QuartzManager.removeJob((ElectronicEffectJob.effect + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_EFFECT);
             QuartzManager.removeJob((ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_FAILURE);
         }
+        /*
         //根据经纬度获取当前城市code
         XpElectronicFenceArea electronicFenceArea = dto.getElectronicFenceAreas().get(0);
         String[] split = electronicFenceArea.getFencePoints().split(",");
@@ -420,6 +431,8 @@
         }
         String cityCode = geocode.get("cityCode");
         dto.setCityCode(cityCode);
+         */
+
         xpElectronicFence.setCityCode(dto.getCityCode());
 
         this.updateById(xpElectronicFence);
@@ -493,7 +506,7 @@
                         XpGeoFencingPolygon xpGeoFencingPolygon = new XpGeoFencingPolygon();
                         xpGeoFencingPolygon.setFenceId(String.valueOf(xpElectronicFence.getId()));
                         xpGeoFencingPolygon.setName(xpElectronicFence.getElectronicName());
-                        xpGeoFencingPolygon.setCityCode(cityCode);
+                        xpGeoFencingPolygon.setCityCode(dto.getCityCode());
                         xpGeoFencingPolygon.setAreaId(String.valueOf(newElectronicFenceArea.getId()));
                         xpGeoFencingPolygon.setOperationStrategy(xpElectronicFence.getOperationStrategy());
                         // 将围栏点转换为GeoJSON多边形
@@ -504,7 +517,7 @@
                         // 如果存在,则更新已有文档
                         old.setFenceId(String.valueOf(xpElectronicFence.getId()));
                         old.setName(xpElectronicFence.getElectronicName());
-                        old.setCityCode(cityCode);
+                        old.setCityCode(dto.getCityCode());
                         old.setAreaId(String.valueOf(newElectronicFenceArea.getId()));
                         old.setOperationStrategy(xpElectronicFence.getOperationStrategy());
                         // 将围栏点转换为GeoJSON多边形
@@ -1000,7 +1013,26 @@
         queryWrapper.like(query.getCityCode() != null, XpElectronicFence::getCityCode, query.getCityCode());
         return list(queryWrapper);
     }
+    @Transactional
+    @ShardingSphereTransactionType(TransactionType.BASE)
+    @Override
+    public void enableFence(Long electronicId) {
+        // 电子围栏生效
+        XpElectronicFence electronicFence = super.getById(electronicId);
+        if(electronicFence != null){
+            electronicFence.setStatus(2);
+            super.updateById(electronicFence);
+            List<XpElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery().eq(XpElectronicFenceArea::getElectronicId, electronicId).list();
+            if(!electronicFenceAreaList.isEmpty()){
+                // 设置为生效
+                for(XpElectronicFenceArea electronicFenceArea : electronicFenceAreaList){
+                    electronicFenceArea.setAreaStatus(1);
+                }
+                xpElectronicFenceAreaService.updateBatchById(electronicFenceAreaList);
+            }
+        }
 
+    }
     @Override
     @Transactional
     @ShardingSphereTransactionType(TransactionType.BASE)
@@ -1019,16 +1051,30 @@
         electronicFence.setStatus(3);
         this.updateById(electronicFence);
 
+        List<String> toDeleteAreaIdStrings = new ArrayList<>();
+
         List<XpElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery()
                 .eq(XpElectronicFenceArea::getElectronicId, electronicId)
                 .list();
-        if (CollUtil.isEmpty(electronicFenceAreaList)) {
-            return;
+        if (!CollUtil.isEmpty(electronicFenceAreaList)) {
+            for (XpElectronicFenceArea electronicFenceArea : electronicFenceAreaList) {
+                electronicFenceArea.setAreaStatus(2);
+                toDeleteAreaIdStrings.add(String.valueOf(electronicFenceArea.getId()));
+            }
+
+            xpElectronicFenceAreaService.updateBatchById(electronicFenceAreaList);
         }
-        for (XpElectronicFenceArea electronicFenceArea : electronicFenceAreaList) {
-            electronicFenceArea.setAreaStatus(2);
+
+        xpStationService.setStatusFailure(electronicId);//场站失效
+
+        // 删除旧的区域数据,然后保存新的区域数据
+        mongoTemplate.remove(new Query(Criteria.where("fenceId").is(String.valueOf(electronicId))), XpGeoFencingPolygon.class);
+        if(CollUtil.isNotEmpty(toDeleteAreaIdStrings)){
+            Query delMongoQuery = new Query();
+            delMongoQuery.addCriteria(Criteria.where("fenceId").is(String.valueOf(electronicId)));
+            delMongoQuery.addCriteria(Criteria.where("areaId").in(toDeleteAreaIdStrings));
+            mongoTemplate.remove(delMongoQuery, XpGeoFencingProhibitedPolygon.class);
         }
-        xpElectronicFenceAreaService.updateBatchById(electronicFenceAreaList);
     }
 
 

--
Gitblit v1.7.1