brand-id-env-maps.mjs
3.7 KB
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
/**
* @file 日报模版 brandId 双环境映射(测试 daily / 生产 production)。
* 测试 ID 来自 Excel 转换脚本;生产 ID 对齐线上洽谈明细 brandIdMap。
* 供 remap 脚本、单测与 convert 脚本 sidecar 引用。
*/
/** @type {Record<'daily' | 'production', Record<string, number>>} */
export const BRAND_NAME_TO_ID = {
daily: {
问界: 3454,
享界: 3503,
智界: 3458,
尚界: 3574,
尊界: 3502,
岚图: 3067
},
production: {
问界: 2695,
享界: 2741,
智界: 2698,
尚界: 2797,
尊界: 2740,
岚图: 2188
}
}
/** 鸿蒙五界 brandId 列表(不含岚图) */
export const FIVE_REALM_BRAND_IDS = {
daily: [
BRAND_NAME_TO_ID.daily.问界,
BRAND_NAME_TO_ID.daily.享界,
BRAND_NAME_TO_ID.daily.智界,
BRAND_NAME_TO_ID.daily.尚界,
BRAND_NAME_TO_ID.daily.尊界
],
production: [
BRAND_NAME_TO_ID.production.问界,
BRAND_NAME_TO_ID.production.享界,
BRAND_NAME_TO_ID.production.智界,
BRAND_NAME_TO_ID.production.尚界,
BRAND_NAME_TO_ID.production.尊界
]
}
/** 五界 + 岚图,对齐 F3-3 / F1-11 / F2-11 filterBrandId */
export const FILTER_BRAND_IDS = {
daily: [...FIVE_REALM_BRAND_IDS.daily, BRAND_NAME_TO_ID.daily.岚图],
production: [...FIVE_REALM_BRAND_IDS.production, BRAND_NAME_TO_ID.production.岚图]
}
/**
* 构建 fromEnv → toEnv 的 brandId 数值替换表。
* @param {'daily' | 'production'} fromEnv
* @param {'daily' | 'production'} toEnv
* @returns {Record<number, number>}
*/
export function buildBrandIdRemap(fromEnv = 'daily', toEnv = 'production') {
const fromMap = BRAND_NAME_TO_ID[fromEnv]
const toMap = BRAND_NAME_TO_ID[toEnv]
const remap = {}
for (const name of Object.keys(fromMap)) {
remap[fromMap[name]] = toMap[name]
}
return remap
}
/**
* 替换 brandId / filterBrandId 数组中的 ID。
* @param {number[]} ids
* @param {Record<number, number>} remap
* @returns {number[]}
*/
export function remapBrandIdArray(ids, remap) {
if (!Array.isArray(ids) || ids.length === 0) return ids
return ids.map(id => {
if (id in remap) return remap[id]
return id
})
}
/**
* 深度遍历 schema list,就地替换 brandId / filterBrandId。
* @param {object[]} list
* @param {Record<number, number>} remap
*/
export function remapSchemaBrandIds(list, remap) {
function walk(field) {
if (!field || typeof field !== 'object') return
if (Array.isArray(field.brandId) && field.brandId.length) {
field.brandId = remapBrandIdArray(field.brandId, remap)
}
if (Array.isArray(field.filterBrandId) && field.filterBrandId.length) {
field.filterBrandId = remapBrandIdArray(field.filterBrandId, remap)
}
const children = field.children
if (!Array.isArray(children)) return
for (const child of children) {
if (Array.isArray(child)) {
child.forEach(walk)
} else {
walk(child)
}
}
}
for (const field of list || []) {
walk(field)
}
}
/**
* 生成 JS fixture 文件头 brandIdMap 注释块。
* @param {'daily' | 'production'} env
* @returns {string}
*/
export function buildFileHeaderComment(env = 'production') {
const map = BRAND_NAME_TO_ID[env]
const lines = [
'// const baseSceneCode = {',
"// '1.1': 100101, //精品升级",
"// '1.2': 100102, //次新车升配",
"// '1.3': 100103, //售后众筹",
"// '2.1.1': 110101, //售前会员权益升级",
"// '2.1.2': 110102, //售后会员权益升级",
"// '2.3.1': 110201, //售前延保",
"// '2.3.2': 110202, //售后延保",
'// }',
'// const sceneType = {',
"// '延保': 0,",
"// '权益': 0,",
"// '轻改': 1,",
'// }',
'// const brandIdMap = {'
]
for (const [name, id] of Object.entries(map)) {
lines.push(`// '${name}': ${id},`)
}
lines.push('// }')
return lines.join('\n')
}