dsh-data-dashboard 0.0.0-stage → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +35 -2
  2. package/assets/theater-board.svg +1 -0
  3. package/backend/incremental/flow.mjs +492 -0
  4. package/backend/incremental/jobs.mjs +58 -0
  5. package/backend/incremental/xlsx-rows.mjs +145 -0
  6. package/backend/job-worker.mjs +22 -0
  7. package/backend/modules/banquet/index.mjs +46 -0
  8. package/backend/modules/inventory/index.mjs +45 -0
  9. package/backend/modules/inventory/legacy-fields.mjs +83 -0
  10. package/backend/modules/invoice/index.mjs +72 -0
  11. package/backend/modules/movement/index.mjs +68 -0
  12. package/backend/modules/opening/index.mjs +48 -0
  13. package/backend/modules/target/index.mjs +45 -0
  14. package/backend/modules/terminal/index.mjs +114 -0
  15. package/backend/modules.mjs +12 -0
  16. package/backend/public/admin.css +220 -0
  17. package/backend/public/admin.js +772 -0
  18. package/backend/public/board.css +70 -0
  19. package/backend/public/board.html +50 -0
  20. package/backend/public/board.js +153 -0
  21. package/backend/public/index.html +113 -0
  22. package/backend/public/org-mapping.js +49 -0
  23. package/backend/public/review.css +5 -0
  24. package/backend/public/review.js +452 -0
  25. package/backend/real-data/generate-dashboard.mjs +137 -0
  26. package/backend/real-data/inventory-history.mjs +316 -0
  27. package/backend/real-data/organization-mapping.mjs +166 -0
  28. package/backend/real-data/source-payload.mjs +459 -0
  29. package/backend/real-data/terminal-components.mjs +280 -0
  30. package/backend/real-data/terminal-structure.css +105 -0
  31. package/backend/real-data/terminal-structure.mjs +276 -0
  32. package/backend/real-data/v10-components.mjs +112 -0
  33. package/backend/real-data/v10-details.css +18 -0
  34. package/backend/real-data/v10-details.mjs +251 -0
  35. package/backend/real-data/v10-layout.css +27 -0
  36. package/backend/real-data/v10-model.mjs +568 -0
  37. package/backend/real-data/v10-overview-data.mjs +253 -0
  38. package/backend/real-data/v10-overview.css +370 -0
  39. package/backend/real-data/v10-overview.mjs +340 -0
  40. package/backend/real-data/v10-presentation.mjs +354 -0
  41. package/backend/real-data/v10-shell.html +1097 -0
  42. package/backend/real-data/v10-template.mjs +353 -0
  43. package/backend/recognition/fingerprint.mjs +32 -0
  44. package/backend/recognition/headers.mjs +2 -0
  45. package/backend/recognition/module-definition.mjs +4 -0
  46. package/backend/recognition/result.mjs +29 -0
  47. package/backend/recognition/upload-limits.mjs +14 -0
  48. package/backend/review-engine.mjs +364 -0
  49. package/backend/review-service.mjs +182 -0
  50. package/backend/server.mjs +569 -0
  51. package/backend/store.mjs +68 -0
  52. package/backend/target-template.mjs +47 -0
  53. package/backend/validate-workbook.mjs +251 -0
  54. package/backend/web-sync/README.md +37 -0
  55. package/backend/web-sync/client.mjs +63 -0
  56. package/backend/web-sync/exporter.mjs +260 -0
  57. package/backend/web-sync/local.html +34 -0
  58. package/backend/web-sync/server.mjs +147 -0
  59. package/build-manifest.json +80 -0
  60. package/client.js +54 -0
  61. package/cordis.patch.yml +3 -0
  62. package/index.js +117 -0
  63. package/lib/dist-manifest.mjs +19 -0
  64. package/lib/market-index.mjs +56 -0
  65. package/lib/package-audit.mjs +34 -0
  66. package/lib/settings.mjs +71 -0
  67. package/lib/tool-definitions.mjs +56 -0
  68. package/lib/tools.mjs +255 -0
  69. package/locale/en.json +6 -0
  70. package/locale/zh.json +6 -0
  71. package/package.json +71 -4
