fieldOptionsService.js
1.12 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
const { fetchFieldOptionsAdapter } = require('./fieldOptionsAdapters.js')
const optionsCache = new Map()
function buildCacheKey(params = {}) {
const brandKey = params.carBrandTypeFlag != null && params.carBrandTypeFlag !== ''
? String(params.carBrandTypeFlag)
: Array.isArray(params.groupBrandIds)
? params.groupBrandIds.join(',')
: ''
return [
params.optionsKey || '',
params.merchantId || '',
params.yqMerchantId || '',
params.staffUuid || '',
params.reportDate || '',
params.saleDate || '',
params.reportType || 'store',
brandKey,
params.name || '',
JSON.stringify(params.sceneList || [])
].join('|')
}
async function fetchFieldOptions(params = {}, options = {}) {
const { useCache = true } = options
const cacheKey = buildCacheKey(params)
if (useCache && optionsCache.has(cacheKey)) {
return optionsCache.get(cacheKey)
}
const result = await fetchFieldOptionsAdapter(params)
if (result?.code === 0 && useCache) {
optionsCache.set(cacheKey, result)
}
return result
}
function clearFieldOptionsCache() {
optionsCache.clear()
}
module.exports = {
fetchFieldOptions,
clearFieldOptionsCache
}