Просмотр исходного кода

fix(kpi): align S5-S7 T8 KPI writes to dashboard tenant

S5-S6-S7-T8-KPI-TENANT-WRITE-CONTRACT-1

* Write S5/S6/S7 T8 KPI DWD, L1 values, and run logs under dashboard tenant 1300000000001/factory 1 instead of tenant 0.
* Add idempotent migration 1.0.187 to complete the dashboard tenant KPI master with S5_L1_004.
* Preserve existing daily/monthly biz_date semantics and keep NULL metric values as NULL.
* Keep dashboard-page, home-l1, and module-detail tenant reads unchanged.
* Do not copy tenant 0 KPI values or clear historical tenant 0 data.

Smoke:

* dotnet build 0 Error.
* AutoVersionUpdate applied 1.0.187 successfully.
* S5/S6/S7 manual refresh succeeded.
* DWD, L1 day values, and run logs were written under tenant 1300000000001/factory 1.
* Dashboard pages for S5/S6/S7 rendered against the default tenant.
* Representative S1 dashboard regression passed.
YY968XX 3 дней назад
Родитель
Сommit
10062a6ff1

+ 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.186</AssemblyVersion>
-    <FileVersion>1.0.186</FileVersion>
-    <Version>1.0.186</Version>
+    <AssemblyVersion>1.0.187</AssemblyVersion>
+    <FileVersion>1.0.187</FileVersion>
+    <Version>1.0.187</Version>
   </PropertyGroup>
 
   <ItemGroup>
@@ -166,6 +166,9 @@
     <None Update="UpdateScripts\1.0.185.sql">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="UpdateScripts\1.0.187.sql">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
 
   <ItemGroup>

+ 29 - 0
server/Admin.NET.Web.Entry/UpdateScripts/1.0.187.sql

@@ -0,0 +1,29 @@
+-- =============================================================================
+-- 批次:S5-S6-S7-T8-KPI-TENANT-WRITE-CONTRACT-1
+-- 目的:幂等补齐看板读取租户(TenantId=1300000000001 / FactoryId=1)下缺失的
+--      S5_L1_004「品类物料库存周转」KPI master。
+-- 背景:S5/S6/S7 refresh 此前把 KPI 值硬编码写入 tenant=0;本批次改写真实看板租户。
+--      看板读取租户已有 S5/S6/S7 其余 8 个 L1 master,唯独缺 S5_L1_004(仅 tenant=0 有)。
+-- 模板:取自 TenantId=0 的 S5_L1_004 定义,仅改 Id/TenantId/时间戳,业务字段原样复制。
+-- 幂等:目标租户已存在 S5_L1_004 时不插入(@tgt_exists 守卫 + uk_kpi_master_code_tenant 唯一键双保险)。
+-- 边界:不删除、不修改 tenant=0 的 S5_L1_004;不覆盖目标租户已有的其它 8 个 master。
+-- =============================================================================
+
+SET @tgt_exists = (SELECT COUNT(*) FROM ado_smart_ops_kpi_master
+                   WHERE TenantId = 1300000000001 AND MetricCode = 'S5_L1_004');
+SET @new_id     = (SELECT COALESCE(MAX(Id), 0) + 1 FROM ado_smart_ops_kpi_master);
+
+INSERT INTO ado_smart_ops_kpi_master
+  (Id, MetricCode, ModuleCode, MetricLevel, ParentId, MetricName, Description, Formula,
+   CalcRule, DataSource, StatFrequency, Department, DopFields, Unit, Direction,
+   IsHomePage, SortNo, Remark, IsEnabled, TenantId, CreatedAt, UpdatedAt,
+   YellowThreshold, RedThreshold, FormulaExpr, FormulaPreview, FormulaRefs)
+SELECT
+  @new_id, MetricCode, ModuleCode, MetricLevel, ParentId, MetricName, Description, Formula,
+  CalcRule, DataSource, StatFrequency, Department, DopFields, Unit, Direction,
+  IsHomePage, SortNo, Remark, IsEnabled,
+  1300000000001 AS TenantId, NOW() AS CreatedAt, NOW() AS UpdatedAt,
+  YellowThreshold, RedThreshold, FormulaExpr, FormulaPreview, FormulaRefs
+FROM ado_smart_ops_kpi_master
+WHERE TenantId = 0 AND ModuleCode = 'S5' AND MetricCode = 'S5_L1_004'
+  AND @tgt_exists = 0;

+ 6 - 6
server/Plugins/Admin.NET.Plugin.AiDOP/FinishedWarehouse/S7MdpSyncTransformService.cs

@@ -128,7 +128,7 @@ select noid as noid,
 INSERT INTO dwd_t8_order_shipment_cycle
   (tenant_id, factory_id, biz_date, source_ztid, order_no, cycle_days, batch_id, create_time)
 VALUES
