AdoS8DashboardController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Admin.NET.Plugin.AiDOP.Dto.S8;
  2. using Admin.NET.Plugin.AiDOP.Infrastructure;
  3. using Admin.NET.Plugin.AiDOP.Service.S8;
  4. namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
  5. [ApiController]
  6. [Route("api/aidop/s8/dashboard")]
  7. [NonUnify]
  8. public class AdoS8DashboardController : ControllerBase
  9. {
  10. private readonly S8DashboardService _svc;
  11. private readonly S8DashboardCellDataService _cellSvc;
  12. private readonly S8DashboardCellConfigService _cfgSvc;
  13. private readonly S8TrustedScopeResolver _scope;
  14. public AdoS8DashboardController(
  15. S8DashboardService svc,
  16. S8DashboardCellDataService cellSvc,
  17. S8DashboardCellConfigService cfgSvc,
  18. S8TrustedScopeResolver scope)
  19. {
  20. _svc = svc;
  21. _cellSvc = cellSvc;
  22. _cfgSvc = cfgSvc;
  23. _scope = scope;
  24. }
  25. // S8-TENANT-FACTORY-P0-CLOSURE-1:以下 tenantId / factoryId 入参
  26. // Compatibility-only. Security scope is resolved server-side.
  27. [HttpGet("overview")]
  28. public async Task<IActionResult> OverviewAsync(
  29. [FromQuery] long tenantId = 1,
  30. [FromQuery] long factoryId = 1,
  31. [FromQuery] DateTime? beginTime = null,
  32. [FromQuery] DateTime? endTime = null,
  33. [FromQuery] string? severity = null,
  34. [FromQuery] string? period = null)
  35. {
  36. _ = tenantId; _ = factoryId;
  37. var scope = await _scope.ResolveAsync();
  38. return Ok(await _svc.GetOverviewAsync(scope.TenantId, scope.FactoryId, beginTime, endTime, severity, period));
  39. }
  40. [HttpGet("trends")]
  41. public async Task<IActionResult> TrendsAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1,
  42. [FromQuery] int days = 14, [FromQuery] string? period = null)
  43. {
  44. _ = tenantId; _ = factoryId;
  45. var scope = await _scope.ResolveAsync();
  46. return Ok(await _svc.GetTrendsAsync(scope.TenantId, scope.FactoryId, days, period));
  47. }
  48. [HttpGet("distributions")]
  49. public async Task<IActionResult> DistributionsAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1, [FromQuery] string? period = null)
  50. {
  51. _ = tenantId; _ = factoryId;
  52. var scope = await _scope.ResolveAsync();
  53. return Ok(await _svc.GetDistributionsAsync(scope.TenantId, scope.FactoryId, period));
  54. }
  55. [HttpGet("quick-exceptions")]
  56. public async Task<IActionResult> QuickExceptionsAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1,
  57. [FromQuery] string mode = "latest")
  58. {
  59. _ = tenantId; _ = factoryId;
  60. var scope = await _scope.ResolveAsync();
  61. return Ok(await _svc.GetQuickExceptionsAsync(scope.TenantId, scope.FactoryId, mode));
  62. }
  63. [HttpGet("dept-backlog")]
  64. public async Task<IActionResult> DeptBacklogAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1, [FromQuery] string? period = null)
  65. {
  66. _ = tenantId; _ = factoryId;
  67. var scope = await _scope.ResolveAsync();
  68. return Ok(await _svc.GetDeptBacklogAsync(scope.TenantId, scope.FactoryId, period));
  69. }
  70. [HttpGet("dim-trends")]
  71. public async Task<IActionResult> DimTrendsAsync(
  72. [FromQuery] long tenantId = 1,
  73. [FromQuery] long factoryId = 1,
  74. [FromQuery] string dim = "object",
  75. [FromQuery] int days = 14,
  76. [FromQuery] string? period = null)
  77. {
  78. _ = tenantId; _ = factoryId;
  79. var scope = await _scope.ResolveAsync();
  80. return Ok(await _svc.GetDimTrendsAsync(scope.TenantId, scope.FactoryId, dim, days, period));
  81. }
  82. /// <summary>
  83. /// 按配置获取单个大屏卡片的数据。配置来源 ado_s8_dashboard_cell_config。
  84. /// </summary>
  85. [HttpGet("cell-data")]
  86. public async Task<IActionResult> CellDataAsync([FromQuery] AdoS8CellDataQueryDto q)
  87. {
  88. try
  89. {
  90. var scope = await _scope.ResolveAsync();
  91. q.TenantId = scope.TenantId;
  92. q.FactoryId = scope.FactoryId;
  93. return Ok(await _cellSvc.GetAsync(q));
  94. }
  95. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  96. }
  97. /// <summary>
  98. /// 按页面编码获取大屏页面结构配置(G-09 一期:四屏启动渲染入口)。
  99. /// 只返回 enabled=true 的 cell,按 layout_area + sort_no 排序。
  100. /// 不替代 cell-data,不触发 ado_s8_exception 查询。
  101. /// </summary>
  102. [HttpGet("page-config")]
  103. public async Task<IActionResult> PageConfigAsync([FromQuery] AdoS8PageConfigQueryDto q)
  104. {
  105. try
  106. {
  107. var scope = await _scope.ResolveAsync();
  108. q.TenantId = scope.TenantId;
  109. q.FactoryId = scope.FactoryId;
  110. return Ok(await _cfgSvc.GetPageConfigAsync(q));
  111. }
  112. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  113. }
  114. }