S6MdpSyncTransformService.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. using Admin.NET.Core.Service;
  2. using Admin.NET.Plugin.AiDOP.Infrastructure;
  3. using Microsoft.Extensions.Logging;
  4. using System.Text.Json;
  5. namespace Admin.NET.Plugin.AiDOP.Manufacturing;
  6. /// <summary>
  7. /// S6 生产执行 — T8 KPI 数据底座与刷新转换服务。
  8. /// 路径 A:方老师 v5.4 KPI 字段对照表 J 列 SQL 原逻辑直发 T8 SQL Server(ConfigId=t8_v5)。
  9. /// 包含 KPI:S6_L1_001 工单制造满足率 / S6_L1_002 工单制造人效。
  10. /// </summary>
  11. public class S6MdpSyncTransformService : ITransient
  12. {
  13. private readonly ISqlSugarClient _db;
  14. private readonly SysNoticeService _sysNoticeService;
  15. private readonly ILogger<S6MdpSyncTransformService> _logger;
  16. private const string JobCode = "S6_MDP_SYNC_TRANSFORM";
  17. private const string JobName = "S6 生产执行 MDP 同步与转换";
  18. private const string T8ConfigId = "t8_v5";
  19. private const string ModuleCode = "S6";
  20. // FAILURE-NOTIFICATION-1:超级管理员 superAdmin.NET(AccountType=999)
  21. private const long NoticeReceiverUserId = 1300000000101L;
  22. private const string NoticeReceiverUserName = "超级管理员";
  23. public S6MdpSyncTransformService(
  24. ISqlSugarClient db,
  25. SysNoticeService sysNoticeService,
  26. ILogger<S6MdpSyncTransformService> logger)
  27. {
  28. _db = db;
  29. _sysNoticeService = sysNoticeService;
  30. _logger = logger;
  31. }
  32. public async Task<S6MdpSyncTransformResult> RunFullAsync(
  33. CancellationToken cancellationToken = default,
  34. string triggerType = "AUTO",
  35. S6MdpRefreshOption? option = null)
  36. {
  37. cancellationToken.ThrowIfCancellationRequested();
  38. option ??= S6MdpRefreshOption.Default();
  39. NormalizeOption(option);
  40. var now = DateTime.Now;
  41. var batchId = $"S6_MDP_FULL_{now:yyyyMMddHHmmss}";
  42. var normalizedTrigger = NormalizeTriggerType(triggerType);
  43. var runLogId = await InsertTransformRunLogAsync(batchId, now, normalizedTrigger, option);
  44. var result = new S6MdpSyncTransformResult
  45. {
  46. BatchId = batchId,
  47. RunLogId = runLogId,
  48. TriggerType = normalizedTrigger,
  49. SourceZtid = option.SourceZtid,
  50. TargetTenantId = option.TargetTenantId,
  51. TargetFactoryId = option.TargetFactoryId,
  52. BizDate = option.BizDate,
  53. BizMonth = option.BizMonth,
  54. MonthlyPeriodStart = option.MonthlyPeriodStart,
  55. MonthlyPeriodEnd = option.MonthlyPeriodEnd
  56. };
  57. try
  58. {
  59. result.StageRows = 0;
  60. result.StandardRows = 0;
  61. var sub22 = await BuildS6L1001WorkOrderMfgFulfillmentAsync(batchId, now, option, cancellationToken);
  62. result.MergeSub("S6_L1_001", sub22);
  63. var sub23 = await BuildS6L1002WorkOrderMfgEfficiencyAsync(batchId, now, option, cancellationToken);
  64. result.MergeSub("S6_L1_002", sub23);
  65. await MarkTransformRunSuccessAsync(runLogId, now, result);
  66. return result;
  67. }
  68. catch (Exception ex)
  69. {
  70. await MarkTransformRunFailedAsync(runLogId, now, ex.Message, batchId);
  71. throw;
  72. }
  73. }
  74. // ─────────────────────────────────────────────────────────────────────────
  75. /// <summary>S6_L1_001 工单制造满足率 = 计划完工时间内累计报工 / 工单计划生产数量。</summary>
  76. private async Task<KpiBuildSubResult> BuildS6L1001WorkOrderMfgFulfillmentAsync(
  77. string batchId, DateTime now, S6MdpRefreshOption option, CancellationToken ct)
  78. {
  79. var sub = new KpiBuildSubResult();
  80. const string sql = @"
  81. select a.noid as noid, b.rwnoid as rwnoid, b.code as code, b.sl as sl, sum(d.slzx) as slzx
  82. from kc_dd_head a with(nolock)
  83. left join kc_dd_list b with(nolock) on a.Id=b.idid
  84. left join (
  85. select b.lynoid as lynoid, b.code as code,
  86. convert(varchar(10), a.shtime, 23) as shtime, b.slzx as slzx
  87. from kc_tz_head a with(nolock)
  88. inner join kc_tz_list b with(nolock) on a.Id=b.idid
  89. where a.ztid=@ztid and a.lbs='生产入库' and a.hzyn=0 and a.zfyn=0 and a.shyn=1
  90. ) d on b.rwnoid=d.lynoid and b.code=d.code
  91. where a.ztid=@ztid and a.lbs='生产任务' and a.zf=0 and a.shyn=1 and d.shtime<=b.jhdate
  92. group by a.noid, b.rwnoid, b.code, b.sl";
  93. var rows = await QueryT8Async<S6MfgFulfillmentRow>(sql, new[] { new SugarParameter("@ztid", option.SourceZtid) });
  94. sub.T8Rows = rows.Count;
  95. var dwdAffected = 0;
  96. var rateList = new List<decimal>();
  97. foreach (var r in rows)
  98. {
  99. ct.ThrowIfCancellationRequested();
  100. if (string.IsNullOrEmpty(r.noid)) continue;
  101. decimal? rate = (r.sl.HasValue && r.sl.Value > 0m && r.slzx.HasValue)
  102. ? Math.Round(r.slzx.Value / r.sl.Value, 4)
  103. : null;
  104. if (rate.HasValue) rateList.Add(rate.Value);
  105. dwdAffected += await _db.Ado.ExecuteCommandAsync(@"
  106. INSERT INTO dwd_t8_work_order_mfg_fulfillment
  107. (tenant_id, factory_id, biz_date, source_ztid, order_no, task_no, item_code,
  108. plan_qty, done_qty_in_window, fulfillment_rate, batch_id, create_time)
  109. VALUES
  110. (@tenantId, @factoryId, @bizDate, @ztid, @orderNo, @taskNo, @itemCode,
  111. @planQty, @doneQty, @rate, @batchId, @now)
  112. ON DUPLICATE KEY UPDATE
  113. plan_qty=VALUES(plan_qty), done_qty_in_window=VALUES(done_qty_in_window),
  114. fulfillment_rate=VALUES(fulfillment_rate),
  115. batch_id=VALUES(batch_id), update_time=@now",
  116. new SugarParameter("@tenantId", option.TargetTenantId),
  117. new SugarParameter("@factoryId", option.TargetFactoryId),
  118. new SugarParameter("@bizDate", option.BizDate),
  119. new SugarParameter("@ztid", option.SourceZtid),
  120. new SugarParameter("@orderNo", r.noid),
  121. new SugarParameter("@taskNo", r.rwnoid ?? ""),
  122. new SugarParameter("@itemCode", r.code ?? ""),
  123. new SugarParameter("@planQty", r.sl),
  124. new SugarParameter("@doneQty", r.slzx),
  125. new SugarParameter("@rate", rate),
  126. new SugarParameter("@batchId", batchId),
  127. new SugarParameter("@now", now));
  128. }
  129. sub.DwdRows = dwdAffected;
  130. decimal? metricValue = rateList.Count > 0
  131. ? Math.Round(rateList.Average() * 100m, 4) // 百分号
  132. : null;
  133. sub.KpiRows = await UpsertKpiValueAsync("S6_L1_001", option.BizDate, metricValue, now, option);
  134. sub.DenominatorStatus = rateList.Count > 0 ? "OK" : "NO_VALID_WORK_ORDER";
  135. return sub;
  136. }
  137. /// <summary>S6_L1_002 工单制造人效 = 完成制造工单数(lbs=生产入库 AND (slzx>=sl OR gdyn=1)) / count(gw=生产)。</summary>
  138. private async Task<KpiBuildSubResult> BuildS6L1002WorkOrderMfgEfficiencyAsync(
  139. string batchId, DateTime now, S6MdpRefreshOption option, CancellationToken ct)
  140. {
  141. var sub = new KpiBuildSubResult();
  142. const string sqlNumer = @"
  143. select count(*) as ddnum
  144. from kc_tz_head a with(nolock)
  145. inner join kc_tz_list b with(nolock) on a.Id=b.idid
  146. where a.ztid=@ztid and a.lbs='生产入库' and a.hzyn=0 and a.zfyn=0 and a.shyn=1
  147. and a.date0 between @startDate and @endDate
  148. and b.slzx>0 and (b.slzx>=b.sl or b.gdyn=1)";
  149. const string sqlDenom = @"
  150. select count(*) as penum
  151. from sys_pelist with(nolock)
  152. where ztid=@ztid and zzzt='在职' and gw='生产'";
  153. var pNumer = new[]
  154. {
  155. new SugarParameter("@ztid", option.SourceZtid),
  156. new SugarParameter("@startDate", option.MonthlyPeriodStart),
  157. new SugarParameter("@endDate", option.MonthlyPeriodEnd)
  158. };
  159. var pDenom = new[] { new SugarParameter("@ztid", option.SourceZtid) };
  160. var numerRows = await QueryT8Async<S6CountRow>(sqlNumer, pNumer);
  161. var denomRows = await QueryT8Async<S6PeNumRow>(sqlDenom, pDenom);
  162. sub.T8Rows = numerRows.Count + denomRows.Count;
  163. int? doneCount = numerRows.FirstOrDefault()?.ddnum;
  164. int? headcount = denomRows.FirstOrDefault()?.penum;
  165. decimal? efficiency = null;
  166. string denomStatus;
  167. if (!headcount.HasValue || headcount.Value <= 0)
  168. denomStatus = "NO_HEADCOUNT";
  169. else if (!doneCount.HasValue)
  170. denomStatus = "NO_NUMERATOR";
  171. else
  172. {
  173. efficiency = Math.Round((decimal)doneCount.Value / headcount.Value, 4);
  174. denomStatus = "OK";
  175. }
  176. sub.DenominatorStatus = denomStatus;
  177. var dwdAffected = await _db.Ado.ExecuteCommandAsync(@"
  178. INSERT INTO dwd_t8_work_order_mfg_efficiency
  179. (tenant_id, factory_id, biz_month, source_ztid, period_start, period_end,
  180. done_count, production_headcount, efficiency, denominator_status, batch_id, create_time)
  181. VALUES
  182. (@tenantId, @factoryId, @bizMonth, @ztid, @periodStart, @periodEnd,
  183. @doneCount, @headcount, @efficiency, @denomStatus, @batchId, @now)
  184. ON DUPLICATE KEY UPDATE
  185. period_start=VALUES(period_start), period_end=VALUES(period_end),
  186. done_count=VALUES(done_count), production_headcount=VALUES(production_headcount),
  187. efficiency=VALUES(efficiency), denominator_status=VALUES(denominator_status),
  188. batch_id=VALUES(batch_id), update_time=@now",
  189. new SugarParameter("@tenantId", option.TargetTenantId),
  190. new SugarParameter("@factoryId", option.TargetFactoryId),
  191. new SugarParameter("@bizMonth", option.BizMonth),
  192. new SugarParameter("@ztid", option.SourceZtid),
  193. new SugarParameter("@periodStart", option.MonthlyPeriodStart),
  194. new SugarParameter("@periodEnd", option.MonthlyPeriodEnd),
  195. new SugarParameter("@doneCount", doneCount),
  196. new SugarParameter("@headcount", headcount),
  197. new SugarParameter("@efficiency", efficiency),
  198. new SugarParameter("@denomStatus", denomStatus),
  199. new SugarParameter("@batchId", batchId),
  200. new SugarParameter("@now", now));
  201. sub.DwdRows = dwdAffected;
  202. sub.KpiRows = await UpsertKpiValueAsync("S6_L1_002", option.MonthlyPeriodEnd, efficiency, now, option);
  203. return sub;
  204. }
  205. // ─────────────────────────────────────────────────────────────────────────
  206. private async Task<List<T>> QueryT8Async<T>(string sql, SugarParameter[] parameters)
  207. {
  208. var t8 = _db.AsTenant().GetConnectionScope(T8ConfigId);
  209. return await t8.Ado.SqlQueryAsync<T>(sql, parameters);
  210. }
  211. private async Task<int> UpsertKpiValueAsync(string metricCode, DateTime bizDate, decimal? metricValue, DateTime now, S6MdpRefreshOption option)
  212. {
  213. // 沿用 S3 UpsertS3KpiValueAsync 范式:先查现存行 → UPDATE;不存在 → SELECT MAX(id)+1 显式生成 id 后 INSERT。
  214. // ado_s9_kpi_value_l1_day.id 为手工分配主键(无 AUTO_INCREMENT),必须显式 set;
  215. // metric_value 允许 NULL(分母缺失不得伪装真实 0)。
  216. // FIX-2:截断时分秒(月度 KPI 入参可能为 YYYY-MM-DD 23:59:59),保证 SELECT WHERE biz_date=@BizDate 与 DB date 列匹配,避免重复 INSERT。
  217. // FIX-1:tenant_id/factory_id 取自 option,默认仍为 1300000000001/1,不破坏 Demo。
  218. bizDate = bizDate.Date;
  219. var existingId = await _db.Ado.GetLongAsync(
  220. "SELECT IFNULL((SELECT id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=@TenantId AND factory_id=@FactoryId " +
  221. "AND module_code=@ModuleCode AND metric_code=@MetricCode AND biz_date=@BizDate AND is_deleted=0 " +
  222. "ORDER BY id LIMIT 1), 0)",
  223. new List<SugarParameter>
  224. {
  225. new("@TenantId", option.TargetTenantId),
  226. new("@FactoryId", option.TargetFactoryId),
  227. new("@ModuleCode", ModuleCode),
  228. new("@MetricCode", metricCode),
  229. new("@BizDate", bizDate)
  230. });
  231. if (existingId > 0)
  232. {
  233. return await _db.Ado.ExecuteCommandAsync(
  234. "UPDATE ado_s9_kpi_value_l1_day SET metric_value=@MetricValue, calc_time=@Now, " +
  235. "update_time=@Now, is_deleted=0, is_active=1 WHERE id=@Id",
  236. new SugarParameter("@MetricValue", metricValue),
  237. new SugarParameter("@Now", now),
  238. new SugarParameter("@Id", existingId));
  239. }
  240. var nextId = await _db.Ado.GetLongAsync(
  241. "SELECT COALESCE(MAX(id), 0) + 1 FROM ado_s9_kpi_value_l1_day");
  242. return await _db.Ado.ExecuteCommandAsync(@"
  243. INSERT INTO ado_s9_kpi_value_l1_day
  244. (id, tenant_id, org_id, company_id, factory_id, status, biz_date,
  245. create_time, update_time, is_deleted, is_active,
  246. module_code, metric_code, metric_value, calc_time)
  247. VALUES
  248. (@Id, @TenantId, NULL, NULL, @FactoryId, NULL, @BizDate,
  249. @Now, @Now, 0, 1,
  250. @ModuleCode, @MetricCode, @MetricValue, @Now)",
  251. new SugarParameter("@Id", nextId),
  252. new SugarParameter("@TenantId", option.TargetTenantId),
  253. new SugarParameter("@FactoryId", option.TargetFactoryId),
  254. new SugarParameter("@BizDate", bizDate),
  255. new SugarParameter("@Now", now),
  256. new SugarParameter("@ModuleCode", ModuleCode),
  257. new SugarParameter("@MetricCode", metricCode),
  258. new SugarParameter("@MetricValue", metricValue));
  259. }
  260. private async Task<long> InsertTransformRunLogAsync(string batchId, DateTime startedAt, string triggerType, S6MdpRefreshOption option)
  261. {
  262. await _db.Ado.ExecuteCommandAsync(@"
  263. INSERT INTO mdp_transform_run_log
  264. (tenant_id, job_code, job_name, trigger_type, batch_id, status, start_time, stage_rows, standard_rows, dwd_rows, create_time, update_time)
  265. VALUES
  266. (@TenantId, @JobCode, @JobName, @TriggerType, @BatchId, 'RUNNING', @StartTime, 0, 0, 0, @StartTime, @StartTime)",
  267. new SugarParameter("@TenantId", option.TargetTenantId),
  268. new SugarParameter("@JobCode", JobCode),
  269. new SugarParameter("@JobName", JobName),
  270. new SugarParameter("@TriggerType", triggerType),
  271. new SugarParameter("@BatchId", batchId),
  272. new SugarParameter("@StartTime", startedAt));
  273. return await _db.Ado.GetLongAsync(
  274. "SELECT id FROM mdp_transform_run_log WHERE batch_id=@BatchId ORDER BY id DESC LIMIT 1",
  275. new List<SugarParameter> { new("@BatchId", batchId) });
  276. }
  277. private async Task MarkTransformRunSuccessAsync(long runLogId, DateTime startedAt, S6MdpSyncTransformResult result)
  278. {
  279. var finishedAt = DateTime.Now;
  280. await _db.Ado.ExecuteCommandAsync(@"
  281. UPDATE mdp_transform_run_log
  282. SET status='SUCCESS', end_time=@EndTime, duration_ms=@DurationMs,
  283. stage_rows=@StageRows, standard_rows=@StandardRows, dwd_rows=@DwdRows,
  284. summary_json=@SummaryJson, update_time=CURRENT_TIMESTAMP
  285. WHERE id=@Id",
  286. new SugarParameter("@EndTime", finishedAt),
  287. new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
  288. new SugarParameter("@StageRows", result.StageRows),
  289. new SugarParameter("@StandardRows", result.StandardRows),
  290. new SugarParameter("@DwdRows", result.DwdRows),
  291. new SugarParameter("@SummaryJson", JsonSerializer.Serialize(new
  292. {
  293. batchId = result.BatchId,
  294. sourceZtid = result.SourceZtid,
  295. bizDate = result.BizDate.ToString("yyyy-MM-dd"),
  296. bizMonth = result.BizMonth,
  297. dwdRows = result.DwdRows,
  298. kpiRows = result.KpiRows,
  299. perKpiDwdRows = result.PerKpiDwdRows,
  300. perKpiKpiRows = result.PerKpiKpiRows,
  301. denominatorStatus = result.KpiDenominatorStatus
  302. })),
  303. new SugarParameter("@Id", runLogId));
  304. }
  305. private async Task MarkTransformRunFailedAsync(long runLogId, DateTime startedAt, string message, string batchId)
  306. {
  307. bool runLogUpdated = false;
  308. try
  309. {
  310. var finishedAt = DateTime.Now;
  311. await _db.Ado.ExecuteCommandAsync(@"
  312. UPDATE mdp_transform_run_log
  313. SET status='FAILED', end_time=@EndTime, duration_ms=@DurationMs,
  314. error_message=@ErrorMessage, update_time=CURRENT_TIMESTAMP
  315. WHERE id=@Id",
  316. new SugarParameter("@EndTime", finishedAt),
  317. new SugarParameter("@DurationMs", (int)(finishedAt - startedAt).TotalMilliseconds),
  318. new SugarParameter("@ErrorMessage", Truncate(message, 2000)),
  319. new SugarParameter("@Id", runLogId));
  320. runLogUpdated = true;
  321. }
  322. catch (Exception ex)
  323. {
  324. Console.Error.WriteLine($"[S6MdpSyncTransform] MarkTransformRunFailed write failed (runLogId={runLogId}): {ex.Message}");
  325. }
  326. // FAILURE-NOTIFICATION-1:写库 FAILED 成功后发通知给超级管理员;通知失败不影响主流程
  327. if (!runLogUpdated) return;
  328. try
  329. {
  330. await _sysNoticeService.AddNotice(new AddNoticeInput
  331. {
  332. Title = "S6 生产执行 T8 KPI 跑批失败",
  333. Content = $"模块:S6 生产执行\n批次ID:{batchId}\n失败时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}\n错误信息:{Truncate(message, 1000)}\n\n请查看 mdp_transform_run_log 获取完整错误与重试记录。",
  334. Type = NoticeTypeEnum.NOTICE,
  335. PublicTime = DateTime.Now,
  336. Status = NoticeStatusEnum.PUBLIC,
  337. PublicUserId = NoticeReceiverUserId,
  338. PublicUserName = NoticeReceiverUserName
  339. });
  340. }
  341. catch (Exception notifyEx)
  342. {
  343. _logger.LogError(notifyEx, "[S6MdpSyncTransform] SysNotice 发送失败 (runLogId={RunLogId}, batchId={BatchId})", runLogId, batchId);
  344. }
  345. }
  346. private static string NormalizeTriggerType(string s) =>
  347. string.IsNullOrWhiteSpace(s) ? "AUTO" : s.Trim().ToUpperInvariant();
  348. private static void NormalizeOption(S6MdpRefreshOption option)
  349. {
  350. var d = S6MdpRefreshOption.Default();
  351. if (option.TargetFactoryId <= 0) option.TargetFactoryId = d.TargetFactoryId;
  352. if (string.IsNullOrWhiteSpace(option.SourceZtid)) option.SourceZtid = d.SourceZtid;
  353. option.TargetTenantId = AidopSourceTenantMap.ResolveTenantId(option.SourceZtid, option.TargetTenantId);
  354. if (option.BizDate == default) option.BizDate = d.BizDate;
  355. if (string.IsNullOrWhiteSpace(option.BizMonth)) option.BizMonth = d.BizMonth;
  356. if (option.MonthlyPeriodStart == default) option.MonthlyPeriodStart = d.MonthlyPeriodStart;
  357. if (option.MonthlyPeriodEnd == default) option.MonthlyPeriodEnd = d.MonthlyPeriodEnd;
  358. }
  359. private static string Truncate(string s, int max) =>
  360. string.IsNullOrEmpty(s) ? "" : (s.Length <= max ? s : s.Substring(0, max));
  361. }
  362. // DTO ────────────────────────────────────────────────────────────────────────
  363. public sealed class S6MdpRefreshOption
  364. {
  365. public string SourceZtid { get; set; } = "pbxfxp";
  366. /// <summary>KPI/DWD 落库目标租户;≤0 时由 <see cref="AidopSourceTenantMap"/> 按 SourceZtid 解析。</summary>
  367. public long TargetTenantId { get; set; }
  368. /// <summary>KPI/DWD 落库目标工厂;默认 1。</summary>
  369. public long TargetFactoryId { get; set; } = 1L;
  370. public DateTime BizDate { get; set; }
  371. public string BizMonth { get; set; } = "";
  372. public DateTime MonthlyPeriodStart { get; set; }
  373. public DateTime MonthlyPeriodEnd { get; set; }
  374. public static S6MdpRefreshOption Default()
  375. {
  376. var today = DateTime.Today;
  377. var yesterday = today.AddDays(-1);
  378. var lastMonth = today.AddMonths(-1);
  379. var monthStart = new DateTime(lastMonth.Year, lastMonth.Month, 1);
  380. var monthEnd = monthStart.AddMonths(1).AddDays(-1);
  381. return new S6MdpRefreshOption
  382. {
  383. SourceZtid = "pbxfxp",
  384. TargetTenantId = 0,
  385. TargetFactoryId = 1L,
  386. BizDate = yesterday,
  387. BizMonth = lastMonth.ToString("yyyy-MM"),
  388. MonthlyPeriodStart = monthStart,
  389. MonthlyPeriodEnd = monthEnd.AddDays(1).AddSeconds(-1)
  390. };
  391. }
  392. }
  393. public sealed class S6MdpSyncTransformResult
  394. {
  395. public string BatchId { get; set; } = "";
  396. public long RunLogId { get; set; }
  397. public string TriggerType { get; set; } = "AUTO";
  398. public string SourceZtid { get; set; } = "";
  399. public long TargetTenantId { get; set; }
  400. public long TargetFactoryId { get; set; }
  401. public DateTime BizDate { get; set; }
  402. public string BizMonth { get; set; } = "";
  403. public DateTime MonthlyPeriodStart { get; set; }
  404. public DateTime MonthlyPeriodEnd { get; set; }
  405. public int StageRows { get; set; }
  406. public int StandardRows { get; set; }
  407. public int DwdRows { get; set; }
  408. public int KpiRows { get; set; }
  409. public Dictionary<string, int> PerKpiDwdRows { get; } = new();
  410. public Dictionary<string, int> PerKpiKpiRows { get; } = new();
  411. public List<string> KpiDenominatorStatus { get; } = new();
  412. public void MergeSub(string kpiCode, KpiBuildSubResult sub)
  413. {
  414. PerKpiDwdRows[kpiCode] = sub.DwdRows;
  415. PerKpiKpiRows[kpiCode] = sub.KpiRows;
  416. DwdRows += sub.DwdRows;
  417. KpiRows += sub.KpiRows;
  418. KpiDenominatorStatus.Add($"{kpiCode}:{sub.DenominatorStatus}");
  419. }
  420. }
  421. public sealed class KpiBuildSubResult
  422. {
  423. public int T8Rows { get; set; }
  424. public int DwdRows { get; set; }
  425. public int KpiRows { get; set; }
  426. public string DenominatorStatus { get; set; } = "OK";
  427. }
  428. // T8 result set 投影类型 ──────────────────────────────────────────────────────
  429. internal sealed class S6MfgFulfillmentRow
  430. {
  431. public string? noid { get; set; }
  432. public string? rwnoid { get; set; }
  433. public string? code { get; set; }
  434. public decimal? sl { get; set; }
  435. public decimal? slzx { get; set; }
  436. }
  437. internal sealed class S6CountRow
  438. {
  439. public int ddnum { get; set; }
  440. }
  441. internal sealed class S6PeNumRow
  442. {
  443. public int penum { get; set; }
  444. }