yeg
2026-09-18 a058f6109834e29435f5ce4aa19a43d67d07c060
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.talentcard.server.business.merchant;
 
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
 
public final class MerchantTypeCatalog {
 
    private static final Map<String, MerchantType> BY_ALIAS;
    private static final List<MerchantType> TYPES;
 
    static {
        List<MerchantType> types = List.of(
                type("food", "餐饮服务", "暖心食享", "MERCHANT", null, null, null, true,
                        "餐饮", "餐饮商家"),
                type("scenic", "景区服务", "悦览花城", "MERCHANT", null, null, null, true,
                        "景区", "景点服务"),
                type("hotel", "酒店服务", "舒心安居", "MERCHANT", null, null, null, true,
                        "酒店", "住宿服务"),
                type("apartment", "公寓租赁", "舒心安居", "MERCHANT", null, null, null, true,
                        "公寓租赁服务", "公寓服务"),
                type("cinema", "观影服务", "怡乐生活", "CINEMA", null, null, null, true,
                        "theatre", "电影院", "影院", "影城", "剧院"),
                type("fuel", "加油服务", "畅行无忧", "FUEL", null, null, null, true,
                        "加油", "加油站"),
                type("parking", "停车服务", "畅行无忧", "PARKING", null, null, null, true,
                        "停车", "停车场"),
                type("carWash", "自助洗车", "畅行无忧", "CAR_WASH", null, null, null, true,
                        "自主洗车", "自助洗车服务", "洗车服务"),
                type("medical", "免费体检", "臻享礼遇", "MEDICAL", "medical", "MEDICAL", null, true,
                        "healthCheck", "体检服务", "医疗体检"),
                type("employment", "配偶推荐就业", "臻享礼遇", "SPOUSE_EMPLOYMENT", "employment", "SPOUSE_EMPLOYMENT", null, true,
                        "就业服务", "配偶就业"),
                type("finance", "金融服务", "臻享礼遇", "FINANCE", "finance", "FINANCE", null, true,
                        "金融"),
                type("approval", "行政审批", "臻享礼遇", "ADMIN_APPROVAL", "approval", "ADMIN_APPROVAL", null, true,
                        "行政审批服务", "政务服务"),
                type("children", "子女托管", "臻享礼遇", "CHILD_ENTRUSTMENT", "children", "CHILD_ENTRUSTMENT", null, true,
                        "学生托付", "学生托管", "子女托管服务"),
                type("housing", "购房优惠", "惠享好物", "SHOPPING", null, null, "housing", true,
                        "购房服务", "住房服务"),
                type("car", "购车服务", "惠享好物", "SHOPPING", null, null, "car", true,
                        "购车优惠", "汽车服务"),
                type("appliance", "家电服务", "惠享好物", "SHOPPING", null, null, "appliance", true,
                        "家用电器服务"),
                type("digital", "数码服务", "惠享好物", "SHOPPING", null, null, "digital", true,
                        "数码产品服务"),
                type("culture", "文化服务", "惠享好物", "SHOPPING", null, null, "book", true,
                        "图书服务", "文化图书服务"),
                type("telecom", "电信服务", "惠享好物", "SHOPPING", null, null, "telecom", true,
                        "通信服务"),
                type("dental", "口腔治疗保健", "惠享好物", "MERCHANT", null, null, "dental", true,
                        "口腔服务", "口腔保健"),
                type("shopping", "购物服务", "惠享好物", "SHOPPING", null, null, null, true,
                        "惠享好物")
        );
        Map<String, MerchantType> aliases = new LinkedHashMap<>();
        for (MerchantType type : types) {
            register(aliases, type.code(), type);
            register(aliases, type.displayName(), type);
            for (String alias : type.aliases()) register(aliases, alias, type);
        }
        TYPES = List.copyOf(types);
        BY_ALIAS = Map.copyOf(aliases);
    }
 
    private MerchantTypeCatalog() {
    }
 
    public static Optional<MerchantType> find(String value) {
        return Optional.ofNullable(BY_ALIAS.get(normalize(value)));
    }
 
    public static String canonicalCode(String value) {
        return find(value).map(MerchantType::code).orElse("other");
    }
 
    public static String displayName(String value) {
        return find(value).map(MerchantType::displayName).orElseGet(() -> value == null ? "" : value.trim());
    }
 
    public static List<String> codesForTopic(String topicName) {
        return TYPES.stream()
                .filter(type -> type.topicName().equals(topicName))
                .map(MerchantType::code)
                .toList();
    }
 
    public static List<String> codesForRequestedValue(String value) {
        List<String> topicCodes = codesForTopic(value == null ? "" : value.trim());
        if (!topicCodes.isEmpty()) return topicCodes;
        return find(value).map(type -> List.of(type.code())).orElseGet(List::of);
    }
 
    public static List<String> codesForShoppingCategory(String categoryKey) {
        return TYPES.stream()
                .filter(type -> categoryKey != null && categoryKey.equals(type.shoppingCategoryKey()))
                .map(MerchantType::code)
                .toList();
    }
 
    public static Optional<MerchantType> forPremiumCategory(String categoryKey) {
        return TYPES.stream()
                .filter(type -> categoryKey != null && categoryKey.equals(type.premiumCategoryKey()))
                .findFirst();
    }
 
    public static Collection<MerchantType> all() {
        return TYPES;
    }
 
    private static MerchantType type(
            String code,
            String displayName,
            String topicName,
            String detailType,
            String premiumCategoryKey,
            String premiumBusinessType,
            String shoppingCategoryKey,
            boolean supportsMerchantAppLogin,
            String... aliases
    ) {
        Set<String> values = new LinkedHashSet<>();
        if (aliases != null) values.addAll(List.of(aliases));
        return new MerchantType(code, displayName, topicName, detailType, premiumCategoryKey,
                premiumBusinessType, shoppingCategoryKey, supportsMerchantAppLogin, Set.copyOf(values));
    }
 
    private static void register(Map<String, MerchantType> aliases, String alias, MerchantType type) {
        String key = normalize(alias);
        if (!key.isBlank()) aliases.put(key, type);
    }
 
    private static String normalize(String value) {
        return value == null ? "" : value.trim().toLowerCase(Locale.ROOT);
    }
 
    public record MerchantType(
            String code,
            String displayName,
            String topicName,
            String detailType,
            String premiumCategoryKey,
            String premiumBusinessType,
            String shoppingCategoryKey,
            boolean supportsMerchantAppLogin,
            Set<String> aliases
    ) {
    }
}