package com.xiaopeng.api.enums; import lombok.Getter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; /** * 路线策略(与高德 strategy 参数对应,见 xp_route_plan 注释) */ @Getter public enum RouteStrategyKind { /** 智能推荐 / 高德默认 */ SMART(32, "智能推荐", 1), /** 时间优先 → 速度最快 */ TIME(38, "时间优先", 2), /** 低价优先 → 少收费 */ PRICE(36, "低价优先", 3), /** 躲避拥堵 */ AVOID_CONGESTION(33, "躲避拥堵", 4), /** 高速优先 */ HIGHWAY_PRIORITY(34, "高速优先", 5), /** 不走高速 */ NO_HIGHWAY(35, "不走高速", 6), /** 大路优先 */ MAIN_ROAD(37, "大路优先", 7), /** 躲避拥堵 + 高速优先 */ AVOID_CONGESTION_HIGHWAY_PRIORITY(39, "躲避拥堵+高速优先", 8), /** 躲避拥堵 + 不走高速 */ AVOID_CONGESTION_NO_HIGHWAY(40, "躲避拥堵+不走高速", 9), /** 躲避拥堵 + 少收费 */ AVOID_CONGESTION_PRICE(41, "躲避拥堵+低价优先", 10), /** 少收费 + 不走高速 */ PRICE_NO_HIGHWAY(42, "低价优先+不走高速", 11), /** 躲避拥堵 + 少收费 + 不走高速 */ AVOID_CONGESTION_PRICE_NO_HIGHWAY(43, "躲避拥堵+低价优先+不走高速", 12), /** 躲避拥堵 + 大路优先 */ AVOID_CONGESTION_MAIN_ROAD(44, "躲避拥堵+大路优先", 13), /** 躲避拥堵 + 速度最快 */ AVOID_CONGESTION_TIME(45, "躲避拥堵+时间优先", 14), /** 速度优先,只返回一条路线 */ SPEED_PRIORITY(0, "速度优先", 15), /** 费用优先,只返回一条路线 */ FEE_PRIORITY(1, "费用优先", 16), /** 常规最快,只返回一条路线 */ REGULAR_FASTEST(2, "常规最快", 17); private static final Comparator BY_PRIORITY = Comparator.comparingInt(RouteStrategyKind::getPriority); private static final Map AMAP_STRATEGY_INDEX; private static final List ORDERED_VALUES; private static final List DEFAULT_PREFERENCE_KINDS; static { Map strategyIndex = new LinkedHashMap<>(); for (RouteStrategyKind kind : values()) { strategyIndex.put(kind.amapStrategy, kind); } AMAP_STRATEGY_INDEX = Collections.unmodifiableMap(strategyIndex); List orderedValues = new ArrayList<>(Arrays.asList(values())); orderedValues.sort(BY_PRIORITY); ORDERED_VALUES = Collections.unmodifiableList(orderedValues); DEFAULT_PREFERENCE_KINDS = Collections.unmodifiableList(Arrays.asList(SMART, TIME, PRICE)); } private final int amapStrategy; private final String displayName; private final int priority; RouteStrategyKind(int amapStrategy, String displayName, int priority) { this.amapStrategy = amapStrategy; this.displayName = displayName; this.priority = priority; } /** * 主标签优先级:数值越小越优先(默认保留智能 > 时间 > 低价,再补充其余全量策略) */ public static RouteStrategyKind primaryOf(Collection kinds) { if (kinds == null || kinds.isEmpty()) { return SMART; } return kinds.stream().min(BY_PRIORITY).orElse(SMART); } public static Optional fromAmapStrategy(int strategy) { return Optional.ofNullable(AMAP_STRATEGY_INDEX.get(strategy)); } public static RouteStrategyKind getStrategy(int strategy) { return AMAP_STRATEGY_INDEX.get(strategy); } public static List orderedValues() { return ORDERED_VALUES; } public static List defaultPreferenceKinds() { return DEFAULT_PREFERENCE_KINDS; } public static List orderedOf(Collection kinds) { if (kinds == null || kinds.isEmpty()) { return Collections.emptyList(); } List ordered = new ArrayList<>(kinds); ordered.sort(BY_PRIORITY); return ordered; } }