S6MdpSyncTransformService.cs 22 KB

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