dsh-data-dashboard 0.1.4 → 0.1.6

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.
@@ -1,11 +1,11 @@
1
- // Incremental, range and full updates. Invoice, movement, opening and
2
- // inventory are dated sources (three modes); terminal and banquet are only
1
+ // Incremental, range and full updates. Invoice, movement, opening, inventory,
2
+ // banquet and the platform / distributor sources are dated (three modes); terminal is only
3
3
  // replaced as a whole but go through the same check card. The composed
4
4
  // workbook is written as an ordinary source so validation, inspection,
5
5
  // review decisions and generation keep their existing contracts.
6
6
  import ExcelJS from 'exceljs';
7
7
  import { normalizeHeader } from '../modules.mjs';
8
- import { sourceDate } from '../review-engine.mjs';
8
+ import { sourceDate, monthDay } from '../review-engine.mjs';
9
9
  import { streamSheetRows } from './xlsx-rows.mjs';
10
10
 
11
11
  export const AGGREGATE_VERSION = 2;
@@ -15,11 +15,18 @@ export const FLOW = {
15
15
  movement: { date: '扫码日期', org: ['大区名称', '办事处名称'], amount: '扫码金额', quantity: '扫码件数', bottles: '扫码数量(瓶)' },
16
16
  opening: { date: '抽奖日期', org: ['产品所属-大区', '产品所属-办事处'], city: '开瓶城市', amount: '开瓶金额', bottles: '开瓶瓶数' },
17
17
  // Inventory: compared and replaced by the day of 提交时间, which itself keeps its seconds.
18
+ // 2026-11-27:藏10、吞之乎平台计入发票,分销商动销作参考;宴席改为按执行月份累加。
19
+ // month: 日期列只到月份,按该月 1 日参与比较与替换(同月重复上传即按月整段替换)。
20
+ zang10: { date: '订单归属年月', month: true, org: ['大区', '办事处'], amount: '订单金额(元)', quantity: '购货数量\n(件)' },
21
+ tunzhihu: { date: '业务日期', org: ['大区', '办事处'], amount: '发票金额', quantity: '数量(件)' },
22
+ distributor: { date: '动销日期 (日)', org: ['大区', '办事处'], amount: '总动销金额', quantity: '总动销数量' },
23
+ banquet: { date: '执行时间(月)', month: true, org: ['大区', '办事处'], quantity: '执行场次', bottles: '开瓶数量',
24
+ // 没有执行月份的行不归入任何月份、不计入;场次与开瓶都为 0 的是组织占位,有数值的在核对卡提醒。
25
+ skipUndated: true },
18
26
  inventory: { date: '提交时间', time: true, org: [['大区', '大区名称'], ['办事处', '办事处名称']], dealer: '经销商编码', key: ['经销商编码', ['产品名称', '产品编码'], '提交时间'], overlapAllowed: true },
19
27
  };
20
28
  export const WHOLE = {
21
29
  terminal: { date: '签约日期', agreement: '协议编号', outlet: '网点编号' },
22
- banquet: { events: '执行场次', bottles: '开瓶数量' },
23
30
  };
24
31
  // Export scope check (contract §11.4). Empty list: the board has no such field.
