InventoryInboundAdminService.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
  4. /// <summary>库存冷链手工补偿入口(管理员)。不接受前端 tenantId/domain/entityCode。</summary>
  5. [ApiDescriptionSettings(Order = 310, Description = "S5库存冷链入站")]
  6. [Route("api/S5InventoryInbound")]
  7. [NonUnify]
  8. public sealed class InventoryInboundAdminService : IDynamicApiController, ITransient
  9. {
  10. private readonly InventoryMdpSyncService _sync;
  11. private readonly InventoryReconService _recon;
  12. private readonly ILogger _logger;
  13. public InventoryInboundAdminService(
  14. InventoryMdpSyncService sync,
  15. InventoryReconService recon,
  16. ILoggerFactory loggerFactory)
  17. {
  18. _sync = sync;
  19. _recon = recon;
  20. _logger = loggerFactory.CreateLogger(nameof(InventoryInboundAdminService));
  21. }
  22. [DisplayName("库存冷链首刷")]
  23. [HttpPost("bootstrap")]
  24. [ApiDescriptionSettings(Name = "S5InventoryBootstrap")]
  25. public async Task<InventorySyncResult> Bootstrap(CancellationToken ct)
  26. {
  27. _logger.LogInformation("[S5InventoryInbound] bootstrap requested");
  28. return await _sync.RunBootstrapAsync(ct);
  29. }
  30. [DisplayName("库存冷链跑一轮")]
  31. [HttpPost("run-once")]
  32. [ApiDescriptionSettings(Name = "S5InventoryRunOnce")]
  33. public async Task<InventorySyncResult> RunOnce(CancellationToken ct)
  34. {
  35. _logger.LogInformation("[S5InventoryInbound] run-once requested");
  36. return await _sync.RunIncrementalAsync(ct);
  37. }
  38. [DisplayName("库存冷链全量校准")]
  39. [HttpPost("reconcile")]
  40. [ApiDescriptionSettings(Name = "S5InventoryReconcile")]
  41. public async Task<InventorySyncResult> Reconcile(CancellationToken ct)
  42. {
  43. _logger.LogInformation("[S5InventoryInbound] reconcile requested");
  44. return await _sync.RunReconcileFullAsync(ct);
  45. }
  46. [DisplayName("库存流水 stg→std 补转换")]
  47. [HttpPost("transform-std")]
  48. [ApiDescriptionSettings(Name = "S5InventoryTransformStd")]
  49. public async Task<InventorySyncResult> TransformStd(CancellationToken ct)
  50. {
  51. _logger.LogInformation("[S5InventoryInbound] transform-std requested");
  52. return await _sync.TransformTransStdFromStgAsync(ct);
  53. }
  54. /// <summary>
  55. /// 库存余额 stg→std 补物化:复用已完整落地的贴源批次,不访问源库。
  56. /// UPSERT 语义,不删除既有标准层数据。
  57. /// </summary>
  58. [DisplayName("库存余额 stg→std 补物化")]
  59. [HttpPost("transform-inventory-std")]
  60. [ApiDescriptionSettings(Name = "S5InventoryTransformInventoryStd")]
  61. public async Task<InventorySyncResult> TransformInventoryStd([FromQuery] string batchId, CancellationToken ct)
  62. {
  63. _logger.LogInformation("[S5InventoryInbound] transform-inventory-std requested batch={Batch}", batchId);
  64. return await _sync.TransformInventoryStdFromStgAsync(batchId, ct);
  65. }
  66. [DisplayName("库存日终对账(手工)")]
  67. [HttpPost("daily-recon")]
  68. [ApiDescriptionSettings(Name = "S5InventoryDailyRecon")]
  69. public async Task<object> DailyRecon(CancellationToken ct)
  70. {
  71. _logger.LogInformation("[S5InventoryInbound] daily-recon requested");
  72. var diffs = await _recon.RunDailyReconAsync(ct);
  73. return new { diffs, message = diffs == 0 ? "clean" : "diffs written" };
  74. }
  75. }