AdoS8ConfigKpiTargetsController.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Admin.NET.Plugin.AiDOP.Infrastructure;
  2. using Admin.NET.Plugin.AiDOP.Service.S8;
  3. namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
  4. /// <summary>
  5. /// S9 KPI 目标值配置(S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1)。
  6. /// 复用 ado_s8_monitor_metric.default_target_ratio;只维护目标值,不涉及 KPI 当前值。
  7. /// 作用域:平台默认租户侧只读 → 自定义本工厂 → 恢复平台默认。
  8. /// </summary>
  9. [ApiController]
  10. [Route("api/aidop/s8/config/kpi-targets")]
  11. [NonUnify]
  12. public class AdoS8ConfigKpiTargetsController : ControllerBase
  13. {
  14. private readonly S8KpiTargetConfigService _svc;
  15. private readonly S8TrustedScopeResolver _scope;
  16. public AdoS8ConfigKpiTargetsController(S8KpiTargetConfigService svc, S8TrustedScopeResolver scope)
  17. {
  18. _svc = svc;
  19. _scope = scope;
  20. }
  21. /// <summary>列表:5 项 Result KPI 的生效目标值(工厂覆盖优先)。</summary>
  22. [HttpGet]
  23. public async Task<IActionResult> ListAsync()
  24. => Ok(await _svc.ListAsync(await _scope.ResolveAsync()));
  25. /// <summary>
  26. /// 自定义本工厂 / 编辑本工厂目标值。按 metricCode 定位,归属由服务端盖章。
  27. /// </summary>
  28. [HttpPut("{metricCode}/factory-override")]
  29. public async Task<IActionResult> UpsertFactoryOverrideAsync(string metricCode, [FromBody] AdoS8KpiTargetUpdateBody body)
  30. {
  31. try
  32. {
  33. return Ok(await _svc.UpsertFactoryOverrideAsync(
  34. metricCode, body?.TargetRatio ?? -1m, body?.Remark, await _scope.ResolveAsync()));
  35. }
  36. catch (S8NotFoundException) { return NotFound(); }
  37. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  38. }
  39. /// <summary>恢复平台默认:只删当前工厂覆盖行,平台默认行不受影响。</summary>
  40. [HttpDelete("{metricCode}/factory-override")]
  41. public async Task<IActionResult> ResetToGlobalDefaultAsync(string metricCode)
  42. {
  43. try { return Ok(await _svc.ResetToGlobalDefaultAsync(metricCode, await _scope.ResolveAsync())); }
  44. catch (S8NotFoundException) { return NotFound(); }
  45. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  46. }
  47. }
  48. /// <summary>S9 KPI 目标值编辑入参。只接受目标值与说明,归属字段一律不接受。</summary>
  49. public class AdoS8KpiTargetUpdateBody
  50. {
  51. /// <summary>目标值(百分比,0–100)。</summary>
  52. public decimal TargetRatio { get; set; }
  53. /// <summary>说明(可选)。</summary>
  54. public string? Remark { get; set; }
  55. }