25
32
  export const SCOPE = {
@@ -29,6 +36,9 @@ export const SCOPE = {
29
36
  inventory: { zone: ['战区名称'], region: ['大区', '大区名称'], product: ['产品名称', '产品编码'], productLabel: '产品' },
30
37
  terminal: { zone: ['战区名称'], region: ['大区'], product: ['签约品种'], productLabel: '签约品种' },
31
38
  banquet: { zone: [], region: ['大区'], product: [], productLabel: '产品' },
39
+ zang10: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
40
+ tunzhihu: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
41
+ distributor: { zone: ['战区'], region: ['大区'], product: [], productLabel: '产品' },
32
42
  };
33
43
  export const PRODUCT_RULE = { windowMin: 3, fileMax: 1, minRows: 20, fallbackDays: 30 };
34
44
  export const MODES = ['incremental', 'range', 'full'];
@@ -95,7 +105,7 @@ const keyText = value => value instanceof Date ? value.toISOString() : text(valu
95
105
  export async function streamSource(file, validation, moduleId, onHeader, onRow) {
96
106
  const spec = FLOW[moduleId];
97
107
  const headerRow = validation.headerRow ?? 1;
98
- let headers = null, dateColumn = -1;
108
+ let headers = null, dateColumn = -1, get = null;
99
109
  // date1904 is filled in once workbook.xml has been read, before any row.
100
110
  const date1904Ref = { value: false };
101
111
  const result = await streamSheetRows(file, validation.sheet, async (rowNumber, cells) => {
@@ -104,6 +114,7 @@ export async function streamSource(file, validation, moduleId, onHeader, onRow)
104
114
  headers = cells.map(value => text(plain(value)));
105
115
  while (headers.length && !headers.at(-1)) headers.pop();
106
116
  dateColumn = headers.findIndex(header => normalizeHeader(header) === normalizeHeader(spec.date));
117
+ get = accessor(headers);
107
118
  if (dateColumn < 0) throw new Error(`缺少日期字段:${spec.date}。`);
108
119
  await onHeader({ sheetName: validation.sheet, headers, dateColumn, format: validation.sourceFormat ?? null });
109
120
  return;
@@ -112,10 +123,11 @@ export async function streamSource(file, validation, moduleId, onHeader, onRow)
112
123
  const values = headers.map((_, index) => plain(cells[index] ?? null));
113
124
  if (!values.some(value => text(value) !== '')) return;
114
125
  const raw = values[dateColumn];
115
- const day = sourceDate(raw, date1904Ref.value);
126
+ const day = spec.month ? monthDay(raw, date1904Ref.value) : sourceDate(raw, date1904Ref.value);
127
+ if (!day && spec.skipUndated) { await onRow({ row: rowNumber, values, date: null, skipped: true, valued: [spec.quantity, spec.bottles].filter(Boolean).some(name => number(get(values, name))) }); return; }
116
128
  // Numeric serial dates are rewritten as dates so the 1900/1904 base of the
117
129
  // composed workbook cannot shift them. Inventory keeps the time of day.
118
- if (day && typeof raw === 'number') values[dateColumn] = spec.time ? serialDateTime(raw, date1904Ref.value) : new Date(`${day}T00:00:00Z`);
130
+ if (day && typeof raw === 'number' && !spec.month) values[dateColumn] = spec.time ? serialDateTime(raw, date1904Ref.value) : new Date(`${day}T00:00:00Z`);
119
131
  await onRow({ row: rowNumber, values, date: day });
120
132
  }, date1904Ref);
121
133
  if (!headers) throw new Error('已验证的工作表无法读取。');
@@ -139,11 +151,12 @@ function scopeHas(get, moduleId) {
139
151
 
140
152
  /** Per-day totals, organizations and scope values, small enough to keep beside a source. */
141
153
  export function aggregator(moduleId) {
142
- const spec = FLOW[moduleId], scope = SCOPE[moduleId], byDate = {}, invalidRows = [], zones = new Set(), days = new Map();
154
+ const spec = FLOW[moduleId], scope = SCOPE[moduleId], byDate = {}, invalidRows = [], zones = new Set(), days = new Map(), skipped = { rows: 0, valued: [], bottles: 0 };
143
155
  let get = null, headers = [], rows = 0, format = null;
144
156
  return {
145
157
  header(info) { headers = info.headers; format = info.format ?? null; get = accessor(info.headers); },
146
- row({ row, values, date }) {
158
+ row({ row, values, date, skipped: skip, valued }) {
159
+ if (skip) { skipped.rows++; if (valued) { skipped.valued.push(row); skipped.bottles += spec.bottles ? number(get(values, spec.bottles)) ?? 0 : 0; } return; }
147
160
  rows++;
148
161
  addTo(zones, get(values, scope.zone));
149
162
  if (!date) { invalidRows.push(row); return; }
@@ -171,6 +184,7 @@ export function aggregator(moduleId) {
171
184
  const dates = Object.keys(byDate).sort();
172
185
  return { version: AGGREGATE_VERSION, moduleId, format, rows, start: dates[0] ?? null, end: dates.at(-1) ?? null,
173
186
  invalidDateRows: invalidRows.length, invalidDateSample: invalidRows.slice(0, 20), byDate, headers,
187
+ skippedRows: skipped.rows, skippedValuedRows: skipped.valued.length, skippedValuedSample: skipped.valued.slice(0, 20), skippedBottles: round(skipped.bottles),
174
188
  has: get ? scopeHas(get, moduleId) : { zone: false, region: false, product: false }, zones: sorted(zones), regions: sorted(regions), products: sorted(products) };
175
189
  },
176
190
  };
@@ -251,7 +265,9 @@ export function suggestMode(base, part) {
251
265
  const overlap = Object.keys(part.byDate).filter(day => base.byDate[day]);
252
266
  if (!overlap.length) return { mode: 'incremental', start: part.start, end: part.end, reason: '文件里全部是新日期,直接追加。' };
253
267
  if (part.start <= base.start && part.end >= base.end) return { mode: 'full', start: part.start, end: part.end, reason: '文件覆盖了当前全部日期,整份替换。' };
254
- return { mode: 'range', start: part.start, end: part.end, reason: `与现有数据有 ${overlap.length} 天重叠,按文件日期范围整段替换。` };
268
+ // 月度板块(日期列只到月份)按月计数,同月重传即替换该月。
269
+ const unit = FLOW[part.moduleId]?.month ? '个月' : '天';
270
+ return { mode: 'range', start: part.start, end: part.end, reason: `与现有数据有 ${overlap.length} ${unit}重叠,按文件日期范围整段替换。` };
255
271
  }
256
272
 
257
273
  /** Totals over several (byDate, days) parts; dealers are counted once across parts. */
@@ -275,10 +291,13 @@ const months = days => [...new Set(days.map(day => day.slice(0, 7)))].sort();
275
291
  const FIGURES = {
276
292
  invoice: [['行数', 'rows', 'count'], ['发票净额(万元)', 'amount', 'wan']],
277
293
  movement: [['行数', 'rows', 'count'], ['扫码金额(万元)', 'amount', 'wan'], ['扫码件数', 'quantity', 'count'], ['扫码瓶数', 'bottles', 'count']],
278
- opening: [['行数', 'rows', 'count'], ['开瓶瓶数', 'bottles', 'count'], ['红包金额(万元)', 'amount', 'wan']],
294
+ opening: [['行数', 'rows', 'count'], ['开瓶瓶数', 'bottles', 'count'], ['开瓶金额(万元)', 'amount', 'wan']],
279
295
  inventory: [['盘点记录', 'rows', 'count'], ['经销商', 'dealers', 'count']],
280
296
  terminal: [['协议数', 'agreements', 'count'], ['签约终端', 'outlets', 'count']],
281
- banquet: [['执行场次', 'events', 'count'], ['开瓶瓶数', 'bottles', 'count']],
297
+ banquet: [['执行场次', 'quantity', 'count'], ['开瓶瓶数', 'bottles', 'count']],
298
+ zang10: [['行数', 'rows', 'count'], ['订单金额(万元)', 'amount', 'wan']],
299
+ tunzhihu: [['行数', 'rows', 'count'], ['发票金额(万元)', 'amount', 'wan']],
300
+ distributor: [['行数', 'rows', 'count'], ['动销金额(万元)', 'amount', 'wan']],
282
301
  };
283
302
  const figures = (moduleId, before, after) => FIGURES[moduleId].map(([label, key, unit]) => ({ label, key, unit, before: before ? before[key] ?? null : null, after: after ? after[key] ?? null : null }));
284
303
  const listText = (values, limit = 3) => `${values.slice(0, limit).join('、')}${values.length > limit ? ` 等 ${values.length} 个` : ''}`;
@@ -334,6 +353,7 @@ export function receipt({ moduleId, base, part, mode, start, end, existingByDate
334
353
  const baseBy = base?.byDate ?? {}, partBy = part.byDate;
335
354
  const partDays = Object.keys(partBy).sort(), baseAll = Object.keys(baseBy);
336
355
  if (!part.rows) blocked.push('文件没有数据行。');
356
+ if (part.skippedValuedRows) warnings.push(`${part.skippedValuedRows} 行没有${spec.date}却有数值(开瓶 ${part.skippedBottles} 瓶;Excel 行号:${part.skippedValuedSample.join('、')}${part.skippedValuedRows > part.skippedValuedSample.length ? '等' : ''}),不归入任何月份、不计入。`);
337
357
  if (part.invalidDateRows) blocked.push(`${part.invalidDateRows} 行${spec.date}无效(Excel 行号:${part.invalidDateSample.join('、')}${part.invalidDateRows > part.invalidDateSample.length ? '等' : ''}),请修正后重新导出。`);
338
358
  if (mode !== 'full' && base && (base.format ?? null) !== (part.format ?? null)) blocked.push('文件格式与当前数据不同,只能整份替换。');
339
359
  let window, after, before, disappearing = [], missing = { regions: [], offices: [], cities: [] };
@@ -409,7 +429,6 @@ export function wholeReceipt({ moduleId, base, part, mode = 'full' }) {
409
429
  if (base.end && part.end && part.end < base.end) warnings.push(`签约日期最新只到 ${part.end},早于当前数据的 ${base.end}。`);
410
430
  }
411
431
  }
412
- if (moduleId === 'banquet') notes.push('宴席表没有日期列;新文件的统计期间需要在导入检查中重新确认。');
413
432
  const scope = scopeCheck(moduleId, base, part);
414
433
  blocked.push(...scope.blocked);
415
434
  return {
@@ -1,46 +1,24 @@
1
1
  import { defineModule } from '../../recognition/module-definition.mjs';
2
2
 
3
- // Headers and user-confirmed meanings apply to the inspected simplified source.
4
- // Detailed sources still require review; this contract only validates structure.
3
+ // 宴席执行(固定模板,2026-11-27 用户确认):每行是 执行月份 × 经销商 × 用酒品种,可直接相加。
5
4
  export default defineModule({
6
5
  "id": "banquet",
7
6
  "title": "宴席执行",
8
- "description": "宴席固定期间组织汇总",
7
+ "description": "按月份的宴席执行场次与开瓶数量",
9
8
  "sheetNames": [
10
9
  "报表"
11
10
  ],
12
11
  "notes": [
13
- "当前规则按已核对的简化表建立,后续详细表需重新核对结构与粒度;简化表没有日期列、产品列、终端编号或场次编号,不构造日明细或产品维度。",
14
- "已核对简化表的固定统计期间包含首尾日期;该确认不代表新上传文件的统计期间已验证。",
15
- "简化表已确认售点推荐奖励单位为元、开瓶数量单位为瓶;执行场次为期间实际执行宴席数,零值表示实际为零。奖励数值含义及是否可直接累加仍待确认。",
16
- "已核对简化表中的上下级同名行属于组织占位,汇总时与其他单元一起计入;保留大区、办事处、主任单元的完整路径。新来源的同名层级性质需重新核对。",
17
- "非空行数不代表有效业务行数或执行场次;重复记录、组织汇总行和总计行仍需逐行核对,业务口径确认不等于业务校验已执行。",
18
- "宴席开瓶与消费者开瓶分开统计,不合并两者数量;两份来源是否重叠未作核实。"
12
+ "按“执行时间(月)”归月,跟随月份与日期区间筛选(区间按覆盖到的整月);不随产品筛选。",
13
+ "执行场次、开瓶数量按原值相加;没有执行月份且场次、开瓶均为 0 的行视为组织占位,跳过。",
14
+ "宴席开瓶与消费者开瓶分开统计,不合并两者数量。"
19
15
  ],
20
16
  "fields": [
21
- {
22
- "key": "region",
23
- "header": "大区"
24
- },
25
- {
26
- "key": "office",
27
- "header": "办事处"
28
- },
29
- {
30
- "key": "directorUnit",
31
- "header": "主任单元"
32
- },
33
- {
34
- "key": "outletReward",
35
- "header": "售点推荐奖励"
36
- },
37
- {
38
- "key": "eventCount",
39
- "header": "执行场次"
40
- },
41
- {
42
- "key": "openingQuantity",
43
- "header": "开瓶数量"
44
- }
17
+ { "key": "executionMonth", "header": "执行时间(月)" },
18
+ { "key": "region", "header": "大区" },
19
+ { "key": "office", "header": "办事处" },
20
+ { "key": "directorUnit", "header": "主任单元" },
21
+ { "key": "eventCount", "header": "执行场次" },
22
+ { "key": "openingQuantity", "header": "开瓶数量" }
45
23
  ]
46
24
  });
@@ -0,0 +1,28 @@
1
+ import { defineModule } from '../../recognition/module-definition.mjs';
2
+
3
+ // 分销商动销(高端产品)。只作动销详情里的参考展示,不并入动销合计:
4
+ // 2026-11-27 核对发现它与终端扫码多为同一批交易,且两表没有共同单号,无法逐笔去重。
5
+ export default defineModule({
6
+ "id": "distributor",
7
+ "title": "分销商动销",
8
+ "description": "高端产品分销商出库,动销参考",
9
+ "sheetNames": [
10
+ "分销商动销明细"
11
+ ],
12
+ "notes": [
13
+ "只在终端动销详情中单独展示,不计入动销合计、动销达成或跨表比例(用户 2026-11-27 选择方案 A)。",
14
+ "按“动销日期 (日)”归属日期;“总动销金额”单位元,退货与补录扣减按原负值计入。"
15
+ ],
16
+ "fields": [
17
+ { "key": "date", "header": "动销日期 (日)" },
18
+ { "key": "distributorName", "header": "分销商名称" },
19
+ { "key": "distributorCode", "header": "分销商编码" },
20
+ { "key": "region", "header": "大区" },
21
+ { "key": "office", "header": "办事处" },
22
+ { "key": "directorUnit", "header": "客户主任单元" },
23
+ { "key": "productName", "header": "产品名称" },
24
+ { "key": "documentCode", "header": "单据编码" },
25
+ { "key": "quantity", "header": "总动销数量" },
26
+ { "key": "amount", "header": "总动销金额" }
27
+ ]
28
+ });
@@ -13,7 +13,7 @@ export default defineModule({
13
13
  "按抽奖日期归属开瓶统计期间,用于日期范围和月份筛选。",
14
14
  "组织归属使用产品所属的大区、办事处、主任单元完整路径;开瓶城市不能替代组织归属。",
15
15
  "当前按源表已有汇总数据读取;非空行数不能作为开瓶瓶数或扫码事件数。",
16
- "开瓶金额表示扫码现金红包奖励,源数值单位为元,按原值读取。"
16
+ "开瓶金额为开瓶产品金额(2026-11-27 用户确认,此前误作现金红包),源数值单位为元,按原值读取,界面以万元显示。"
17
17
  ],
18
18
  "fields": [
19
19
  {
@@ -0,0 +1,27 @@
1
+ import { defineModule } from '../../recognition/module-definition.mjs';
2
+
3
+ // 吞之乎平台销售(固定模板,2026-11-27 用户确认)。只读“订单”工作表并计入发票销售;同文件的“动销”页不参与计算。
4
+ export default defineModule({
5
+ "id": "tunzhihu",
6
+ "title": "吞之乎平台销售",
7
+ "description": "吞之乎平台订单,计入发票销售",
8
+ "sheetNames": [
9
+ "订单"
10
+ ],
11
+ "notes": [
12
+ "按“发票金额”计入发票,单位元、含税,正负按原值;单据类型 XS 与 zk3(现金折扣)都计入(用户 2026-11-27 确认)。",
13
+ "按“业务日期”归属日期;“动销”工作表不参与计算,动销以分销商动销与终端扫码为准。",
14
+ "表内只有大区、办事处、主任单元三级组织,按名称挂到其他来源的完整组织路径;挂不上的保留为“上级未提供”。"
15
+ ],
16
+ "fields": [
17
+ { "key": "businessDate", "header": "业务日期" },
18
+ { "key": "orderCode", "header": "订单编号" },
19
+ { "key": "region", "header": "大区" },
20
+ { "key": "office", "header": "办事处" },
21
+ { "key": "directorUnit", "header": "主任单元" },
22
+ { "key": "dealerName", "header": "销管客户名称" },
23
+ { "key": "productName", "header": "产品名称" },
24
+ { "key": "invoiceAmount", "header": "发票金额" },
25
+ { "key": "documentType", "header": "单据类型" }
26
+ ]
27
+ });
@@ -0,0 +1,30 @@
1
+ import { defineModule } from '../../recognition/module-definition.mjs';
2
+
3
+ // 藏10平台销售(固定模板,2026-11-27 用户确认)。计入发票销售,与公司发票分开上传、分开留痕。
4
+ export default defineModule({
5
+ "id": "zang10",
6
+ "title": "藏10平台销售",
7
+ "description": "藏10平台订单,计入发票销售",
8
+ "sheetNames": [
9
+ "工作表1",
10
+ "藏10平台销售"
11
+ ],
12
+ "notes": [
13
+ "按“订单金额(元)”计入发票,单位元、含税,正负都按原值计入;首单标记、账务类型、藏10/藏8 不作筛选,全部计入(用户 2026-11-27 确认)。",
14
+ "按“订单归属年月”归月:订单所在日期在归属月内时用订单所在日期,否则记为归属月 1 日。",
15
+ "表内只有大区、办事处、客户主任单元三级组织,按名称挂到其他来源的完整组织路径;挂不上的保留为“上级未提供”,不丢弃。"
16
+ ],
17
+ "fields": [
18
+ { "key": "attributionMonth", "header": "订单归属年月" },
19
+ { "key": "orderYear", "header": "订单所在年" },
20
+ { "key": "orderMonth", "header": "订单所在月" },
21
+ { "key": "orderDay", "header": "订单所在日" },
22
+ { "key": "orderCode", "header": "订单编号" },
23
+ { "key": "region", "header": "大区" },
24
+ { "key": "office", "header": "办事处" },
25
+ { "key": "directorUnit", "header": "客户主任单元" },
26
+ { "key": "dealerName", "header": "购货经销商名称" },
27
+ { "key": "productName", "header": "购货产品标准名称" },
28
+ { "key": "orderAmount", "header": "订单金额(元)" }
29
+ ]
30
+ });
@@ -5,8 +5,11 @@ import terminal from './modules/terminal/index.mjs';
5
5
  import inventory from './modules/inventory/index.mjs';
6
6
  import banquet from './modules/banquet/index.mjs';
7
7
  import target from './modules/target/index.mjs';
8
+ import zang10 from './modules/zang10/index.mjs';
9
+ import tunzhihu from './modules/tunzhihu/index.mjs';
10
+ import distributor from './modules/distributor/index.mjs';
8
11
 
9
12
  // Shared registration only. Module branches edit their own directory.
10
- export const moduleDefinitions = [invoice, movement, opening, terminal, inventory, banquet, target];
13
+ export const moduleDefinitions = [invoice, movement, opening, terminal, inventory, banquet, target, zang10, tunzhihu, distributor];
11
14
  export const moduleById = new Map(moduleDefinitions.map(module => [module.id, module]));
12
15
  export { normalizeHeader } from './recognition/headers.mjs';
@@ -190,3 +190,31 @@ html.embedded main{padding:20px 28px 24px;max-width:1240px}
190
190
  .status-state.is-muted{color:#9aa7b2}
191
191
  @media(max-width:1100px){.status-row{grid-template-columns:130px minmax(0,1fr) 120px 150px 90px 70px}.check-head{flex-wrap:wrap}.check-file{flex-basis:100%;order:5}}
192
192
  @media(max-width:760px){.status-head{display:none}.status-row{grid-template-columns:1fr 1fr}.status-name,.status-row>span:nth-child(2){grid-column:1/-1}.check-table{grid-template-columns:110px repeat(3,minmax(0,1fr))}.receipt-grid{grid-template-columns:80px minmax(0,1fr)}.receipt-grid .receipt-now{grid-column:2}.update-head{flex-direction:column}}
193
+
194
+ /* Organization mapping status (设计预览画布 ⑪). */
195
+ .org-map{margin:-18px 0 34px;border-radius:12px;font-size:12px;line-height:1.6}
196
+ .org-map-line{display:flex;align-items:center;gap:10px;padding:11px 16px;flex-wrap:wrap}
197
+ .org-map-dot{width:8px;height:8px;border-radius:50%;flex:none}
198
+ .org-map b{font-weight:600;white-space:nowrap}
199
+ .org-map-text{min-width:0;flex:1 1 320px}
200
+ .org-map-time{margin-left:auto;font-size:11px;opacity:.8;white-space:nowrap}
201
+ .org-map-toggle{margin-left:auto;border:0;background:none;color:var(--wine);font:inherit;font-weight:600;cursor:pointer;padding:2px 0;white-space:nowrap}
202
+ .org-map-applied{background:#ecfdf5;color:#065f46}.org-map-applied .org-map-dot{background:#047857}
203
+ .org-map-partial{background:#fffbeb;color:#92400e;border:1px solid #fcd34d}.org-map-partial .org-map-dot{background:#d97706}
204
+ .org-map-invalid{background:#fff1f2;color:#9f1239;border:1px solid #fecdd3}.org-map-invalid .org-map-dot{background:#e11d48}
205
+ .org-map-list{padding:0 16px 12px;overflow-x:auto}
206
+ .org-map-list table{width:100%;border-collapse:collapse;background:#fff;border-radius:8px;overflow:hidden;font-size:12px;min-width:560px}
207
+ .org-map-list th{font-weight:500;font-size:11px;color:#8a7a5a;background:#fff8e1;text-align:left;padding:8px 10px}
208
+ .org-map-list td{padding:8px 10px;border-top:1px solid #fef3c7;color:#4d5e6c}
209
+ .org-map-module{font-weight:600;color:#283640}
210
+ .org-map-pending{color:#a16207}.org-map-rejected{color:#b42318}
211
+ .org-map-note,.org-map-more{margin:8px 0 0;color:#7c6a46;font-size:11.5px}
212
+ .org-chip{font:inherit;font-size:11px;border-radius:999px;padding:3px 9px;white-space:nowrap;border:1px solid transparent;background:#f1f5f9;color:#64748b}
213
+ button.org-chip{cursor:pointer}
214
+ .org-chip-applied{background:#ecfdf5;color:#047857}
215
+ .org-chip-partial{background:#fffbeb;color:#a16207;border-color:#fcd34d;font-weight:600}
216
+ .org-chip-invalid{background:#fff1f2;color:#b42318;font-weight:600}
217
+ .org-map-row td{background:#fffdf5;padding:6px 21px 14px}
218
+ .org-map-row .org-map-list{padding:0}
219
+ .org-map-detail-line{margin:4px 0 8px;font-size:11.5px;color:#92400e}
220
+ @media(max-width:760px){.org-map{margin-top:-10px}.org-map-time,.org-map-toggle{margin-left:0}}
@@ -4,7 +4,7 @@ if (new URLSearchParams(location.search).has('embed')) document.documentElement.
4
4
 
5
5
  const $ = selector => document.querySelector(selector);
6
6
  const rows = new Map();
7
- const preferredOrder = ['invoice', 'movement', 'opening', 'terminal', 'inventory', 'banquet', 'target'];
7
+ const preferredOrder = ['invoice', 'zang10', 'tunzhihu', 'movement', 'distributor', 'opening', 'terminal', 'inventory', 'banquet', 'target'];
8
8
  let state = null;
9
9
  let working = null;
10
10
  let connected = false;
@@ -22,6 +22,9 @@ const iconPaths = {
22
22
  inventory: '<path d="m12 2 9 5v10l-9 5-9-5V7zm-9 5 9 5 9-5M12 12v10M7 4.8l10 5.5v6"/>',
23
23
  banquet: '<path d="m3 21 4-14 10 10zm4-14 10 10M13 3l1 4m4-2 2-2m-2 7 4 1m-1 5 2 1M8 13l3 3"/>',
24
24
  target: '<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1"/>',
25
+ zang10: '<path d="M4 3h16v18l-3-2-3 2-3-2-3 2-4-2zM8 8h8m-8 4h5"/><circle cx="16" cy="14" r="2"/>',
26
+ tunzhihu: '<path d="M4 3h16v18l-3-2-3 2-3-2-3 2-4-2zM8 8h8m-8 4h5"/><path d="M15 12l2 2 3-3"/>',
27
+ distributor: '<path d="M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm10 0a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/>',
25
28
  };
26
29
 
27
30
  function element(tag, className, text) {
@@ -131,11 +134,11 @@ const selectedUpload = module => module?.candidateUpload || module?.activeUpload
131
134
  function rangeText(module, upload) {
132
135
  if (!upload) return '尚未上传';
133
136
  const count = `${Number(upload.validation?.rowCount || 0).toLocaleString('zh-CN')} 行`;
134
- if (module.id === 'banquet') return `无日期列 · ${count}`;
135
137
  if (module.id === 'target') return count;
136
138
  if (!upload.coverage) return '正在计算数据起止日…';
137
139
  if (!upload.coverage.start) return '—';
138
- const prefix = { terminal: '签约日期 ', inventory: '提交时间 ' }[module.id] || '';
140
+ const prefix = { terminal: '签约日期 ', inventory: '提交时间 ', banquet: '执行月份 ', zang10: '归属月份 ' }[module.id] || '';
141
+ if (['banquet', 'zang10'].includes(module.id)) return `${prefix}${upload.coverage.start.slice(0, 7)} ~ ${upload.coverage.end.slice(0, 7)}`;
139
142
  return `${prefix}${upload.coverage.start} ~ ${upload.coverage.end}`;
140
143
  }
141
144
  function versionText(upload) {
@@ -212,6 +215,48 @@ function localLink(href, label, download = false) {
212
215
  return link;
213
216
  }
214
217
 
218
+ // Organization mapping status (设计预览画布 ⑪): the latest generation under the
219
+ // generate panel, and one chip per record that opens the same list.
220
+ const openMappingRows = new Set();
221
+ let mappingBannerOpen = false, mappingBannerSignature = '';
222
+ function mappingList(view) {
223
+ const box = element('div', 'org-map-list');
224
+ const table = element('table'); const head = element('tr');
225
+ for (const label of ['板块', '原路径(大区 / 办事处 / 主任单元)', '行数', '原因']) { const th = element('th', '', label); th.scope = 'col'; head.append(th); }
226
+ const thead = element('thead'); thead.append(head); const tbody = element('tbody');
227
+ for (const item of view.items) {
228
+ const row = element('tr');
229
+ row.append(element('td', 'org-map-module', item.module), element('td', '', item.path), element('td', '', item.rows), element('td', item.rejected ? 'org-map-rejected' : 'org-map-pending', item.reason));
230
+ tbody.append(row);
231
+ }
232
+ table.append(thead, tbody); box.append(table);
233
+ if (view.more) box.append(element('p', 'org-map-more', `另有 ${view.more} 条未列出,完整清单见该版本的 diagnostics.json。`));
234
+ if (view.kind === 'partial') box.append(element('p', 'org-map-note', window.OrgMapping.note));
235
+ return box;
236
+ }
237
+ function renderMappingBanner(generations) {
238
+ const host = $('#org-mapping-status');
239
+ const latest = generations.find(item => item.status === 'completed' && item.mode === 'real');
240
+ const view = latest && window.OrgMapping ? window.OrgMapping.view(latest) : null;
241
+ // Rebuild only on change: the state poll runs every few seconds and the box is aria-live.
242
+ const signature = JSON.stringify([latest?.id, view, mappingBannerOpen]);
243
+ if (signature === mappingBannerSignature) return;
244
+ mappingBannerSignature = signature;
245
+ host.replaceChildren();
246
+ if (!view || view.kind === 'none') { host.hidden = true; return; }
247
+ host.hidden = false; host.className = `org-map org-map-${view.kind}`;
248
+ const line = element('div', 'org-map-line');
249
+ line.append(element('i', 'org-map-dot'), element('b', '', `组织映射:${view.chip.split(' · ')[0]}`), element('span', 'org-map-text', view.line));
250
+ if (view.items.length) {
251
+ const toggle = element('button', 'org-map-toggle', mappingBannerOpen ? '收起清单 ▴' : '查看清单 ▾'); toggle.type = 'button';
252
+ toggle.setAttribute('aria-expanded', String(mappingBannerOpen));
253
+ toggle.addEventListener('click', () => { mappingBannerOpen = !mappingBannerOpen; renderMappingBanner(generations); });
254
+ line.append(toggle);
255
+ } else line.append(element('span', 'org-map-time', `最近生成 ${readableTime(latest.finishedAt || latest.createdAt)}`));
256
+ host.append(line);
257
+ if (mappingBannerOpen && view.items.length) host.append(mappingList(view));
258
+ }
259
+
215
260
  function renderHistory() {
216
261
  const generations = [...(state?.generations || [])].sort((a,b) => String(b.createdAt).localeCompare(String(a.createdAt)));
217
262
  $('#history-count').textContent = `${generations.length} 条记录`;
@@ -222,6 +267,7 @@ function renderHistory() {
222
267
  latestLink.href = localLink(latest.viewUrl, '').href;
223
268
  latestLink.textContent = latest.mode === 'real' ? '打开最新生成的真实数据看板 ↗' : latest.mode === 'demo' ? '打开最近的历史演示看板 ↗' : '打开最近生成的看板 ↗';
224
269
  }
270
+ renderMappingBanner(generations);
225
271
  const signature = JSON.stringify(generations);
226
272
  if (signature === historySignature) return;
227
273
  historySignature = signature;
@@ -235,7 +281,7 @@ function renderHistory() {
235
281
  const wrapper = element('div', 'history-table-wrap');
236
282
  const table = element('table', 'history-table');
237
283
  const thead = element('thead'); const tr = element('tr');
238
- for (const label of ['成品 / 任务', '生成时间', '状态', '操作']) { const th = element('th','',label); th.scope = 'col'; tr.append(th); }
284
+ for (const label of ['成品 / 任务', '生成时间', '状态', '组织映射', '操作']) { const th = element('th','',label); th.scope = 'col'; tr.append(th); }
239
285
  thead.append(tr); const tbody = element('tbody');
240
286
  for (const generation of generations) {
241
287
  const row = element('tr');
@@ -265,7 +311,23 @@ function renderHistory() {
265
311
  actions.append(links);
266
312
  } else if (generation.status === 'failed') actions.append(element('span', 'history-sub history-error', generation.error || '生成未完成,请重试。'));
267
313
  else actions.append(element('span', 'history-sub', generation.stage || '正在准备成品…'));
268
- row.append(name, created, statusCell, actions); tbody.append(row);
314
+ const mappingCell = element('td');
315
+ const mapping = generation.status === 'completed' && generation.mode === 'real' && window.OrgMapping ? window.OrgMapping.view(generation) : null;
316
+ if (mapping) {
317
+ const open = openMappingRows.has(generation.id) && mapping.items.length;
318
+ const chip = element(mapping.items.length ? 'button' : 'span', `org-chip org-chip-${mapping.kind}`, `${mapping.chip}${mapping.items.length ? (open ? ' ▴' : ' ▾') : ''}`);
319
+ if (mapping.line) chip.title = mapping.line;
320
+ if (mapping.items.length) {
321
+ chip.type = 'button'; chip.setAttribute('aria-expanded', String(Boolean(open)));
322
+ chip.addEventListener('click', () => { if (openMappingRows.has(generation.id)) openMappingRows.delete(generation.id); else openMappingRows.add(generation.id); historySignature = null; renderHistory(); });
323
+ }
324
+ mappingCell.append(chip);
325
+ } else mappingCell.append(element('span', 'history-sub', '—'));
326
+ row.append(name, created, statusCell, mappingCell, actions); tbody.append(row);
327
+ if (mapping && mapping.items.length && openMappingRows.has(generation.id)) {
328
+ const detail = element('tr', 'org-map-row'); const cell = element('td'); cell.colSpan = 5;
329
+ cell.append(element('p', 'org-map-detail-line', mapping.line), mappingList(mapping)); detail.append(cell); tbody.append(detail);
330
+ }
269
331
  }
270
332
  table.append(thead, tbody); wrapper.append(table); host.append(wrapper);
271
333
  }
@@ -340,7 +402,7 @@ let generateAfterBatch = false;
340
402
  let lastReceipt = null;
341
403
  const moduleOf = id => state?.modules?.find(module => module.id === id) || null;
342
404
  const moduleTitle = id => moduleOf(id)?.title || '';
343
- const SHORT = { invoice: '发票', movement: '动销', opening: '开瓶', inventory: '库存', terminal: '签约', banquet: '宴席', target: '目标' };
405
+ const SHORT = { invoice: '发票', movement: '动销', opening: '开瓶', inventory: '库存', terminal: '签约', banquet: '宴席', target: '目标', zang10: '藏10', tunzhihu: '吞之乎', distributor: '分销商' };
344
406
  const shortTitle = id => SHORT[id] || moduleTitle(id);
345
407
  const isUpdatable = id => Boolean(moduleOf(id)?.updatable);
346
408
  const modesOf = id => moduleOf(id)?.modes || [];
@@ -455,7 +517,7 @@ function checkCard(item, counts) {
455
517
  head.append(select);
456
518
  } else head.append(element('b', 'check-board', moduleTitle(item.moduleId)));
457
519
  const r = item.receipt;
458
- const dateLabel = { terminal: '签约日期', inventory: '提交时间' }[item.moduleId] || '文件日期';
520
+ const dateLabel = { terminal: '签约日期', inventory: '提交时间', banquet: '执行月份', zang10: '归属月份' }[item.moduleId] || '文件日期';
459
521
  const fileInfo = r?.file?.start ? `${item.file.name} · ${dateLabel} ${dayRange(r.file.start, r.file.end)}` : item.moduleId === 'banquet' && r ? `${item.file.name} · ${countText(r.file.rows)} 行` : item.file.name;
460
522
  const file = element('span', 'check-file', fileInfo); file.title = item.file.name;
461
523
  head.append(file);
@@ -505,7 +567,7 @@ function checkCard(item, counts) {
505
567
  }
506
568
  card.append(range);
507
569
  }
508
- const compact = item.moduleId === 'banquet' && !r.blocked.length && !r.requiresConfirmation;
570
+ const compact = false;
509
571
  if (compact) {
510
572
  const [events, bottles] = r.figures;
511
573
  card.append(element('p', 'check-note', `执行场次 ${countText(events.before)} → ${countText(events.after)} · 开瓶 ${countText(bottles.before)} → ${countText(bottles.after)} 瓶。${(r.notes || []).join('')}`));
@@ -617,8 +679,9 @@ function changeText(item) {
617
679
  const arrow = key => { const value = figure(key); return value ? `${countText(value.before)} → ${countText(value.after)}` : ''; };
618
680
  const auto = isUpdatable(item.moduleId) && modesOf(item.moduleId).length > 1 ? `(${item.modeAuto ? '系统建议' : '手动'})` : '';
619
681
  const what = item.mode === 'range' ? `范围更新 ${dayRange(r.start, r.end)}${auto}` : item.mode === 'incremental' ? `增量追加 ${dayRange(r.file.start, r.file.end)}${auto}` : `整份替换${auto}`;
620
- const core = { invoice: `净额 ${delta('amount', ' 万元')}`, movement: `扫码金额 ${delta('amount', ' 万元')}`, opening: `开瓶 ${delta('bottles', ' 瓶')}`, inventory: `${delta('rows', '')} 条盘点`,
621
- terminal: `协议 ${arrow('agreements')}${r.disappearingAgreements ? `(已确认 ${countText(r.disappearingAgreements)} 份消失)` : ''}`, banquet: `场次 ${arrow('events')}` }[item.moduleId] || '';
682
+ const core = { invoice: `净额 ${delta('amount', ' 万元')}`, movement: `扫码金额 ${delta('amount', ' 万元')}`, opening: `开瓶金额 ${delta('amount', ' 万元')}`, inventory: `${delta('rows', '')} 条盘点`,
683
+ terminal: `协议 ${arrow('agreements')}${r.disappearingAgreements ? `(已确认 ${countText(r.disappearingAgreements)} 份消失)` : ''}`, banquet: `场次 ${delta('quantity', ' 场')}`,
684
+ zang10: `订单金额 ${delta('amount', ' 万元')}`, tunzhihu: `发票金额 ${delta('amount', ' 万元')}`, distributor: `动销金额 ${delta('amount', ' 万元')}` }[item.moduleId] || '';
622
685
  return [what, core].filter(Boolean).join(',');
623
686
  }
624
687
  function renderReceipt() {
@@ -1,7 +1,10 @@
1
1
  :root{font-family:Inter,-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;color:#1f2328;--line:#e5e7eb;--muted:#6b7280;--wine:#aa343e;--wine-dark:#8f2933;--green:#258475}
2
2
  *{box-sizing:border-box}[hidden]{display:none!important}html,body{height:100%}body{margin:0;display:flex;flex-direction:column;background:#fff}
3
3
  button{font:inherit;cursor:pointer}
4
- .bar{display:flex;align-items:center;gap:16px;padding:10px 18px;border-bottom:1px solid var(--line);background:#fff;flex:none}
4
+ /* Title + tabs sit centred; the right column only holds a temporary status hint,
5
+ so it appearing or disappearing never moves the centred group. */
6
+ .bar{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);grid-template-areas:". title meta";align-items:center;column-gap:16px;padding:10px 18px;border-bottom:1px solid var(--line);background:#fff;flex:none}
7
+ .title-group{grid-area:title;display:flex;align-items:center;gap:16px;white-space:nowrap}
5
8
  .bar h1{font-size:15px;font-weight:600;margin:0;white-space:nowrap}
6
9
  .seg{display:flex;background:#f1f2f4;border-radius:9px;padding:3px}
7
10
  .seg button{border:0;background:transparent;padding:5px 14px;border-radius:7px;font-size:13px;color:#4b5563}
@@ -11,8 +14,19 @@ button{font:inherit;cursor:pointer}
11
14
  .seg button[data-view="update"]::before{content:"";display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--wine);margin-right:6px;vertical-align:2px}
12
15
  .seg button[data-view="update"].on{background:var(--wine);color:#fff}
13
16
  .seg button[data-view="update"].on::before{background:#fff}
14
- .meta{margin:0 0 0 auto;font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
15
- .meta b{color:#1f2328;font-weight:500}
17
+ .meta{grid-area:meta;justify-self:end;max-width:100%;margin:0;font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
18
+ .meta.warn{color:#b42318}
19
+ @media (max-width:760px){
20
+ /* Too narrow for a side column: the hint drops to its own centred line under the tabs. */
21
+ .bar{grid-template-columns:minmax(0,1fr);grid-template-areas:none;row-gap:4px}
22
+ .title-group,.meta{grid-area:auto;justify-self:center}
23
+ }
24
+ @media (max-width:480px){
25
+ .bar{padding:8px 10px}
26
+ .title-group{gap:10px}
27
+ .bar h1{font-size:14px}
28
+ .seg button{padding:5px 10px}
29
+ }
16
30
  .btn{border:1px solid #d1d5db;background:#fff;border-radius:8px;padding:6px 12px;font-size:12.5px;color:#1f2328;white-space:nowrap}
17
31
  .btn:hover{background:#f9fafb}
18
32
  .btn-wine{background:var(--wine);border-color:var(--wine);color:#fff}.btn-wine:hover{background:var(--wine-dark)}
@@ -41,3 +55,16 @@ tr.viewing td{background:#fdf6f6}
41
55
  .link{border:0;background:none;color:var(--wine);padding:0 2px;font-size:12.5px}
42
56
  a.link{text-decoration:none}.link:hover{text-decoration:underline}
43
57
  .toast{position:fixed;right:22px;bottom:22px;background:#111827;color:#fff;font-size:13px;padding:10px 14px;border-radius:10px;z-index:9}
58
+ /* Organization mapping column (设计预览画布 ⑪). */
59
+ .chip{font:inherit;font-size:11px;border-radius:999px;padding:2px 8px;white-space:nowrap;border:1px solid transparent;background:#f1f5f9;color:#64748b}
60
+ button.chip{cursor:pointer}
61
+ .chip.applied{background:#ecfdf5;color:#047857}
62
+ .chip.partial{background:#fffbeb;color:#a16207;border-color:#fcd34d;font-weight:600}
63
+ .chip.invalid{background:#fff1f2;color:#b42318;font-weight:600}
64
+ tr.map-row td{background:#fffdf5;padding:6px 10px 14px}
65
+ .map-line{margin:2px 0 8px;font-size:12px;color:#92400e}
66
+ .map-list{font-size:12px;background:#fff;border:1px solid #fde68a;border-radius:8px;border-collapse:separate;border-spacing:0;overflow:hidden}
67
+ .map-list th{background:#fff8e1;color:#8a7a5a}
68
+ .map-list td{border-bottom:1px solid #fef3c7;padding:7px 10px}
69
+ .map-list .mod{font-weight:600}.map-list .pend{color:#a16207}.map-list .rej{color:#b42318}
70
+ .map-note{margin:8px 0 0;font-size:11.5px;color:#7c6a46}
@@ -6,17 +6,20 @@
6
6
  <meta name="color-scheme" content="light" />
7
7
  <title>战区经营看板</title>
8
8
  <link rel="stylesheet" href="/board.css" />
9
+ <script src="/org-mapping.js" defer></script>
9
10
  <script src="/board.js" defer></script>
10
11
  </head>
11
12
  <body>
12
13
  <header class="bar">
13
- <h1>战区经营看板</h1>
14
- <nav class="seg" aria-label="切换视图">
15
- <button type="button" class="on" data-view="board">看板</button>
16
- <button type="button" data-view="update">更新数据</button>
17
- <button type="button" data-view="history">历史版本</button>
18
- </nav>
19
- <p class="meta" id="meta">正在连接本机后台…</p>
14
+ <div class="title-group">
15
+ <h1>战区经营看板</h1>
16
+ <nav class="seg" aria-label="切换视图">
17
+ <button type="button" class="on" data-view="board">看板</button>
18
+ <button type="button" data-view="update">更新数据</button>
19
+ <button type="button" data-view="history">历史版本</button>
20
+ </nav>
21
+ </div>
22
+ <p class="meta" id="meta" role="status" aria-live="polite" hidden></p>
20
23
  </header>
21
24
  <main class="views">
22
25
  <section class="view on" id="view-board" aria-label="最新看板">
@@ -35,8 +38,8 @@
35
38
  <div class="card">
36
39
  <div class="card-head"><h2>历史版本</h2><p>每次生成单独保存;新上传不会改动已生成的版本。点“查看”在看板页打开。</p></div>
37
40
  <table>
38
- <thead><tr><th>生成时间</th><th>数据截至</th><th>使用的资料</th><th>状态</th><th></th></tr></thead>
39
- <tbody id="history"><tr><td colspan="5" class="muted">正在读取…</td></tr></tbody>
41
+ <thead><tr><th>生成时间</th><th>数据截至</th><th>使用的资料</th><th>状态</th><th>组织映射</th><th></th></tr></thead>
42
+ <tbody id="history"><tr><td colspan="6" class="muted">正在读取…</td></tr></tbody>
40
43
  </table>
41
44
  </div>
42
45
  </div>