dsh-data-dashboard 0.1.7 → 0.1.8
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.
|
@@ -49,6 +49,17 @@ export const isUpdatable = id => isFlowModule(id) || isWholeModule(id);
|
|
|
49
49
|
export const modesFor = id => isFlowModule(id) ? MODES : isWholeModule(id) ? ['full'] : [];
|
|
50
50
|
|
|
51
51
|
const text = value => value === null || value === undefined ? '' : String(value).trim();
|
|
52
|
+
/** The current source no longer has the date column of the current template (the template was updated). */
|
|
53
|
+
export class TemplateMismatchError extends Error {
|
|
54
|
+
constructor(message) { super(message); this.code = 'TEMPLATE_MISMATCH'; }
|
|
55
|
+
}
|
|
56
|
+
/** Stand-in for a current source saved under an older template: it can only be replaced as a whole. */
|
|
57
|
+
export function outdatedBase(moduleId, reason) {
|
|
58
|
+
return { version: AGGREGATE_VERSION, moduleId, outdated: true, reason: reason || `当前有效版本缺少${FLOW[moduleId]?.date ?? '必需'}列,是旧模板文件。` };
|
|
59
|
+
}
|
|
60
|
+
/** A cached aggregate built from a file without the current date column is stale as well. */
|
|
61
|
+
export const aggregateMatchesTemplate = (moduleId, aggregate) => !FLOW[moduleId] || !aggregate?.headers
|
|
62
|
+
|| aggregate.headers.some(header => normalizeHeader(header) === normalizeHeader(FLOW[moduleId].date));
|
|
52
63
|
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
53
64
|
export const validDay = value => typeof value === 'string' && DAY.test(value) && sourceDate(value) === value;
|
|
54
65
|
const shiftDay = (day, offset) => { const d = new Date(`${day}T00:00:00Z`); d.setUTCDate(d.getUTCDate() + offset); return d.toISOString().slice(0, 10); };
|
|
@@ -115,7 +126,7 @@ export async function streamSource(file, validation, moduleId, onHeader, onRow)
|
|
|
115
126
|
while (headers.length && !headers.at(-1)) headers.pop();
|
|
116
127
|
dateColumn = headers.findIndex(header => normalizeHeader(header) === normalizeHeader(spec.date));
|
|
117
128
|
get = accessor(headers);
|
|
118
|
-
if (dateColumn < 0) throw new
|
|
129
|
+
if (dateColumn < 0) throw new TemplateMismatchError(`缺少日期字段:${spec.date}。`);
|
|
119
130
|
await onHeader({ sheetName: validation.sheet, headers, dateColumn, format: validation.sourceFormat ?? null });
|
|
120
131
|
return;
|
|
121
132
|
}
|
|
@@ -260,6 +271,7 @@ export const existingInvoiceRows = (base, part) => existingRows('invoice', base,
|
|
|
260
271
|
|
|
261
272
|
export function suggestMode(base, part) {
|
|
262
273
|
if (part?.whole) return { mode: 'full', start: part.start, end: part.end, reason: '这个板块只支持整份替换。' };
|
|
274
|
+
if (base?.outdated) return { mode: 'full', start: part.start, end: part.end, reason: '当前有效版本是旧模板文件,只能用新模板整份替换。' };
|
|
263
275
|
if (!base || !base.start) return { mode: 'full', start: part.start, end: part.end, reason: '当前没有有效数据,用这份文件建立基线。' };
|
|
264
276
|
if ((base.format ?? null) !== (part.format ?? null)) return { mode: 'full', start: part.start, end: part.end, reason: '文件格式与当前数据不同,只能整份替换。' };
|
|
265
277
|
const overlap = Object.keys(part.byDate).filter(day => base.byDate[day]);
|
|
@@ -350,6 +362,12 @@ export function receipt({ moduleId, base, part, mode, start, end, existingByDate
|
|
|
350
362
|
if (isWholeModule(moduleId)) return wholeReceipt({ moduleId, base, part, mode });
|
|
351
363
|
if (!MODES.includes(mode)) throw new Error('更新方式无效。');
|
|
352
364
|
const spec = FLOW[moduleId], blocked = [], warnings = [];
|
|
365
|
+
// 模板更新后,旧文件不再参与比对:只允许整份替换,按“当前没有可比数据”处理。
|
|
366
|
+
if (base?.outdated) {
|
|
367
|
+
if (mode !== 'full') blocked.push('当前有效版本是旧模板文件,不能与新文件合并,请改用整份替换。');
|
|
368
|
+
warnings.push(`${base.reason.replace(/。$/, '')}。整份替换后旧模板数据会被新文件取代,不做逐月比对。`);
|
|
369
|
+
base = null; existingByDate = {};
|
|
370
|
+
}
|
|
353
371
|
const baseBy = base?.byDate ?? {}, partBy = part.byDate;
|
|
354
372
|
const partDays = Object.keys(partBy).sort(), baseAll = Object.keys(baseBy);
|
|
355
373
|
if (!part.rows) blocked.push('文件没有数据行。');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readSource, aggregate, aggregator, aggregateFile, keyMatcher, receipt, streamSource, composeFile, summarizeFile, isWholeModule } from './flow.mjs';
|
|
1
|
+
import { readSource, aggregate, aggregator, aggregateFile, keyMatcher, receipt, streamSource, composeFile, summarizeFile, isWholeModule, outdatedBase, aggregateMatchesTemplate } from './flow.mjs';
|
|
2
2
|
import { streamSheetRows } from './xlsx-rows.mjs';
|
|
3
3
|
import { sourceDate } from '../review-engine.mjs';
|
|
4
4
|
import { normalizeHeader } from '../modules.mjs';
|
|
@@ -33,11 +33,18 @@ export async function runFlowJob(job) {
|
|
|
33
33
|
const part = await readSource(job.partFile, job.partValidation, job.moduleId);
|
|
34
34
|
const partAggregate = aggregate(part, job.moduleId);
|
|
35
35
|
if (!job.baseFile) return { part: partAggregate, base: null, existingByDate: {} };
|
|
36
|
+
if (job.baseAggregate && !aggregateMatchesTemplate(job.moduleId, job.baseAggregate)) return { part: partAggregate, base: outdatedBase(job.moduleId), existingByDate: {} };
|
|
36
37
|
const needAggregate = !job.baseAggregate, matcher = keyMatcher(job.moduleId, part);
|
|
37
38
|
if (needAggregate || matcher) {
|
|
38
39
|
const acc = needAggregate ? aggregator(job.moduleId) : null;
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
try {
|
|
41
|
+
await streamSource(job.baseFile, job.baseValidation, job.moduleId,
|
|
42
|
+
info => { acc?.header(info); matcher?.header(info); }, row => { acc?.row(row); matcher?.row(row); });
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// 模板已更新:旧文件缺少当前日期列,不能比对,只能整份替换。
|
|
45
|
+
if (error?.code === 'TEMPLATE_MISMATCH') return { part: partAggregate, base: outdatedBase(job.moduleId), existingByDate: {} };
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
41
48
|
return { part: partAggregate, base: acc ? acc.result() : job.baseAggregate, existingByDate: matcher ? matcher.result() : {} };
|
|
42
49
|
}
|
|
43
50
|
return { part: partAggregate, base: job.baseAggregate, existingByDate: {} };
|
package/backend/server.mjs
CHANGED
|
@@ -320,7 +320,7 @@ export async function createAdminServer({ port = 4180, dataDir = DEFAULT_DATA_DI
|
|
|
320
320
|
busy.stage = '正在对比现有数据';
|
|
321
321
|
const analysis = await workerJob({ kind: 'analyze', moduleId, partFile: file, partValidation: validation,
|
|
322
322
|
baseFile: base ? resolve(dataDir, 'uploads', base.id, 'source.xlsx') : null, baseValidation: base?.validation, baseAggregate: cached }, () => {}, log);
|
|
323
|
-
if (base && !cached && analysis.base && isFlowModule(moduleId)) await atomicJson(resolve(dataDir, 'uploads', base.id, 'aggregate.json'), { version: AGGREGATE_VERSION, sha256: base.sha256, aggregate: analysis.base }).catch(log);
|
|
323
|
+
if (base && !cached && analysis.base && !analysis.base.outdated && isFlowModule(moduleId)) await atomicJson(resolve(dataDir, 'uploads', base.id, 'aggregate.json'), { version: AGGREGATE_VERSION, sha256: base.sha256, aggregate: analysis.base }).catch(log);
|
|
324
324
|
const suggestion = suggestMode(analysis.base, analysis.part);
|
|
325
325
|
const meta = { id, moduleId, filename, ...info, validation, createdAt: new Date().toISOString(), baseUploadId: base?.id ?? null, base: analysis.base, part: analysis.part, existingByDate: analysis.existingByDate, suggestion };
|
|
326
326
|
await atomicJson(resolve(directory, 'meta.json'), meta);
|
package/build-manifest.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-data-dashboard",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"builtAt": "2026-
|
|
5
|
-
"sourceCommit": "
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"builtAt": "2026-12-02T13:05:54.057Z",
|
|
5
|
+
"sourceCommit": "b2c125e24713f0618b7a5efe040d82c36e45d268",
|
|
6
6
|
"sourceDirty": false,
|
|
7
7
|
"files": {
|
|
8
8
|
"README.md": "ae7f24665cd16f9d729d719ef2335c328d14e0c8b791e40c5c39c8a61d8783d6",
|
|
9
9
|
"assets/theater-board.svg": "896b0573d86494e4c31b11bde56cecd517b509bd3bf940a24742ac565f164afc",
|
|
10
|
-
"backend/incremental/flow.mjs": "
|
|
11
|
-
"backend/incremental/jobs.mjs": "
|
|
10
|
+
"backend/incremental/flow.mjs": "6853f6bd3ef6ec175c02c568484163d4dded0c436279b31b072bac0fb1881e29",
|
|
11
|
+
"backend/incremental/jobs.mjs": "7ea5e7f45943bd66d66533ddc8d16ab02239b772aaab5f0d1827d6baa782e0a8",
|
|
12
12
|
"backend/incremental/xlsx-rows.mjs": "4d840c2401bb0e6157d36f3a0df4e7750bee3209ea6ddb40b70fd9d7cd4e2447",
|
|
13
13
|
"backend/job-worker.mjs": "a9cfa26a77d72926e8485f274a441ae2f919555aee31288776d4e0abc5de9c50",
|
|
14
14
|
"backend/modules.mjs": "80f0d3f0639ab15a6745d5be275f22d42d364173f4216f49e94d8e2cf1862919",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"backend/recognition/upload-limits.mjs": "8fde2d6c62ab7f0bfa1a945d34efc462087b895fd25e92cf5d5c34c97d738ace",
|
|
58
58
|
"backend/review-engine.mjs": "852373424d48d7d35d75e35c0baaecc9fea7484565a58be96f366db517395309",
|
|
59
59
|
"backend/review-service.mjs": "c9d4526b952e07c7c9a5d9c5ef9ccaf6bd108527057dd605e24107312d1bb02f",
|
|
60
|
-
"backend/server.mjs": "
|
|
60
|
+
"backend/server.mjs": "41fd740bde7d16962a8835c544e6e11a0c92d59f546434176d19db98aa545ef4",
|
|
61
61
|
"backend/store.mjs": "1e74edc99a577fa9a72a43722a35b6cee7c0c5582b49a5786bbc676412602f0b",
|
|
62
62
|
"backend/target-template.mjs": "fa33f13b8ee56da7a2bc44c1c474d879817e270bddad03350799143f7fe78b43",
|
|
63
63
|
"backend/validate-workbook.mjs": "2f86c034e4af578b7971486e81e86912f69a086c877c516223350b52931cc377",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"lib/tools.mjs": "dd920e4b586e726081b2e4e268223f708c2dd202b3f5217fcd7053405f75861b",
|
|
78
78
|
"locale/en.json": "e7a5b39324d6162e7d29957fbc7a0f4bde9c588de2000c874f058df5520f472c",
|
|
79
79
|
"locale/zh.json": "dd29dcecb35aa6e95a295af228fd39f833c1f492cc5ca41567bb6945ab134510",
|
|
80
|
-
"package-lock.json": "
|
|
81
|
-
"package.json": "
|
|
80
|
+
"package-lock.json": "2db746b5dcb9552d2a39ea5a41bec31159941ecc269748d27f4ded043b7aba87",
|
|
81
|
+
"package.json": "a469bcc2b25ebc44d86a7b73d0d8711fdeda40831e3d15c7997673ed4d52df03"
|
|
82
82
|
}
|
|
83
83
|
}
|