S7MdpSyncTransformService.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using System.Text.Json;
  2. namespace Admin.NET.Plugin.AiDOP.FinishedWarehouse;
  3. /// <summary>
  4. /// S7 成品仓储 — T8 KPI 数据底座与刷新转换服务。
  5. /// 路径 A:方老师 v5.4 KPI 字段对照表 J 列 SQL 原逻辑直发 T8 SQL Server(ConfigId=t8_v5)。
  6. /// 包含 KPI:S7_L1_001 订单发货周期 / S7_L1_002 订单发货满足率 / S7_L1_003 成品仓储人效。
  7. /// </summary>
  8. public class S7MdpSyncTransformService : ITransient
  9. {
  10. private readonly ISqlSugarClient _db;
  11. private const string JobCode = "S7_MDP_SYNC_TRANSFORM";
  12. private const string JobName = "S7 成品仓储 MDP 同步与转换";
  13. private const string T8ConfigId = "t8_v5";
  14. private const string ModuleCode = "S7";
  15. public S7MdpSyncTransformService(ISqlSugarClient db)
  16. {
  17. _db = db;
  18. }
  19. public async Task<S7MdpSyncTransformResult> RunFullAsync(
  20. CancellationToken cancellationToken = default,
  21. string triggerType = "AUTO",
  22. S7MdpRefreshOption? option = null)
  23. {
  24. cancellationToken.ThrowIfCancellationRequested();
  25. option ??= S7MdpRefreshOption.Default();
  26. var now = DateTime.Now;
  27. var batchId = $"S7_MDP_FULL_{now:yyyyMMddHHmmss}";
  28. var normalizedTrigger = NormalizeTriggerType(triggerType);
  29. var runLogId = await InsertTransformRunLogAsync(batchId, now, normalizedTrigger);
  30. var result = new S7MdpSyncTransformResult
  31. {
  32. BatchId = batchId,
  33. RunLogId = runLogId,
  34. TriggerType = normalizedTrigger,
  35. SourceZtid = option.SourceZtid,
  36. BizDate = option.BizDate,
  37. BizMonth = option.BizMonth,
  38. MonthlyPeriodStart = option.MonthlyPeriodStart,
  39. MonthlyPeriodEnd = option.MonthlyPeriodEnd
  40. };
  41. try
  42. {
  43. result.StageRows = 0;
  44. result.StandardRows = 0;
  45. var sub25 = await BuildS7L1001OrderShipmentCycleAsync(batchId, now, option, cancellationToken);
  46. result.MergeSub("S7_L1_001", sub25);
  47. var sub26 = await BuildS7L1002OrderShipmentFulfillmentAsync(batchId, now, option, cancellationToken);
  48. result.MergeSub("S7_L1_002", sub26);
  49. var sub27 = await BuildS7L1003FinishedWarehouseEfficiencyAsync(batchId, now, option, cancellationToken);
  50. result.MergeSub("S7_L1_003", sub27);
  51. await MarkTransformRunSuccessAsync(runLogId, now, result);
  52. return result;
  53. }
  54. catch (Exception ex)
  55. {
  56. await MarkTransformRunFailedAsync(runLogId, now, ex.Message);
  57. throw;
  58. }
  59. }
  60. // ─────────────────────────────────────────────────────────────────────────
  61. /// <summary>S7_L1_001 订单发货周期 = 最晚发货日期 - 最早 FQC 报检日期(5 表 JOIN)。</summary>
  62. private async Task<KpiBuildSubResult> BuildS7L1001OrderShipmentCycleAsync(
  63. string batchId, DateTime now, S7MdpRefreshOption option, CancellationToken ct)
  64. {
  65. var sub = new KpiBuildSubResult();
  66. const string sql = @"
  67. select noid as noid,
  68. datediff(day, min(shdate), max(shtime)) as scts
  69. from (
  70. select a.noid as noid, b.code as code,
  71. IsNull(c.shdate, b.addtime) as shdate,
  72. (case when b.gdyn=1 then b.gdtime else d.shtime end) as shtime,
  73. (case when b.gdyn=1 or b.sl<=b.slzx then 1 else 0 end) as wczt
  74. from kc_dd_head a with(nolock)
  75. left join kc_dd_list b with(nolock) on a.Id=b.idid
  76. left join (
  77. select min(b.id) as id, b.lynoid as lynoid, b.code as code,
  78. max(a.shtime) as shtime, sum(b.slzx) as slzx
  79. from kc_tz_head a with(nolock)
  80. inner join kc_tz_list b with(nolock) on a.Id=b.idid
  81. where a.ztid=@ztid and a.lbs='销售出库' and a.hzyn=0 and a.zfyn=0 and a.shyn=1
  82. group by b.lynoid, b.code
  83. ) d on b.rwnoid=d.lynoid and b.code=d.code
  84. left join kc_zj_list c on a.ztid=c.ztid and c.lyid=b.id and c.zjyn=1
  85. where a.ztid=@ztid and a.lbs='销售订单' and a.zf=0 and a.shyn=1
  86. ) n
  87. group by noid
  88. having min(wczt)=1";
  89. var rows = await QueryT8Async<S7CycleRow>(sql, new[] { new SugarParameter("@ztid", option.SourceZtid) });
  90. sub.T8Rows = rows.Count;
  91. var dwdAffected = 0;
  92. var cycleList = new List<int>();
  93. foreach (var r in rows)
  94. {
  95. ct.ThrowIfCancellationRequested();
  96. if (string.IsNullOrEmpty(r.noid)) continue;
  97. if (r.scts.HasValue) cycleList.Add(r.scts.Value);
  98. dwdAffected += await _db.Ado.ExecuteCommandAsync(@"
  99. INSERT INTO dwd_t8_order_shipment_cycle
  100. (tenant_id, factory_id, biz_date, source_ztid, order_no, cycle_days, batch_id, create_time)
  101. VALUES
  102. (0, 1, @bizDate, @ztid, @orderNo, @cycleDays, @batchId, @now)
  103. ON DUPLICATE KEY UPDATE
  104. cycle_days=VALUES(cycle_days),
  105. batch_id=VALUES(batch_id), update_time=@now",
  106. new SugarParameter("@bizDate", option.BizDate),
  107. new SugarParameter("@ztid", option.SourceZtid),
  108. new SugarParameter("@orderNo", r.noid),
  109. new SugarParameter("@cycleDays", r.scts),
  110. new SugarParameter("@batchId", batchId),
  111. new SugarParameter("@now", now));
  112. }
  113. sub.DwdRows = dwdAffected;
  114. decimal? metricValue = cycleList.Count > 0
  115. ? Math.Round((decimal)cycleList.Average(), 4)
  116. : null;
  117. sub.KpiRows = await UpsertKpiValueAsync("S7_L1_001", option.BizDate, metricValue, now);
  118. sub.DenominatorStatus = cycleList.Count > 0 ? "OK" : "NO_COMPLETED_ORDER";
  119. return sub;
  120. }
  121. /// <summary>S7_L1_002 订单发货满足率 = (交期前发货行数 / 该订单总行数) × 100%。</summary>
  122. private async Task<KpiBuildSubResult> BuildS7L1002OrderShipmentFulfillmentAsync(
  123. string batchId, DateTime now, S7MdpRefreshOption option, CancellationToken ct)
  124. {
  125. var sub = new KpiBuildSubResult();
  126. const string sql = @"
  127. select noid as noid,
  128. count(noid) as total_rows,
  129. sum(wczt) as in_window_rows
  130. from (
  131. select a.noid as noid, b.rwnoid as rwnoid, b.code as code,
  132. (case when sum(d.slzx)>=b.sl then 1 else 0 end) as wczt
  133. from kc_dd_head a with(nolock)
  134. left join kc_dd_list b with(nolock) on a.Id=b.idid
  135. left join (
  136. select b.lynoid as lynoid, b.code as code,
  137. convert(varchar(10), a.shtime, 23) as shtime, b.slzx as slzx
  138. from kc_tz_head a with(nolock)
  139. inner join kc_tz_list b with(nolock) on a.Id=b.idid
  140. where a.ztid=@ztid and a.lbs='销售出库' and a.hzyn=0 and a.zfyn=0 and a.shyn=1
  141. ) d on b.rwnoid=d.lynoid and b.code=d.code and d.shtime<=b.jhdate
  142. where a.ztid=@ztid and a.lbs='销售订单' and a.zf=0 and a.shyn=1
  143. group by a.noid, b.rwnoid, b.code, b.sl
  144. ) n
  145. group by noid";
  146. var rows = await QueryT8Async<S7FulfillmentRow>(sql, new[] { new SugarParameter("@ztid", option.SourceZtid) });
  147. sub.T8Rows = rows.Count;
  148. var dwdAffected = 0;
  149. var rateList = new List<decimal>();
  150. foreach (var r in rows)
  151. {
  152. ct.ThrowIfCancellationRequested();
  153. if (string.IsNullOrEmpty(r.noid)) continue;
  154. decimal? rate = (r.total_rows > 0)
  155. ? Math.Round((decimal)r.in_window_rows / r.total_rows * 100m, 4)
  156. : null;
  157. if (rate.HasValue) rateList.Add(rate.Value);
  158. dwdAffected += await _db.Ado.ExecuteCommandAsync(@"
  159. INSERT INTO dwd_t8_order_shipment_fulfillment
  160. (tenant_id, factory_id, biz_date, source_ztid, order_no,
  161. total_rows, in_window_rows, fulfillment_rate, batch_id, create_time)
  162. VALUES
  163. (0, 1, @bizDate, @ztid, @orderNo,
  164. @total, @inWindow, @rate, @batchId, @now)
  165. ON DUPLICATE KEY UPDATE
  166. total_rows=VALUES(total_rows), in_window_rows=VALUES(in_window_rows),
  167. fulfillment_rate=VALUES(fulfillment_rate),
  168. batch_id=VALUES(batch_id), update_time=@now",
  169. new SugarParameter("@bizDate", option.BizDate),
  170. new SugarParameter("@ztid", option.SourceZtid),
  171. new SugarParameter("@orderNo", r.noid),
  172. new SugarParameter("@total", r.total_rows),
  173. new SugarParameter("@inWindow", r.in_window_rows),
  174. new SugarParameter("@rate", rate),
  175. new SugarParameter("@batchId", batchId),
  176. new SugarParameter("@now", now));
  177. }
  178. sub.DwdRows = dwdAffected;
  179. decimal? metricValue = rateList.Count > 0
  180. ? Math.Round(rateList.Average(), 4)
  181. : null;
  182. sub.KpiRows = await UpsertKpiValueAsync("S7_L1_002", option.BizDate, metricValue, now);
  183. sub.DenominatorStatus = rateList.Count > 0 ? "OK" : "NO_VALID_ORDER";
  184. return sub;
  185. }
  186. /// <summary>S7_L1_003 成品仓储人效 = SUM(slzx where lbs=销售出库) / count(gw=仓管)。</summary>
  187. private async Task<KpiBuildSubResult> BuildS7L1003FinishedWarehouseEfficiencyAsync(
  188. string batchId, DateTime now, S7MdpRefreshOption option, CancellationToken ct)
  189. {
  190. var sub = new KpiBuildSubResult();
  191. const string sqlNumer = @"
  192. select b.lynoid as lynoid, b.code as code,
  193. convert(varchar(10), a.shtime, 23) as shtime, b.slzx as slzx
  194. from kc_tz_head a with(nolock)
  195. inner join kc_tz_list b with(nolock) on a.Id=b.idid
  196. where a.ztid=@ztid and a.lbs='销售出库' and a.hzyn=0 and a.zfyn=0 and a.shyn=1
  197. and convert(varchar(10), a.shtime, 23) between @startDateText and @endDateText";
  198. const string sqlDenom = @"
  199. select count(*) as penum
  200. from sys_pelist with(nolock)
  201. where ztid=@ztid and zzzt='在职' and gw='仓管'";
  202. var pNumer = new[]
  203. {
  204. new SugarParameter("@ztid", option.SourceZtid),
  205. new SugarParameter("@startDateText", option.MonthlyPeriodStart.ToString("yyyy-MM-dd")),
  206. new SugarParameter("@endDateText", option.MonthlyPeriodEnd.ToString("yyyy-MM-dd"))
  207. };
  208. var pDenom = new[] { new SugarParameter("@ztid", option.SourceZtid) };
  209. var numerRows = await QueryT8Async<S7ShipmentDetailRow>(sqlNumer, pNumer);
  210. var denomRows = await QueryT8Async<S7PeNumRow>(sqlDenom, pDenom);
  211. sub.T8Rows = numerRows.Count + denomRows.Count;
  212. decimal? shipmentQty = numerRows.Sum(r => r.slzx ?? 0m);
  213. if (numerRows.Count == 0) shipmentQty = null;
  214. int? headcount = denomRows.FirstOrDefault()?.penum;
  215. decimal? efficiency = null;
  216. string denomStatus;
  217. if (!headcount.HasValue || headcount.Value <= 0)
  218. denomStatus = "NO_HEADCOUNT";
  219. else if (!shipmentQty.HasValue)
  220. denomStatus = "NO_NUMERATOR";
  221. else
  222. {
  223. efficiency = Math.Round(shipmentQty.Value / headcount.Value, 4);
  224. denomStatus = "OK";
  225. }
  226. sub.DenominatorStatus = denomStatus;
  227. var dwdAffected = await _db.Ado.ExecuteCommandAsync(@"
  228. INSERT INTO dwd_t8_finished_warehouse_efficiency
  229. (tenant_id, factory_id, biz_month, source_ztid, period_start, period_end,
  230. shipment_qty, warehouse_headcount, efficiency, denominator_status, batch_id, create_time)
  231. VALUES
  232. (0, 1, @bizMonth, @ztid, @periodStart, @periodEnd,
  233. @shipmentQty, @headcount, @efficiency, @denomStatus, @batchId, @now)
  234. ON DUPLICATE KEY UPDATE
  235. period_start=VALUES(period_start), period_end=VALUES(period_end),
  236. shipment_qty=VALUES(shipment_qty), warehouse_headcount=VALUES(warehouse_headcount),
  237. efficiency=VALUES(efficiency), denominator_status=VALUES(denominator_status),
  238. batch_id=VALUES(batch_id), update_time=@now",
  239. new SugarParameter("@bizMonth", option.BizMonth),
  240. new SugarParameter("@ztid", option.SourceZtid),
  241. new SugarParameter("@periodStart", option.MonthlyPeriodStart),
  242. new SugarParameter("@periodEnd", option.MonthlyPeriodEnd),
  243. new SugarParameter("@shipmentQty", shipmentQty),
  244. new SugarParameter("@headcount", headcount),
  245. new SugarParameter("@efficiency", efficiency),
  246. new SugarParameter("@denomStatus", denomStatus),
  247. new SugarParameter("@batchId", batchId),
  248. new SugarParameter("@now", now));
  249. sub.DwdRows = dwdAffected;
  250. sub.KpiRows = await UpsertKpiValueAsync("S7_L1_003", option.MonthlyPeriodEnd, efficiency, now);
  251. return sub;
  252. }
  253. // ─────────────────────────────────────────────────────────────────────────
  254. private async Task<List<T>> QueryT8Async<T>(string sql, SugarParameter[] parameters)
  255. {
  256. var t8 = _db.AsTenant().GetConnectionScope(T8ConfigId);
  257. return await t8.Ado.SqlQueryAsync<T>(sql, parameters);
  258. }
  259. private async Task<int> UpsertKpiValueAsync(string metricCode, DateTime bizDate, decimal? metricValue, DateTime now)
  260. {
  261. // 沿用 S3 UpsertS3KpiValueAsync 范式:先查现存行 → UPDATE;不存在 → SELECT MAX(id)+1 显式生成 id 后 INSERT。
  262. // ado_s9_kpi_value_l1_day.id 为手工分配主键(无 AUTO_INCREMENT),必须显式 set;
  263. // metric_value 允许 NULL(分母缺失不得伪装真实 0)。
  264. // FIX-2:截断时分秒(月度 KPI 入参可能为 YYYY-MM-DD 23:59:59),保证 SELECT WHERE biz_date=@BizDate 与 DB date 列匹配,避免重复 INSERT。
  265. bizDate = bizDate.Date;
  266. var existingId = await _db.Ado.GetLongAsync(
  267. "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=0 AND factory_id=1 " +
  268. "AND module_code=@ModuleCode AND metric_code=@MetricCode AND biz_date=@BizDate AND is_deleted=0 " +
  269. "ORDER BY id LIMIT 1), 0)",
  270. new List<SugarParameter>
  271. {
  272. new("@ModuleCode", ModuleCode),
  273. new("@MetricCode", metricCode),
  274. new("@BizDate", bizDate)
  275. });
  276. if (existingId > 0)
  277. {
  278. return await _db.Ado.ExecuteCommandAsync(
  279. "UPDATE ado_s9_kpi_value_l1_day SET metric_value=@MetricValue, calc_time=@Now, " +
  280. "update_time=@Now, is_deleted=0, is_active=1 WHERE id=@Id",
  281. new SugarParameter("@MetricValue", metricValue),
  282. new SugarParameter("@Now", now),
  283. new SugarParameter("@Id", existingId));
  284. }
  285. var nextId = await _db.Ado.GetLongAsync(
  286. "SELECT COALESCE(MAX(id), 0) + 1 FROM ado_s9_kpi_value_l1_day");
  287. return await _db.Ado.ExecuteCommandAsync(@"
  288. INSERT INTO ado_s9_kpi_value_l1_day
  289. (id, tenant_id, org_id, company_id, factory_id, status, biz_date,
  290. create_time, update_time, is_deleted, is_active,
  291. module_code, metric_code, metric_value, calc_time)
  292. VALUES
  293. (@Id, 0, NULL, NULL, 1, NULL, @BizDate,
  294. @Now, @Now, 0, 1,
  295. @ModuleCode, @MetricCode, @MetricValue, @Now)",
  296. new SugarParameter("@Id", nextId),
  297. new SugarParameter("@BizDate", bizDate),
  298. new SugarParameter("@Now", now),
  299. new SugarParameter("@ModuleCode", ModuleCode),
  300. new SugarParameter("@MetricCode", metricCode),
  301. new SugarParameter("@MetricValue", metricValue));
  302. }
  303. private async Task<long> InsertTransformRunLogAsync(string batchId, DateTime startedAt, string triggerType)
  304. {
  305. await _db.Ado.ExecuteCommandAsync(@"
  306. INSERT INTO mdp_transform_run_log
  307. (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time, stage_rows, standard_rows, dwd_rows, create_time, update_time)
  308. VALUES
  309. (0, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
  310. new SugarParameter("@JobCode", JobCode),
  311. new SugarParameter("@JobName", JobName),
  312. new SugarParameter("@TriggerType", triggerType),
  313. new SugarParameter("@BatchId", batchId),
  314. new SugarParameter("@StartTime", startedAt));
  315. return await _db.Ado.GetLongAsync(
  316. "SELECT id FROM mdp_transform_run_log WHERE batch_id=@BatchId ORDER BY id DESC LIMIT 1",
  317. new List<SugarParameter> { new("@BatchId", batchId) });
  318. }
  319. private async Task MarkTransformRunSuccessAsync(long runLogId, DateTime startedAt, S7MdpSyncTransformResult result)
  320. {
  321. var finishedAt = DateTime.Now;
  322. await _db.Ado.ExecuteCommandAsync(@"
  323. UPDATE mdp_transform_run_log
  324. SET status='SUCCESS', end_time=@EndTime, duration_ms=@DurationMs,
  325. stage_rows=@StageRows, standard_rows=@StandardRows, dwd_rows=@DwdRows,
  326. summary_json=@SummaryJson, update_time=CURRENT_TIMESTAMP
  327. WHERE id=@Id",
  328. new SugarParameter("@EndTime", finishedAt),
  329. new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
  330. new SugarParameter("@StageRows", result.StageRows),
  331. new SugarParameter("@StandardRows", result.StandardRows),
  332. new SugarParameter("@DwdRows", result.DwdRows),
  333. new SugarParameter("@SummaryJson", JsonSerializer.Serialize(new
  334. {
  335. batchId = result.BatchId,
  336. sourceZtid = result.SourceZtid,
  337. bizDate = result.BizDate.ToString("yyyy-MM-dd"),
  338. bizMonth = result.BizMonth,
  339. dwdRows = result.DwdRows,
  340. kpiRows = result.KpiRows,
  341. perKpiDwdRows = result.PerKpiDwdRows,
  342. perKpiKpiRows = result.PerKpiKpiRows,
  343. denominatorStatus = result.KpiDenominatorStatus
  344. })),
  345. new SugarParameter("@Id", runLogId));
  346. }
  347. private async Task MarkTransformRunFailedAsync(long runLogId, DateTime startedAt, string message)
  348. {
  349. try
  350. {
  351. var finishedAt = DateTime.Now;
  352. await _db.Ado.ExecuteCommandAsync(@"
  353. UPDATE mdp_transform_run_log
  354. SET status='FAILED', end_time=@EndTime, duration_ms=@DurationMs,
  355. error_message=@ErrorMessage, update_time=CURRENT_TIMESTAMP
  356. WHERE id=@Id",
  357. new SugarParameter("@EndTime", finishedAt),
  358. new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
  359. new SugarParameter("@ErrorMessage", Truncate(message, 2000)),
  360. new SugarParameter("@Id", runLogId));
  361. }
  362. catch (Exception ex)
  363. {
  364. Console.Error.WriteLine($"[S7MdpSyncTransform] MarkTransformRunFailed write failed (runLogId={runLogId}): {ex.Message}");
  365. }
  366. }
  367. private static string NormalizeTriggerType(string s) =>
  368. string.IsNullOrWhiteSpace(s) ? "AUTO" : s.Trim().ToUpperInvariant();
  369. private static string Truncate(string s, int max) =>
  370. string.IsNullOrEmpty(s) ? "" : (s.Length <= max ? s : s.Substring(0, max));
  371. }
  372. // DTO ────────────────────────────────────────────────────────────────────────
  373. public sealed class S7MdpRefreshOption
  374. {
  375. public string SourceZtid { get; set; } = "pbxfxp";
  376. public DateTime BizDate { get; set; }
  377. public string BizMonth { get; set; } = "";
  378. public DateTime MonthlyPeriodStart { get; set; }
  379. public DateTime MonthlyPeriodEnd { get; set; }
  380. public static S7MdpRefreshOption Default()
  381. {
  382. var today = DateTime.Today;
  383. var yesterday = today.AddDays(-1);
  384. var lastMonth = today.AddMonths(-1);
  385. var monthStart = new DateTime(lastMonth.Year, lastMonth.Month, 1);
  386. var monthEnd = monthStart.AddMonths(1).AddDays(-1);
  387. return new S7MdpRefreshOption
  388. {
  389. SourceZtid = "pbxfxp",
  390. BizDate = yesterday,
  391. BizMonth = lastMonth.ToString("yyyy-MM"),
  392. MonthlyPeriodStart = monthStart,
  393. MonthlyPeriodEnd = monthEnd.AddDays(1).AddSeconds(-1)
  394. };
  395. }
  396. }
  397. public sealed class S7MdpSyncTransformResult
  398. {
  399. public string BatchId { get; set; } = "";
  400. public long RunLogId { get; set; }
  401. public string TriggerType { get; set; } = "AUTO";
  402. public string SourceZtid { get; set; } = "";
  403. public DateTime BizDate { get; set; }
  404. public string BizMonth { get; set; } = "";
  405. public DateTime MonthlyPeriodStart { get; set; }
  406. public DateTime MonthlyPeriodEnd { get; set; }
  407. public int StageRows { get; set; }
  408. public int StandardRows { get; set; }
  409. public int DwdRows { get; set; }
  410. public int KpiRows { get; set; }
  411. public Dictionary<string, int> PerKpiDwdRows { get; } = new();
  412. public Dictionary<string, int> PerKpiKpiRows { get; } = new();
  413. public List<string> KpiDenominatorStatus { get; } = new();
  414. public void MergeSub(string kpiCode, KpiBuildSubResult sub)
  415. {
  416. PerKpiDwdRows[kpiCode] = sub.DwdRows;
  417. PerKpiKpiRows[kpiCode] = sub.KpiRows;
  418. DwdRows += sub.DwdRows;
  419. KpiRows += sub.KpiRows;
  420. KpiDenominatorStatus.Add($"{kpiCode}:{sub.DenominatorStatus}");
  421. }
  422. }
  423. public sealed class KpiBuildSubResult
  424. {
  425. public int T8Rows { get; set; }
  426. public int DwdRows { get; set; }
  427. public int KpiRows { get; set; }
  428. public string DenominatorStatus { get; set; } = "OK";
  429. }
  430. // T8 result set 投影类型 ──────────────────────────────────────────────────────
  431. internal sealed class S7CycleRow
  432. {
  433. public string? noid { get; set; }
  434. public int? scts { get; set; }
  435. }
  436. internal sealed class S7FulfillmentRow
  437. {
  438. public string? noid { get; set; }
  439. public int total_rows { get; set; }
  440. public int in_window_rows { get; set; }
  441. }
  442. internal sealed class S7ShipmentDetailRow
  443. {
  444. public string? lynoid { get; set; }
  445. public string? code { get; set; }
  446. public string? shtime { get; set; }
  447. public decimal? slzx { get; set; }
  448. }
  449. internal sealed class S7PeNumRow
  450. {
  451. public int penum { get; set; }
  452. }