“mitao”
2026-03-19 338d91e9dcbd355ef8f8fa2efaa3f21c97ad4596
fix:围栏编辑问题
6个文件已修改
108 ■■■■■ 已修改文件
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/constant/I18nKeyConstant.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/controller/XpElectronicFenceManagementController.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/resources/i18n/messages.properties 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/resources/i18n/messages_en_US.properties 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/resources/i18n/messages_zh_CN.properties 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/constant/I18nKeyConstant.java
@@ -105,4 +105,9 @@
    String POINT_ENABLE_NOT_IN_OPERATING_AREA = "point.enable.not.in.operating.area";
    // 点位启用-在禁行区内
    String POINT_ENABLE_IN_PROHIBITED_AREA = "point.enable.in.prohibited.area";
    // 围栏生效时间不合法(定时生效时,生效时间不能早于当前时间)
    String FENCE_EFFECT_TIME_INVALID = "fence.effect.time.invalid";
    // 围栏失效时间不合法(定时失效时,失效时间不能早于当前时间)
    String FENCE_FAILURE_TIME_INVALID = "fence.failure.time.invalid";
}
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);
            }
        }
    }
}
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);
xp-robotaxi-map-boot/src/main/resources/i18n/messages.properties
@@ -42,3 +42,5 @@
point.delete.has.cruise.plan.point=操作失败,该点位有关联的巡游计划点位
point.enable.not.in.operating.area=当前点位不在围栏运营区域内,不能启用。
point.enable.in.prohibited.area=当前点位在禁行区内,不能启用。
fence.effect.time.invalid=围栏生效时间不合法,定时生效时生效时间不能早于当前时间
fence.failure.time.invalid=围栏失效时间不合法,定时失效时失效时间不能早于当前时间
xp-robotaxi-map-boot/src/main/resources/i18n/messages_en_US.properties
@@ -35,3 +35,5 @@
point.delete.has.cruise.plan.point=Operation failed. This point is associated with cruise plan points.
point.enable.not.in.operating.area=This point is not within the fence operating area and cannot be enabled.
point.enable.in.prohibited.area=This point is in a prohibited area and cannot be enabled.
fence.effect.time.invalid=Invalid fence effect time: the scheduled effect time cannot be earlier than the current time
fence.failure.time.invalid=Invalid fence failure time: the scheduled failure time cannot be earlier than the current time
xp-robotaxi-map-boot/src/main/resources/i18n/messages_zh_CN.properties
@@ -35,3 +35,5 @@
point.delete.has.cruise.plan.point=操作失败,该点位有关联的巡游计划点位
point.enable.not.in.operating.area=当前点位不在围栏运营区域内,不能启用。
point.enable.in.prohibited.area=当前点位在禁行区内,不能启用。
fence.effect.time.invalid=围栏生效时间不合法,定时生效时生效时间不能早于当前时间
fence.failure.time.invalid=围栏失效时间不合法,定时失效时失效时间不能早于当前时间