|
|
@@ -41,6 +41,8 @@ public class S5MdpSyncTransformService : ITransient
|
|
|
{
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
option ??= S5MdpRefreshOption.Default();
|
|
|
+ // 目标租户由 T8 账套(ztid)映射决定,替代此前写死的 1300000000001(禁止固定默认/兜底)
|
|
|
+ option.TenantId = AidopSourceTenantMap.ResolveTenantId(option.SourceZtid, option.TenantId);
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
var batchId = $"S5_MDP_FULL_{now:yyyyMMddHHmmss}";
|
|
|
@@ -143,10 +145,11 @@ 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
|
|
|
- (1300000000001, 1, @bizDate, @ztid, @itemCode, @online, @receipt, @cycleDays, @batchId, @now)
|
|
|
+ (@TenantId, 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",
|
|
|
+ new SugarParameter("@TenantId", option.TenantId),
|
|
|
new SugarParameter("@bizDate", option.BizDate),
|
|
|
new SugarParameter("@ztid", option.SourceZtid),
|
|
|
new SugarParameter("@itemCode", code),
|
|
|
@@ -162,7 +165,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
decimal? metricValue = cycleDaysList.Count > 0
|
|
|
? (decimal)cycleDaysList.Average()
|
|
|
: null;
|
|
|
- sub.KpiRows = await UpsertKpiValueAsync("S5_L1_001", option.BizDate, metricValue, now);
|
|
|
+ sub.KpiRows = await UpsertKpiValueAsync("S5_L1_001", option.TenantId, option.BizDate, metricValue, now);
|
|
|
sub.DenominatorStatus = cycleDaysList.Count > 0 ? "OK" : "NO_NUMERATOR";
|
|
|
return sub;
|
|
|
}
|
|
|
@@ -220,12 +223,13 @@ 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
|
|
|
- (1300000000001, 1, @bizDate, @ztid, @workOrderNo, @beforeKg, @total, @rate, @batchId, @now)
|
|
|
+ (@TenantId, 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),
|
|
|
fulfillment_rate=VALUES(fulfillment_rate),
|
|
|
batch_id=VALUES(batch_id), update_time=@now",
|
|
|
+ new SugarParameter("@TenantId", option.TenantId),
|
|
|
new SugarParameter("@bizDate", option.BizDate),
|
|
|
new SugarParameter("@ztid", option.SourceZtid),
|
|
|
new SugarParameter("@workOrderNo", d.noid),
|
|
|
@@ -240,7 +244,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
decimal? metricValue = rateList.Count > 0
|
|
|
? Math.Round(rateList.Average() * 100m, 4) // 百分号
|
|
|
: null;
|
|
|
- sub.KpiRows = await UpsertKpiValueAsync("S5_L1_002", option.BizDate, metricValue, now);
|
|
|
+ sub.KpiRows = await UpsertKpiValueAsync("S5_L1_002", option.TenantId, option.BizDate, metricValue, now);
|
|
|
sub.DenominatorStatus = rateList.Count > 0 ? "OK" : "NO_VALID_ORDER";
|
|
|
return sub;
|
|
|
}
|
|
|
@@ -301,13 +305,14 @@ 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
|
|
|
- (1300000000001, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
|
|
|
+ (@TenantId, 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),
|
|
|
online_qty=VALUES(online_qty), warehouse_headcount=VALUES(warehouse_headcount),
|
|
|
efficiency=VALUES(efficiency), denominator_status=VALUES(denominator_status),
|
|
|
batch_id=VALUES(batch_id), update_time=@now",
|
|
|
+ new SugarParameter("@TenantId", option.TenantId),
|
|
|
new SugarParameter("@bizMonth", option.BizMonth),
|
|
|
new SugarParameter("@ztid", option.SourceZtid),
|
|
|
new SugarParameter("@periodStart", option.MonthlyPeriodStart),
|
|
|
@@ -321,7 +326,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
sub.DwdRows = dwdAffected;
|
|
|
|
|
|
// 月度 KPI 入日表:用月末日作 biz_date,月内每天可由聚合 API 再分发;分母缺失时 metric_value=NULL
|
|
|
- sub.KpiRows = await UpsertKpiValueAsync("S5_L1_003", option.MonthlyPeriodEnd, efficiency, now);
|
|
|
+ sub.KpiRows = await UpsertKpiValueAsync("S5_L1_003", option.TenantId, option.MonthlyPeriodEnd, efficiency, now);
|
|
|
return sub;
|
|
|
}
|
|
|
|
|
|
@@ -365,7 +370,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
|
|
|
- (1300000000001, 1, @bizMonth, @ztid, @startYm, @endYm,
|
|
|
+ (@TenantId, 1, @bizMonth, @ztid, @startYm, @endYm,
|
|
|
@ckcode, @ckname, @itemCode, @itemName, @pcode, @pname,
|
|
|
@je3, @je2, @turnoverDays, @batchId, @now)
|
|
|
ON DUPLICATE KEY UPDATE
|
|
|
@@ -377,6 +382,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
period_start_yyyymm=VALUES(period_start_yyyymm),
|
|
|
period_end_yyyymm=VALUES(period_end_yyyymm),
|
|
|
batch_id=VALUES(batch_id), update_time=@now",
|
|
|
+ new SugarParameter("@TenantId", option.TenantId),
|
|
|
new SugarParameter("@bizMonth", option.BizMonth),
|
|
|
new SugarParameter("@ztid", option.SourceZtid),
|
|
|
new SugarParameter("@startYm", option.TvfPeriodStartYyyymm),
|
|
|
@@ -399,7 +405,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
decimal? metricValue = turnoverDaysList.Count > 0
|
|
|
? Math.Round(turnoverDaysList.Average(), 4)
|
|
|
: null;
|
|
|
- sub.KpiRows = await UpsertKpiValueAsync("S5_L1_004", option.MonthlyPeriodEnd, metricValue, now);
|
|
|
+ sub.KpiRows = await UpsertKpiValueAsync("S5_L1_004", option.TenantId, option.MonthlyPeriodEnd, metricValue, now);
|
|
|
sub.DenominatorStatus = turnoverDaysList.Count > 0 ? "OK" : "NO_VALID_OUTBOUND_COST";
|
|
|
return sub;
|
|
|
}
|
|
|
@@ -414,7 +420,7 @@ ON DUPLICATE KEY UPDATE
|
|
|
return await t8.Ado.SqlQueryAsync<T>(sql, parameters);
|
|
|
}
|
|
|
|
|
|
- private async Task<int> UpsertKpiValueAsync(string metricCode, DateTime bizDate, decimal? metricValue, DateTime now)
|
|
|
+ private async Task<int> UpsertKpiValueAsync(string metricCode, long tenantId, DateTime bizDate, decimal? metricValue, DateTime now)
|
|
|
{
|
|
|
// 沿用 S3 UpsertS3KpiValueAsync 范式:先查现存行 → UPDATE;不存在 → SELECT MAX(id)+1 显式生成 id 后 INSERT。
|
|
|
// ado_s9_kpi_value_l1_day.id 为手工分配主键(无 AUTO_INCREMENT),必须显式 set;
|
|
|
@@ -422,11 +428,12 @@ 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=1300000000001 AND factory_id=1 " +
|
|
|
+ "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=@TenantId 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>
|
|
|
{
|
|
|
+ new("@TenantId", tenantId),
|
|
|
new("@ModuleCode", ModuleCode),
|
|
|
new("@MetricCode", metricCode),
|
|
|
new("@BizDate", bizDate)
|
|
|
@@ -450,10 +457,11 @@ 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, 1300000000001, NULL, NULL, 1, NULL, @BizDate,
|
|
|
+ (@Id, @TenantId, NULL, NULL, 1, NULL, @BizDate,
|
|
|
@Now, @Now, 0, 1,
|
|
|
@ModuleCode, @MetricCode, @MetricValue, @Now)",
|
|
|
new SugarParameter("@Id", nextId),
|
|
|
+ new SugarParameter("@TenantId", tenantId),
|
|
|
new SugarParameter("@BizDate", bizDate),
|
|
|
new SugarParameter("@Now", now),
|
|
|
new SugarParameter("@ModuleCode", ModuleCode),
|
|
|
@@ -467,7 +475,8 @@ 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
|
|
|
- (1300000000001, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
|
|
|
+ (@TenantId, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
|
|
|
+ new SugarParameter("@TenantId", option.TenantId),
|
|
|
new SugarParameter("@JobCode", JobCode),
|
|
|
new SugarParameter("@JobName", JobName),
|
|
|
new SugarParameter("@TriggerType", triggerType),
|
|
|
@@ -574,6 +583,8 @@ public sealed class S5MdpRefreshOption
|
|
|
{
|
|
|
/// <summary>T8 账套(kc_tz_head.ztid);实测当前唯一账套为 pbxfxp。</summary>
|
|
|
public string SourceZtid { get; set; } = "pbxfxp";
|
|
|
+ /// <summary>KPI 落库目标租户;0=由 SourceZtid 经 AidopSourceTenantMap 解析(禁止写死固定租户)。</summary>
|
|
|
+ public long TenantId { get; set; }
|
|
|
/// <summary>日 T+1 KPI 的业务日期(默认昨天)。</summary>
|
|
|
public DateTime BizDate { get; set; }
|
|
|
/// <summary>月 M+1 KPI 的业务月 YYYY-MM(默认上月)。</summary>
|