-  (0, 1, @bizDate, @ztid, @orderNo, @cycleDays, @batchId, @now)
+  (1300000000001, 1, @bizDate, @ztid, @orderNo, @cycleDays, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   cycle_days=VALUES(cycle_days),
   batch_id=VALUES(batch_id), update_time=@now",
@@ -195,7 +195,7 @@ INSERT INTO dwd_t8_order_shipment_fulfillment
   (tenant_id, factory_id, biz_date, source_ztid, order_no,
    total_rows, in_window_rows, fulfillment_rate, batch_id, create_time)
 VALUES
-  (0, 1, @bizDate, @ztid, @orderNo,
+  (1300000000001, 1, @bizDate, @ztid, @orderNo,
    @total, @inWindow, @rate, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   total_rows=VALUES(total_rows), in_window_rows=VALUES(in_window_rows),
@@ -273,7 +273,7 @@ INSERT INTO dwd_t8_finished_warehouse_efficiency
   (tenant_id, factory_id, biz_month, source_ztid, period_start, period_end,
    shipment_qty, warehouse_headcount, efficiency, denominator_status, batch_id, create_time)
 VALUES
-  (0, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
+  (1300000000001, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
    @shipmentQty, @headcount, @efficiency, @denomStatus, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   period_start=VALUES(period_start), period_end=VALUES(period_end),
@@ -312,7 +312,7 @@ ON DUPLICATE KEY UPDATE
         // FIX-2:截断时分秒(月度 KPI 入参可能为 YYYY-MM-DD 23:59:59),保证 SELECT WHERE biz_date=@BizDate 与 DB date 列匹配,避免重复 INSERT。
         bizDate = bizDate.Date;
         var existingId = await _db.Ado.GetLongAsync(
-            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=0 AND factory_id=1 " +
+            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=1300000000001 AND factory_id=1 " +
             "AND module_code=@ModuleCode AND metric_code=@MetricCode AND biz_date=@BizDate AND is_deleted=0 " +
             "ORDER BY id LIMIT 1), 0)",
             new List<SugarParameter>
@@ -340,7 +340,7 @@ INSERT INTO ado_s9_kpi_value_l1_day
    create_time, update_time, is_deleted, is_active,
    module_code, metric_code, metric_value, calc_time)
 VALUES
-  (@Id, 0, NULL, NULL, 1, NULL, @BizDate,
+  (@Id, 1300000000001, NULL, NULL, 1, NULL, @BizDate,
    @Now, @Now, 0, 1,
    @ModuleCode, @MetricCode, @MetricValue, @Now)",
             new SugarParameter("@Id", nextId),
@@ -357,7 +357,7 @@ VALUES
 INSERT INTO mdp_transform_run_log
   (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time, stage_rows, standard_rows, dwd_rows, create_time, update_time)
 VALUES
-  (0, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
+  (1300000000001, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
             new SugarParameter("@JobCode", JobCode),
             new SugarParameter("@JobName", JobName),
             new SugarParameter("@TriggerType", triggerType),

+ 5 - 5
server/Plugins/Admin.NET.Plugin.AiDOP/Manufacturing/S6MdpSyncTransformService.cs

@@ -119,7 +119,7 @@ INSERT INTO dwd_t8_work_order_mfg_fulfillment
   (tenant_id, factory_id, biz_date, source_ztid, order_no, task_no, item_code,
    plan_qty, done_qty_in_window, fulfillment_rate, batch_id, create_time)
 VALUES
-  (0, 1, @bizDate, @ztid, @orderNo, @taskNo, @itemCode,
+  (1300000000001, 1, @bizDate, @ztid, @orderNo, @taskNo, @itemCode,
    @planQty, @doneQty, @rate, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   plan_qty=VALUES(plan_qty), done_qty_in_window=VALUES(done_qty_in_window),
@@ -197,7 +197,7 @@ INSERT INTO dwd_t8_work_order_mfg_efficiency
   (tenant_id, factory_id, biz_month, source_ztid, period_start, period_end,
    done_count, production_headcount, efficiency, denominator_status, batch_id, create_time)
 VALUES
-  (0, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
+  (1300000000001, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
    @doneCount, @headcount, @efficiency, @denomStatus, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   period_start=VALUES(period_start), period_end=VALUES(period_end),
@@ -236,7 +236,7 @@ ON DUPLICATE KEY UPDATE
         // FIX-2:截断时分秒(月度 KPI 入参可能为 YYYY-MM-DD 23:59:59),保证 SELECT WHERE biz_date=@BizDate 与 DB date 列匹配,避免重复 INSERT。
         bizDate = bizDate.Date;
         var existingId = await _db.Ado.GetLongAsync(
-            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=0 AND factory_id=1 " +
+            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=1300000000001 AND factory_id=1 " +
             "AND module_code=@ModuleCode AND metric_code=@MetricCode AND biz_date=@BizDate AND is_deleted=0 " +
             "ORDER BY id LIMIT 1), 0)",
             new List<SugarParameter>
@@ -264,7 +264,7 @@ INSERT INTO ado_s9_kpi_value_l1_day
    create_time, update_time, is_deleted, is_active,
    module_code, metric_code, metric_value, calc_time)
 VALUES
-  (@Id, 0, NULL, NULL, 1, NULL, @BizDate,
+  (@Id, 1300000000001, NULL, NULL, 1, NULL, @BizDate,
    @Now, @Now, 0, 1,
    @ModuleCode, @MetricCode, @MetricValue, @Now)",
             new SugarParameter("@Id", nextId),
@@ -281,7 +281,7 @@ VALUES
 INSERT INTO mdp_transform_run_log
   (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time, stage_rows, standard_rows, dwd_rows, create_time, update_time)
 VALUES
-  (0, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
+  (1300000000001, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
             new SugarParameter("@JobCode", JobCode),
             new SugarParameter("@JobName", JobName),
             new SugarParameter("@TriggerType", triggerType),

+ 7 - 7
server/Plugins/Admin.NET.Plugin.AiDOP/MaterialWarehouse/S5MdpSyncTransformService.cs

@@ -143,7 +143,7 @@ select b.code as code, min(a.shtime) as shtime
 INSERT INTO dwd_t8_material_online_cycle
   (tenant_id, factory_id, biz_date, source_ztid, item_code, online_date, receipt_date, cycle_days, batch_id, create_time)
 VALUES
-  (0, 1, @bizDate, @ztid, @itemCode, @online, @receipt, @cycleDays, @batchId, @now)
+  (1300000000001, 1, @bizDate, @ztid, @itemCode, @online, @receipt, @cycleDays, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   online_date=VALUES(online_date), receipt_date=VALUES(receipt_date),
   cycle_days=VALUES(cycle_days), batch_id=VALUES(batch_id), update_time=@now",
@@ -220,7 +220,7 @@ INSERT INTO dwd_t8_material_online_fulfillment
   (tenant_id, factory_id, biz_date, source_ztid, work_order_no,
    before_kgdate_rows, total_rows, fulfillment_rate, batch_id, create_time)
 VALUES
-  (0, 1, @bizDate, @ztid, @workOrderNo, @beforeKg, @total, @rate, @batchId, @now)
+  (1300000000001, 1, @bizDate, @ztid, @workOrderNo, @beforeKg, @total, @rate, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   before_kgdate_rows=VALUES(before_kgdate_rows),
   total_rows=VALUES(total_rows),
@@ -301,7 +301,7 @@ INSERT INTO dwd_t8_material_warehouse_efficiency
   (tenant_id, factory_id, biz_month, source_ztid, period_start, period_end,
    online_qty, warehouse_headcount, efficiency, denominator_status, batch_id, create_time)
 VALUES
-  (0, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
+  (1300000000001, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
    @onlineQty, @headcount, @efficiency, @denomStatus, @batchId, @now)
 ON DUPLICATE KEY UPDATE
   period_start=VALUES(period_start), period_end=VALUES(period_end),
@@ -365,7 +365,7 @@ INSERT INTO dwd_t8_material_inventory_turnover
    warehouse_code, warehouse_name, item_code, item_name, category_code, category_name,
    avg_inventory_value, monthly_outbound_cost, turnover_days, batch_id, create_time)
 VALUES
-  (0, 1, @bizMonth, @ztid, @startYm, @endYm,
+  (1300000000001, 1, @bizMonth, @ztid, @startYm, @endYm,
    @ckcode, @ckname, @itemCode, @itemName, @pcode, @pname,
    @je3, @je2, @turnoverDays, @batchId, @now)
 ON DUPLICATE KEY UPDATE
@@ -422,7 +422,7 @@ ON DUPLICATE KEY UPDATE
         // FIX-2:截断时分秒(月度 KPI 入参可能为 YYYY-MM-DD 23:59:59),保证 SELECT WHERE biz_date=@BizDate 与 DB date 列匹配,避免重复 INSERT。
         bizDate = bizDate.Date;
         var existingId = await _db.Ado.GetLongAsync(
-            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=0 AND factory_id=1 " +
+            "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=1300000000001 AND factory_id=1 " +
             "AND module_code=@ModuleCode AND metric_code=@MetricCode AND biz_date=@BizDate AND is_deleted=0 " +
             "ORDER BY id LIMIT 1), 0)",
             new List<SugarParameter>
@@ -450,7 +450,7 @@ INSERT INTO ado_s9_kpi_value_l1_day
    create_time, update_time, is_deleted, is_active,
    module_code, metric_code, metric_value, calc_time)
 VALUES
-  (@Id, 0, NULL, NULL, 1, NULL, @BizDate,
+  (@Id, 1300000000001, NULL, NULL, 1, NULL, @BizDate,
    @Now, @Now, 0, 1,
    @ModuleCode, @MetricCode, @MetricValue, @Now)",
             new SugarParameter("@Id", nextId),
@@ -467,7 +467,7 @@ VALUES
 INSERT INTO mdp_transform_run_log
   (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time, stage_rows, standard_rows, dwd_rows, create_time, update_time)
 VALUES
-  (0, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
+  (1300000000001, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
             new SugarParameter("@JobCode", JobCode),
             new SugarParameter("@JobName", JobName),
             new SugarParameter("@TriggerType", triggerType),