Ver Fonte

fix: include scope in data-lake rowKey

company rows and chain rows both have empty shopId, so the chain
upsert was overwriting the company rows on every sync (sync log
showed 连锁 added=0 updated=30 while 全公司 rows vanished).
KenZ1117 há 2 semanas atrás
pai
commit
e3f5770e73
1 ficheiros alterados com 3 adições e 2 exclusões
  1. 3 2
      reports-store.js

+ 3 - 2
reports-store.js

@@ -115,10 +115,11 @@ function saveRows(entityKey, rows) {
 }
 
 function rowKey(row) {
-  return `${row.date}|${row.shopId == null ? '' : row.shopId}`;
+  // scope 必须参与键:全公司行与连锁行的 shopId 都为空串,缺 scope 会互相覆盖
+  return `${row.date}|${row.scope || ''}|${row.shopId == null ? '' : row.shopId}`;
 }
 
-/** 合并写入:按 date|shopId upsert,浅字段覆盖(raw 整体替换) */
+/** 合并写入:按 date|scope|shopId upsert,浅字段覆盖(raw 整体替换) */
 function upsertRows(entityKey, incoming) {
   if (!Array.isArray(incoming) || !incoming.length) return { added: 0, updated: 0, total: 0 };
   const rows = loadRows(entityKey);