liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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<RouteStrategyKind> BY_PRIORITY = Comparator.comparingInt(RouteStrategyKind::getPriority);
    private static final Map<Integer, RouteStrategyKind> AMAP_STRATEGY_INDEX;
    private static final List<RouteStrategyKind> ORDERED_VALUES;
    private static final List<RouteStrategyKind> DEFAULT_PREFERENCE_KINDS;
 
    static {
        Map<Integer, RouteStrategyKind> strategyIndex = new LinkedHashMap<>();
        for (RouteStrategyKind kind : values()) {
            strategyIndex.put(kind.amapStrategy, kind);
        }
        AMAP_STRATEGY_INDEX = Collections.unmodifiableMap(strategyIndex);
 
        List<RouteStrategyKind> 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;
    }
 
    /**
     * 主标签优先级:数值越小越优先(默认保留智能 &gt; 时间 &gt; 低价,再补充其余全量策略)
     */
    public static RouteStrategyKind primaryOf(Collection<RouteStrategyKind> kinds) {
        if (kinds == null || kinds.isEmpty()) {
            return SMART;
        }
        return kinds.stream().min(BY_PRIORITY).orElse(SMART);
    }
 
    public static Optional<RouteStrategyKind> 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<RouteStrategyKind> orderedValues() {
        return ORDERED_VALUES;
    }
 
    public static List<RouteStrategyKind> defaultPreferenceKinds() {
        return DEFAULT_PREFERENCE_KINDS;
    }
 
    public static List<RouteStrategyKind> orderedOf(Collection<RouteStrategyKind> kinds) {
        if (kinds == null || kinds.isEmpty()) {
            return Collections.emptyList();
        }
        List<RouteStrategyKind> ordered = new ArrayList<>(kinds);
        ordered.sort(BY_PRIORITY);
        return ordered;
    }
}