MdpHotWatchAdminService.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
  2. namespace Admin.NET.Plugin.AiDOP.DataPlatform.HotWatch;
  3. /// <summary>热回读联调:手工登记 / 立即轮询。</summary>
  4. [ApiDescriptionSettings(Order = 329, Description = "MDP 热回读运维")]
  5. [Route("api/aidop/mdp-hot-watch")]
  6. [AllowAnonymous]
  7. [NonUnify]
  8. public class MdpHotWatchAdminService : IDynamicApiController, ITransient
  9. {
  10. private readonly MdpHotWatchService _hotWatch;
  11. private readonly ISqlSugarClient _db;
  12. public MdpHotWatchAdminService(MdpHotWatchService hotWatch, ISqlSugarClient db)
  13. {
  14. _hotWatch = hotWatch;
  15. _db = db;
  16. }
  17. public sealed class EnrollWorkOrderInput
  18. {
  19. public string WorkOrd { get; set; } = "";
  20. public string? Domain { get; set; }
  21. public long TenantId { get; set; }
  22. }
  23. [DisplayName("登记工单热回读")]
  24. [HttpPost("enroll-work-order")]
  25. public async Task<object> EnrollWorkOrder([FromBody] EnrollWorkOrderInput input, CancellationToken ct = default)
  26. {
  27. if (input == null || string.IsNullOrWhiteSpace(input.WorkOrd))
  28. throw Oops.Oh("WorkOrd 不能为空");
  29. var domain = string.IsNullOrWhiteSpace(input.Domain) ? "8010" : input.Domain.Trim();
  30. await _hotWatch.EnrollAsync(
  31. "WORK_ORDER",
  32. input.WorkOrd.Trim(),
  33. domain,
  34. new[] { "WorkOrdMaster", "WorkOrdRouting", "PeriodSequenceDet" },
  35. input.TenantId,
  36. ct: ct);
  37. return new { ok = true, workOrd = input.WorkOrd.Trim(), domain };
  38. }
  39. [DisplayName("热回读轮询一次")]
  40. [HttpPost("poll-once")]
  41. public async Task<object> PollOnce([FromQuery] int take = 100, CancellationToken ct = default)
  42. {
  43. var (polled, changed, terminated) = await _hotWatch.PollOnceAsync(take <= 0 ? 100 : take, ct);
  44. return new { ok = true, polled, changed, terminated };
  45. }
  46. public sealed class ForceRepollInput
  47. {
  48. public string BizKey { get; set; } = "";
  49. public string? BizType { get; set; }
  50. }
  51. /// <summary>清空快照哈希,下一轮 poll 必走变更写回(联调)。</summary>
  52. [DisplayName("强制重读业务键")]
  53. [HttpPost("force-repoll")]
  54. public async Task<object> ForceRepoll([FromBody] ForceRepollInput input, CancellationToken ct = default)
  55. {
  56. if (input == null || string.IsNullOrWhiteSpace(input.BizKey))
  57. throw Oops.Oh("BizKey 不能为空");
  58. var key = input.BizKey.Trim();
  59. var type = string.IsNullOrWhiteSpace(input.BizType) ? null : input.BizType.Trim();
  60. var q = _db.Queryable<AdoMdpHotWatch>().Where(x => x.BizKey == key && x.Status == 0);
  61. if (!string.IsNullOrWhiteSpace(type))
  62. q = q.Where(x => x.BizType == type);
  63. var rows = await q.ToListAsync(ct);
  64. foreach (var w in rows)
  65. {
  66. w.LastSnapshotHash = null;
  67. w.UpdateTime = DateTime.Now;
  68. await _db.Updateable(w)
  69. .UpdateColumns(x => new { x.LastSnapshotHash, x.UpdateTime })
  70. .ExecuteCommandAsync(ct);
  71. }
  72. var (polled, changed, terminated) = await _hotWatch.PollOnceAsync(Math.Max(100, rows.Count), ct);
  73. return new { ok = true, cleared = rows.Count, polled, changed, terminated };
  74. }
  75. }