From 338d91e9dcbd355ef8f8fa2efaa3f21c97ad4596 Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期四, 19 三月 2026 19:03:35 +0800
Subject: [PATCH] fix:围栏编辑问题

---
 xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java |   61 ++++++++++++++----------------
 1 files changed, 28 insertions(+), 33 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 61414f2..7e68557 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
@@ -338,7 +338,6 @@
                             DateUtils.localDateTimeToDate(dto.getFailureTime()),
                             maps
                     );
-                    xpElectronicFence.setStatus(1);
                 }
             }
         }
@@ -449,21 +448,19 @@
             xpElectronicFence.setStatus(0);
         } else if (dto.getStatus() == 1) {
             if (dto.getEffectType() == 1) {
-                // 设置为启用中
+                // 立即生效:设置为启用中
                 xpElectronicFence.setStatus(2);
                 xpElectronicFence.setEffectTime(LocalDateTime.now());
             } else {
                 if (dto.getEffectTime().isBefore(LocalDateTime.now())) {
-                    // 设置为启用中
+                    // 定时生效时间已过:直接设置为启用中
                     xpElectronicFence.setStatus(2);
                 } else {
-                    // 先删除以前的定时任务
+                    // 定时生效:注册生效定时任务
                     QuartzManager.removeJob((ElectronicEffectJob.effect + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_EFFECT);
-
-                    // 添加定时任务job type=1电子围栏生效 type=2电子围栏失效
-                    Map<String, ? extends Object> maps =
-                            new ImmutableMap.Builder<String, Long>().
-                                    put("type", 1L)
+                    Map<String, ? extends Object> effectMaps =
+                            new ImmutableMap.Builder<String, Long>()
+                                    .put("type", 1L)
                                     .put("id", xpElectronicFence.getId())
                                     .build();
                     QuartzManager.addJob(
@@ -471,35 +468,33 @@
                             (ElectronicEffectJob.effect + xpElectronicFence.getId()).toUpperCase(),
                             TimeJobType.ELECTRONIC_EFFECT,
                             DateUtils.localDateTimeToDate(dto.getEffectTime()),
-                            maps
+                            effectMaps
                     );
                     xpElectronicFence.setStatus(1);
                 }
             }
-            if (dto.getFailureType() != null && dto.getFailureType() == 2) {
-
-                if (dto.getFailureTime().isBefore(LocalDateTime.now())) {
-                    // 设置待启用
-                    xpElectronicFence.setStatus(1);
-                } else {
-                    // 先删除以前的定时任务
-                    QuartzManager.removeJob((ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_FAILURE);
-                    // 添加定时任务job type=1电子围栏生效 type=2电子围栏失效
-                    Map<String, ? extends Object> maps =
-                            new ImmutableMap.Builder<String, Long>().
-                                    put("type", 2L)
-                                    .put("id", xpElectronicFence.getId())
-                                    .build();
-                    QuartzManager.addJob(
-                            ElectronicEffectJob.class,
-                            (ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(),
-                            TimeJobType.ELECTRONIC_FAILURE,
-                            DateUtils.localDateTimeToDate(dto.getFailureTime()),
-                            maps
-                    );
-                    xpElectronicFence.setStatus(1);
-                }
+        }
+        // 失效时间处理:独立于 status 判断,只要 failureType=2 就注册失效定时任务
+        if (dto.getFailureType() != null && dto.getFailureType() == 2) {
+            if (dto.getFailureTime() != null && !dto.getFailureTime().isBefore(LocalDateTime.now())) {
+                // 先删除以前的定时任务,再注册新的失效定时任务
+                QuartzManager.removeJob((ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_FAILURE);
+                Map<String, ? extends Object> failureMaps =
+                        new ImmutableMap.Builder<String, Long>()
+                                .put("type", 2L)
+                                .put("id", xpElectronicFence.getId())
+                                .build();
+                QuartzManager.addJob(
+                        ElectronicEffectJob.class,
+                        (ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(),
+                        TimeJobType.ELECTRONIC_FAILURE,
+                        DateUtils.localDateTimeToDate(dto.getFailureTime()),
+                        failureMaps
+                );
             }
+        } else {
+            // failureType 不是定时失效,清除可能存在的旧失效定时任务
+            QuartzManager.removeJob((ElectronicEffectJob.failure + xpElectronicFence.getId()).toUpperCase(), TimeJobType.ELECTRONIC_FAILURE);
         }
         //根据经纬度获取当前城市code
         XpElectronicFenceArea electronicFenceArea = dto.getElectronicFenceAreas().get(0);

--
Gitblit v1.7.1