Ver Fonte

fix(s0): 回填标准BOM legacy行 ParentMaterialId/ComponentMaterialId

53031 行 legacy BOM(2026-05-27/28一次性导入只写编码未写FK)按 工厂+租户 限定
1:1 关联 ItemMaster.RecID 回填 FK。仅 UPDATE FK IS NULL、不改编码/主数据/状态、
不覆盖已有FK、不动 demo RecID=1。影响 106062 行(父53031+子53031),回填后
列表父/子名称列正常显示。新增 1.0.203.sql 幂等迁移。bump server 1.0.202->1.0.203。
YY968XX há 4 meses atrás
pai
commit
37e838b938

+ 6 - 3
server/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj

@@ -11,9 +11,9 @@
     <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
     <Copyright>Admin.NET</Copyright>
     <Description>Admin.NET ͨÓÃȨÏÞ¿ª·¢Æ½Ì¨</Description>
-    <AssemblyVersion>1.0.202</AssemblyVersion>
-    <FileVersion>1.0.202</FileVersion>
-    <Version>1.0.202</Version>
+    <AssemblyVersion>1.0.203</AssemblyVersion>
+    <FileVersion>1.0.203</FileVersion>
+    <Version>1.0.203</Version>
   </PropertyGroup>
 
   <ItemGroup>
@@ -184,6 +184,9 @@
     <None Update="UpdateScripts\1.0.197.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="UpdateScripts\1.0.203.sql">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
 
   <ItemGroup>

+ 40 - 0
server/Admin.NET.Web.Entry/UpdateScripts/1.0.203.sql

@@ -0,0 +1,40 @@
+-- =============================================================================
+-- S0-STANDARD-BOM-MATERIAL-FK-BACKFILL-EXECUTION-1
+-- 目的:回填 ProductStructureMaster legacy 行(2026-05-27/28 一次性导入只写父/子项编码、
+--       未写后加的 FK 列)的 ParentMaterialId / ComponentMaterialId,按 工厂 + 租户 限定
+--       1:1 关联 ItemMaster.RecID(ItemMaster 唯一索引 uk_ItemMaster_factory_item=(factory_ref_id,ItemNum)
+--       保证工厂内编码唯一 → 无多匹配)。
+-- 范围:仅 UPDATE FK IS NULL 的行;只写 FK,不改 ParentItem/ComponentItem 编码、不改 ItemMaster、
+--       不改状态字段(IsActive/IsEnabled)、不删行;不覆盖已有非 NULL FK;不更新 demo RecID=1
+--       (其 FK=0 非 NULL,IS NULL 不命中,且 RecID<>1 显式排除)。
+-- 安全:工厂限定(p.FactoryRefId=im.factory_ref_id) + 租户限定(p.tenant_id=im.tenant_id);
+--       阶段 0 只读校验:父/子各 53031 行可回填,多匹配 0,匹配不到 0,跨工厂/跨租户 0。
+-- 幂等:WHERE FK IS NULL → 重跑只命中剩余 NULL,已回填行不再变动。
+-- 回滚(如需,人工执行,非本脚本自动):
+--   UPDATE ProductStructureMaster SET ParentMaterialId=NULL, ComponentMaterialId=NULL
+--   WHERE RecID<>1 AND CreatedAt BETWEEN '2026-05-27' AND '2026-05-28 23:59:59';
+-- =============================================================================
+
+-- 段 1:回填父项 ParentMaterialId
+UPDATE ProductStructureMaster p
+JOIN ItemMaster im
+  ON im.ItemNum = p.ParentItem
+ AND im.factory_ref_id = p.FactoryRefId
+ AND im.tenant_id = p.tenant_id
+SET p.ParentMaterialId = im.RecID
+WHERE p.ParentMaterialId IS NULL
+  AND p.ParentItem IS NOT NULL
+  AND p.ParentItem <> ''
+  AND p.RecID <> 1;
+
+-- 段 2:回填子项 ComponentMaterialId
+UPDATE ProductStructureMaster p
+JOIN ItemMaster im
+  ON im.ItemNum = p.ComponentItem
+ AND im.factory_ref_id = p.FactoryRefId
+ AND im.tenant_id = p.tenant_id
+SET p.ComponentMaterialId = im.RecID
+WHERE p.ComponentMaterialId IS NULL
+  AND p.ComponentItem IS NOT NULL
+  AND p.ComponentItem <> ''
+  AND p.RecID <> 1;