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/controller/XpElectronicFenceManagementController.java |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpElectronicFenceManagementController.java b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpElectronicFenceManagementController.java
index 88a3f67..f1c911e 100644
--- a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpElectronicFenceManagementController.java
+++ b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpElectronicFenceManagementController.java
@@ -35,6 +35,8 @@
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -102,6 +104,7 @@
     @PostMapping("/add")
     @ApiOperation(value = "新增电子围栏")
     public R add(@Validated @RequestBody ElectronicFenceAddDto dto) {
+        validateFenceTime(dto.getStatus(), dto.getEffectType(), dto.getEffectTime(), dto.getFailureType(), dto.getFailureTime());
         return xpElectronicFenceService.addElectronic(dto);
     }
 
@@ -154,6 +157,7 @@
     @Transactional
     @ShardingSphereTransactionType(TransactionType.BASE)
     public R edit(@Validated @RequestBody ElectronicFenceUpdateDto dto) {
+        validateFenceTime(dto.getStatus(), dto.getEffectType(), dto.getEffectTime(), dto.getFailureType(), dto.getFailureTime());
         return xpElectronicFenceService.editElectronic(dto);
     }
 
@@ -313,4 +317,36 @@
         XpElectronicFence xpElectronicFence = xpElectronicFenceService.getById(fenceId);
         return R.ok(xpElectronicFence);
     }
+
+    /**
+     * 校验围栏生效时间和失效时间的合法性:
+     * <ul>
+     *   <li>生效类型不是立即生效(effectType != 1)时,生效时间不能早于当前时间</li>
+     *   <li>失效类型不是永不失效(failureType != 1)时,失效时间不能早于当前时间</li>
+     * </ul>
+     *
+     * @param status
+     * @param effectType  生效类型(1=立即生效 2=定时生效)
+     * @param effectTime  生效时间
+     * @param failureType 失效类型(1=永不失效 2=定时失效)
+     * @param failureTime 失效时间
+     */
+    private void validateFenceTime(@NotNull Integer status, Integer effectType, LocalDateTime effectTime,
+                                   Integer failureType, LocalDateTime failureTime) {
+        LocalDateTime now = LocalDateTime.now();
+        // 定时生效时,生效时间不能早于当前时间
+        if (null != status && status == 2 && effectType != null && effectType != 1) {
+            if (effectTime == null || effectTime.isBefore(now)) {
+                throw new ServiceException("围栏生效时间不合法,定时生效时生效时间不能早于当前时间",
+                        I18nKeyConstant.FENCE_EFFECT_TIME_INVALID);
+            }
+        }
+        // 定时失效时,失效时间不能早于当前时间
+        if (null != status && status == 2 && failureType != null && failureType != 1) {
+            if (failureTime == null || failureTime.isBefore(now)) {
+                throw new ServiceException("围栏失效时间不合法,定时失效时失效时间不能早于当前时间",
+                        I18nKeyConstant.FENCE_FAILURE_TIME_INVALID);
+            }
+        }
+    }
 }

--
Gitblit v1.7.1