@@ -0,0 +1,253 @@
1
+ // Serialized into each offline dashboard. Keep this factory self-contained.
2
+ export function createV10OverviewData(model, presentation) {
3
+ const cache = new WeakMap(), regionalCache = new Map();
4
+ const finite = value => typeof value === 'number' && Number.isFinite(value);
5
+ const text = value => typeof value === 'string' && value.trim().length > 0;
6
+ // Pure per string; memoized because comparisons re-check every row's date.
7
+ const validDates = new Map();
8
+ const validDate = value => {
9
+ if (typeof value !== 'string') return false;
10
+ let result = validDates.get(value);
11
+ if (result === undefined) {
12
+ result = /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(`${value}T00:00:00Z`)) && new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value;
13
+ validDates.set(value, result);
14
+ }
15
+ return result;
16
+ };
17
+ const keyFor = filters => JSON.stringify([filters.month, filters.period, filters.start, filters.end, filters.region, filters.office, filters.unit, filters.product]);
18
+ const periodOf = filters => model.periodOf ? model.periodOf(filters) : { mode: 'month', start: `${filters.month}-01`, end: null, month: filters.month };
19
+ const pending = (label, unit, reason, state = 'pending') => ({ label, unit, value: null, state, reason });
20
+ const copy = item => ({ ...item, ...(item?.notes ? { notes: [...item.notes] } : {}), ...(item?.range ? { range: { ...item.range } } : {}) });
21
+ const ready = item => item?.state === 'available' && finite(item.value);
22
+ const partsFor = key => { try { const result = JSON.parse(key); return Array.isArray(result) ? result : []; } catch { return []; } };
23
+ const fullName = key => partsFor(key).map(value => text(value) ? value : '未提供').join(' / ') || '未提供组织';
24
+ const defaultFilters = filters => { const f = { ...model.defaults, ...filters }, p = periodOf(f); return p.mode === 'range' ? { ...f, month: p.month } : f; };
25
+ const childFilters = (filters, level, key) => ({ ...filters, [level]: key,
26
+ ...(level === 'region' ? { office: 'all', unit: 'all' } : level === 'office' ? { unit: 'all' } : {}) });
27
+ const monthEnd = month => new Date(Date.UTC(Number(month.slice(0, 4)), Number(month.slice(5, 7)), 0)).toISOString().slice(0, 10);
28
+ const priorDate = (date, fullMonthEnd = false) => {
29
+ const month = `${Number(date.slice(0, 4)) - 1}${date.slice(4, 7)}`, last = monthEnd(month);
30
+ return fullMonthEnd ? last : `${month}-${String(Math.min(Number(date.slice(8)), Number(last.slice(8)))).padStart(2, '0')}`;
31
+ };
32
+ const sum = values => {
33
+ let value = 0, correction = 0;
34
+ for (const item of values) { const next = item - correction, updated = value + next; correction = (updated - value) - next; value = updated; }
35
+ return value;
36
+ };
37
+ function windowMetric(id, module, start, end, requireMonths = false) {
38
+ const field = id === 'opening' ? 'bottles' : 'amount', unit = id === 'opening' ? '瓶' : '元';
39
+ const fail = (reason, state = 'missing') => ({ ...pending('同期来源合计', unit, reason, state), range: { start, end } });
40
+ const source = model.payload.modules[id], cover = model.payload.coverage[id];
41
+ if (source.state === 'unavailable') return fail('未接入有效来源');
42
+ if (!validDate(start) || !validDate(end) || start > end) return fail('比较期间无效');
43
+ if (!validDate(cover?.start) || !validDate(cover?.end) || cover.start > start || cover.end < end) return fail('来源未覆盖完整比较期间');
44
+ if (source.metrics?.[field]?.status === 'pending') return fail('来源数值口径待确认', 'pending');
45
+ const scoped = module.scopedRows || [];
46
+ if (scoped.some(row => !validDate(row.date))) return fail('存在缺失或无效日期,无法完整分期', 'pending');
47
+ const rows = scoped.filter(row => row.date >= start && row.date <= end);
48
+ if (!rows.length) return fail('当前范围缺少同期记录,不推定为零');
49
+ if (requireMonths) {
50
+ const months = new Set(rows.map(row => row.date.slice(0, 7)));
51
+ for (let date = `${start.slice(0, 7)}-01`; date <= end; date = new Date(Date.UTC(Number(date.slice(0, 4)), Number(date.slice(5, 7)), 1)).toISOString().slice(0, 10)) {
52
+ if (!months.has(date.slice(0, 7))) return fail('累计比较期间缺月,不能补零');
53
+ }
54
+ }
55
+ if (rows.some(row => !finite(row[field]))) return fail('比较期间存在缺失或不可用数值', 'pending');
56
+ const value = sum(rows.map(row => row[field]));
57
+ if (!finite(value)) return fail('来源合计超出可表示范围', 'pending');
58
+ return { label: '同期来源合计', unit, value, state: 'available', reason: null, range: { start, end },
59
+ negative: id === 'opening' ? null : sum(rows.filter(row => row.amount < 0).map(row => row.amount)) };
60
+ }
61
+ function yearComparison(id, module, filters, cumulative = false, fixedRange = null) {
62
+ const p = periodOf(filters), range = p.mode === 'range';
63
+ const label = cumulative ? '累计同比' : range ? '区间同比' : '当月同比', cover = model.payload.coverage[id];
64
+ const month = range ? p.month : filters.month, validMonth = /^\d{4}-(0[1-9]|1[0-2])$/.test(month || '');
65
+ const start = fixedRange?.start || (validMonth ? cumulative ? `${month.slice(0, 4)}-01-01` : range ? p.start : `${month}-01` : null);
66
+ const end = fixedRange?.end || (validMonth && validDate(cover?.end) ? [range ? p.end : monthEnd(month), cover.end].sort()[0] : null);
67
+ const current = windowMetric(id, module, start, end, cumulative);
68
+ const previous = windowMetric(id, module, validDate(start) ? priorDate(start) : null,
69
+ validDate(end) ? priorDate(end, end === monthEnd(end.slice(0, 7))) : null, cumulative);
70
+ let reason = !ready(current) ? `本期:${current.reason}` : !ready(previous) ? `去年同期:${previous.reason}` : previous.value <= 0 ? '去年同期为零或负数,不计算增长率' : null;
71
+ const value = reason ? null : (current.value - previous.value) / previous.value * 100;
72
+ if (!reason && !finite(value)) reason = '同比超出可表示范围';
73
+ return { label, unit: '%', value: reason ? null : value, state: reason ? 'pending' : 'available', reason,
74
+ current, previous, range: { start, end }, notes: validDate(start) && validDate(end) ? [`${start} 至 ${end};对比 ${previous.range.start} 至 ${previous.range.end}`] : [] };
75
+ }
76
+ function yearMonths(id, module, filters) {
77
+ const year = Number(filters.month.slice(0, 4)), selected = Number(filters.month.slice(5));
78
+ if (!Number.isInteger(year) || !selected) return [];
79
+ return Array.from({ length: 12 }, (_, index) => {
80
+ const month = `${year}-${String(index + 1).padStart(2, '0')}`;
81
+ const compare = yearComparison(id, module, { ...filters, period: 'month', month });
82
+ const previousMonth = `${year - 1}-${String(index + 1).padStart(2, '0')}`;
83
+ // A partial current month compares the same days in the background bar.
84
+ // Future slots may still show the prior year's complete month.
85
+ const previous = index + 1 <= selected && validDate(compare.current.range?.end) && compare.current.range.end >= `${month}-01`
86
+ ? compare.previous : windowMetric(id, module, `${previousMonth}-01`, monthEnd(previousMonth));
87
+ return { month, current: index + 1 <= selected ? compare.current : pending('净额', '元', '所选月之后尚不展示', 'missing'), previous };
88
+ });
89
+ }
90
+ function previousOpeningDays(module, comparison, currentPoints) {
91
+ const cover = model.payload.coverage.opening, previous = comparison.previous;
92
+ if (!validDate(previous.range.start) || !validDate(previous.range.end) || !validDate(cover?.start) || !validDate(cover?.end)
93
+ || cover.start > previous.range.start || cover.end < previous.range.end) return [];
94
+ const scoped = module.scopedRows || [], byDay = new Map();
95
+ const blocked = scoped.some(row => !validDate(row.date)) || model.payload.modules.opening.metrics?.bottles?.status === 'pending';
96
+ for (const row of scoped) if (row.date >= previous.range.start && row.date <= previous.range.end) {
97
+ if (!byDay.has(row.date)) byDay.set(row.date, []); byDay.get(row.date).push(row.bottles);
98
+ }
99
+ return currentPoints.map(point => {
100
+ const date = priorDate(point.date), values = byDay.get(date) || [];
101
+ const value = !blocked && date.slice(5) === point.date.slice(5) && values.length && values.every(finite) ? sum(values) : null;
102
+ return { date, value: finite(value) ? value : null, state: finite(value) ? 'available' : 'missing', reason: finite(value) ? null : '去年当日缺少有效记录,保留断点' };
103
+ });
104
+ }
105
+ function openingTotal(filters, module, ratio) {
106
+ const label = '总开瓶数(年累计共同期间)', unit = '瓶';
107
+ if (ready(ratio) && finite(ratio.numerator)) return { label, unit, value: ratio.numerator, state: 'available', reason: null, range: { ...ratio.range }, notes: [...ratio.notes] };
108
+ // Keep a known numerator visible when only the denominator is unusable.
109
+ // The window and source binding remain the confirmed cross-source contract.
110
+ const rule = model.payload.decisionContract?.crossTableMetrics, ids = ['opening', 'movement'];
111
+ if (model.payload.decisionContract?.version !== 1 || rule?.status !== 'confirmed' || ids.some(id => !rule.sources?.[id] || rule.sources[id] !== model.payload.sources[id]?.sha256))
112
+ return pending(label, unit, '这两个来源版本的共同期间关系尚未确认');
113
+ if (ids.some(id => model.payload.modules[id].state === 'unavailable')) return pending(label, unit, '缺少来源,无法确认共同截止日', 'missing');
114
+ if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(filters.month || '')) return pending(label, unit, '所选月份无效,无法定位累计期间');
115
+ const covers = ids.map(id => model.payload.coverage?.[id]);
116
+ if (covers.some(cover => !validDate(cover?.start) || !validDate(cover?.end) || cover.start > cover.end)) return pending(label, unit, '来源期间缺失或无效,无法确认共同截止日');
117
+ const p = periodOf(filters), start = `${filters.month.slice(0, 4)}-01-01`, monthEnd = p.mode === 'range' ? p.end : new Date(Date.UTC(Number(filters.month.slice(0, 4)), Number(filters.month.slice(5, 7)), 0)).toISOString().slice(0, 10);
118
+ const end = [monthEnd, ...covers.map(cover => cover.end)].sort()[0], range = { start, end };
119
+ const fail = (reason, state = 'pending') => ({ ...pending(label, unit, reason, state), range });
120
+ if (end < start) return fail('来源截止日尚未覆盖所选年度', 'unavailable');
121
+ const source = model.payload.modules.opening;
122
+ if (covers[0].start.slice(0, 7) > start.slice(0, 7)) return fail('开瓶来源月份未覆盖累计窗口', 'unavailable');
123
+ if (source.records.some(row => !validDate(row.date))) return fail('开瓶来源存在日期缺失或无效,无法完整分期');
124
+ if (source.metrics?.bottles?.status === 'pending') return fail('开瓶瓶数来源规则或口径待确认');
125
+ for (let month = 1; month <= Number(end.slice(5, 7)); month++) {
126
+ const key = `${start.slice(0, 4)}-${String(month).padStart(2, '0')}`;
127
+ if (!source.records.some(row => row.date.slice(0, 7) === key && row.date <= end)) return fail('开瓶计算窗口有月份无来源记录,不能补零', 'unavailable');
128
+ }
129
+ const rows = (module.scopedRows || []).filter(row => row.date >= start && row.date <= end);
130
+ if (!rows.length) return fail('当前组织在共同期间没有开瓶来源记录', 'missing');
131
+ if (rows.some(row => !finite(row.bottles))) return fail('计算窗口存在缺失或不可用开瓶瓶数');
132
+ let value = 0, correction = 0;
133
+ for (const row of rows) { const next = row.bottles - correction, updated = value + next; correction = (updated - value) - next; value = updated; }
134
+ return finite(value) ? { label, unit, value, state: 'available', reason: null, range } : fail('开瓶合计超出可表示范围');
135
+ }
136
+ function regionalMetrics(filters, supplied) {
137
+ const key = keyFor(filters);
138
+ if (regionalCache.has(key)) return regionalCache.get(key);
139
+ const data = supplied || model.select(filters), modules = data.modules;
140
+ const terminal = modules.terminal, totals = terminal.structure?.totals;
141
+ const rate = totals?.effectiveRate;
142
+ const effectiveRate = terminal.state === 'unavailable'
143
+ ? pending('签约有效率', '%', '未接入有效签约来源', 'missing')
144
+ : finite(rate) ? { label: '签约有效率', unit: '%', value: rate * 100, state: 'available', reason: null,
145
+ numerator: totals.effectiveCount, denominator: totals.terminalCount }
146
+ : pending('签约有效率', '%', totals?.terminalCount === 0 ? '当前范围无签约终端,无法计算有效率' : '来源、日期、品系、件数或身份关联不足以完整判定');
147
+ const openingRate = copy(modules.opening.crossMetrics?.find(item => item.key === 'openingMovementRatio') || pending('总开瓶率', '%', '当前来源未确认该跨表指标'));
148
+ const result = { invoice: copy(modules.invoice.main), movement: copy(modules.movement.main), opening: copy(modules.opening.main), effectiveRate,
149
+ signed: copy(terminal.main), effectiveCount: copy(terminal.extra?.find(item => item.label === '有效终端数') || pending('有效终端数', '家', '有效终端尚未完整判定')),
150
+ openingRate, openingTotal: openingTotal(filters, modules.opening, openingRate),
151
+ ratio: copy(modules.movement.crossMetrics?.find(item => item.key === 'invoiceMovementMonthRatio')
152
+ || pending('当月动销 / 开票', '%', '当前来源未确认该跨表指标')),
153
+ // 当月(区间)目标达成率,与总览卡同一取数规则。
154
+ invoiceAttainment: copy(modules.invoice.targets?.attainment || pending('发票目标达成率', '%', '未上传经营目标', 'missing')),
155
+ movementAttainment: copy(modules.movement.targets?.attainment || pending('动销目标达成率', '%', '未上传经营目标', 'missing')) };
156
+ result.invoiceYoY = yearComparison('invoice', modules.invoice, filters);
157
+ result.movementYoY = yearComparison('movement', modules.movement, filters);
158
+ result.openingYoY = ready(result.openingTotal) && result.openingTotal.range
159
+ ? yearComparison('opening', modules.opening, filters, true, result.openingTotal.range)
160
+ : pending('累计开瓶同比', '%', result.openingTotal.reason || '共同期间未确认');
161
+ // Cache only small display metrics, not each selection's full source arrays.
162
+ regionalCache.set(key, result);
163
+ if (regionalCache.size > 96) regionalCache.delete(regionalCache.keys().next().value);
164
+ return result;
165
+ }
166
+ function openingTrend(data, filters) {
167
+ const source = model.payload.modules.opening, scoped = data.modules.opening.scopedRows || data.modules.opening.rows || [];
168
+ const coverage = model.payload.coverage?.opening;
169
+ const result = { openingDaily: [], openingPeriod: '来源期间未提供', openingState: { state: 'missing', reason: '未接入有效开瓶来源' } };
170
+ if (source.state === 'unavailable') return result;
171
+ if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(filters.month || '')) {
172
+ result.openingState = { state: 'pending', reason: '所选月份无效,无法定位单月日度期间' };
173
+ return result;
174
+ }
175
+ if (!validDate(coverage?.start) || !validDate(coverage?.end) || coverage.start > coverage.end) {
176
+ result.openingState = { state: 'pending', reason: '开瓶来源覆盖期间缺失或无效,无法定位日度期间' };
177
+ return result;
178
+ }
179
+ const p = periodOf(filters), monthStart = p.mode === 'range' ? p.start : `${filters.month}-01`;
180
+ const monthEnd = p.mode === 'range' ? p.end : new Date(Date.UTC(Number(filters.month.slice(0, 4)), Number(filters.month.slice(5, 7)), 0)).toISOString().slice(0, 10);
181
+ const start = [monthStart, coverage.start].sort().at(-1), end = [monthEnd, coverage.end].sort()[0];
182
+ if (start > end) {
183
+ result.openingPeriod = '所选期间无来源覆盖';
184
+ result.openingState = { state: 'missing', reason: '所选期间不在开瓶来源覆盖期间内' };
185
+ return result;
186
+ }
187
+ result.openingPeriod = `${start} 至 ${end}`;
188
+ const unknownDate = scoped.some(row => !validDate(row.date));
189
+ const blocked = unknownDate ? '存在缺失或无效日期,无法完整分期' : source.metrics?.bottles?.status === 'pending' ? '开瓶瓶数来源规则或口径待确认' : null;
190
+ const byDay = new Map();
191
+ for (const row of scoped) {
192
+ if (!validDate(row.date) || row.date < start || row.date > end) continue;
193
+ if (!byDay.has(row.date)) byDay.set(row.date, []);
194
+ byDay.get(row.date).push(row.bottles);
195
+ }
196
+ for (let day = start; day <= end; day = new Date(Date.parse(`${day}T00:00:00Z`) + 86400000).toISOString().slice(0, 10)) {
197
+ const values = byDay.get(day) || [];
198
+ let value = null, state = 'pending', reason = blocked;
199
+ if (!blocked && !values.length) { state = 'missing'; reason = '当日无来源记录,不推定为零'; }
200
+ else if (!blocked && values.some(item => !finite(item))) reason = '当日存在缺失或不可用开瓶瓶数';
201
+ else if (!blocked) {
202
+ let sum = 0, correction = 0;
203
+ for (const item of values) { const next = item - correction, updated = sum + next; correction = (updated - sum) - next; sum = updated; }
204
+ if (finite(sum)) { value = sum; state = 'available'; reason = null; } else reason = '当日合计超出可表示范围';
205
+ }
206
+ result.openingDaily.push({ date: day, value, state, reason });
207
+ }
208
+ const points = result.openingDaily;
209
+ result.openingState = blocked ? { state: 'pending', reason: blocked }
210
+ : points.some(item => item.state === 'pending') ? { state: 'pending', reason: '部分日期瓶数不完整,图中保留断点' }
211
+ : points.some(item => item.state === 'available') ? { state: 'available', reason: points.some(item => item.state === 'missing') ? '缺日保留断点,不补零' : null }
212
+ : { state: 'missing', reason: '当前组织与期间内无开瓶来源记录' };
213
+ return result;
214
+ }
215
+ function describe(data, filters = model.defaults) {
216
+ const f = defaultFilters(filters), supplied = data || model.select(f), cacheKey = keyFor(f);
217
+ let byFilters = cache.get(supplied);
218
+ if (byFilters?.has(cacheKey)) return byFilters.get(cacheKey);
219
+ const groupField = ['region', 'office', 'unit'].includes(supplied.groupField) ? supplied.groupField : f.region === 'all' ? 'region' : f.office === 'all' ? 'office' : 'unit';
220
+ const keys = [...new Set((supplied.grouped || []).map(item => item.name))];
221
+ const expectedParts = groupField === 'region' ? 4 : groupField === 'office' ? 5 : 6;
222
+ const parentInvoice = supplied.modules.invoice.main;
223
+ const regional = keys.map(key => {
224
+ const selection = childFilters(f, groupField, key), parts = partsFor(key);
225
+ const metrics = regionalMetrics(selection, keyFor(selection) === cacheKey ? supplied : null);
226
+ const invoiceShare = ready(metrics.invoice) && ready(parentInvoice) && parentInvoice.value > 0 && finite(metrics.invoice.value / parentInvoice.value * 100)
227
+ ? { label: '发票占比', unit: '%', value: metrics.invoice.value / parentInvoice.value * 100, state: 'available', reason: null,
228
+ numerator: metrics.invoice.value, denominator: parentInvoice.value }
229
+ : pending('发票占比', '%', '当前组织或父范围发票净额不完整,或父范围合计不大于零');
230
+ // 该组织(含下级)在哪些来源出现过;总览各视图只列出与本视图来源相关的组织。
231
+ const sources = [...new Set(model.organizations.filter(item => item[groupField] === key).flatMap(item => [...(item.sources || [])]))];
232
+ return { key, name: model.label(key), fullName: fullName(key), sources,
233
+ drillable: f.unit === 'all' && parts.length === expectedParts && parts.every(text) && model.organizations.some(item => item[groupField] === key),
234
+ ...Object.fromEntries(Object.entries(metrics).map(([name, item]) => [name, copy(item)])), invoiceShare };
235
+ });
236
+ const sourceEnds = Object.fromEntries(model.ids.filter(id => model.payload.modules[id].state !== 'unavailable')
237
+ .map(id => [id, validDate(model.payload.coverage?.[id]?.end) ? model.payload.coverage[id].end : null]));
238
+ const ends = [...new Set(Object.values(sourceEnds))];
239
+ const result = { regional, groupField, ...openingTrend(supplied, f),
240
+ openingGrowth: (({ groups, ...total }) => total)(supplied.modules.opening.dayChange || { ...pending('较昨日开瓶', '%', '当前数据未提供日度比较'), precision: 1 }),
241
+ sourceEndLabel: ends.length === 1 && ends[0] ? `截至 ${ends[0]}` : !ends.length || ends.every(value => value === null) ? '来源截止日期未提供' : '各来源截止不同', sourceEnds };
242
+ result.heroes = Object.fromEntries(['invoice', 'movement'].map(id => [id, {
243
+ monthly: yearMonths(id, supplied.modules[id], f), yoy: yearComparison(id, supplied.modules[id], f),
244
+ ytdYoY: yearComparison(id, supplied.modules[id], f, true),
245
+ }]));
246
+ result.openingYoY = yearComparison('opening', supplied.modules.opening, f);
247
+ result.openingPreviousDaily = previousOpeningDays(supplied.modules.opening, result.openingYoY, result.openingDaily);
248
+ if (!byFilters) { byFilters = new Map(); cache.set(supplied, byFilters); }
249
+ byFilters.set(cacheKey, result);
250
+ return result;
251
+ }
252
+ return { describe };
253
+ }