| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- using Admin.NET.Plugin.AiDOP.Service.S8;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
- /// <summary>
- /// S9 KPI 目标值配置(S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1)。
- /// 复用 ado_s8_monitor_metric.default_target_ratio;只维护目标值,不涉及 KPI 当前值。
- /// 作用域:平台默认租户侧只读 → 自定义本工厂 → 恢复平台默认。
- /// </summary>
- [ApiController]
- [Route("api/aidop/s8/config/kpi-targets")]
- [NonUnify]
- public class AdoS8ConfigKpiTargetsController : ControllerBase
- {
- private readonly S8KpiTargetConfigService _svc;
- private readonly S8TrustedScopeResolver _scope;
- public AdoS8ConfigKpiTargetsController(S8KpiTargetConfigService svc, S8TrustedScopeResolver scope)
- {
- _svc = svc;
- _scope = scope;
- }
- /// <summary>列表:5 项 Result KPI 的生效目标值(工厂覆盖优先)。</summary>
- [HttpGet]
- public async Task<IActionResult> ListAsync()
- => Ok(await _svc.ListAsync(await _scope.ResolveAsync()));
- /// <summary>
- /// 自定义本工厂 / 编辑本工厂目标值。按 metricCode 定位,归属由服务端盖章。
- /// </summary>
- [HttpPut("{metricCode}/factory-override")]
- public async Task<IActionResult> UpsertFactoryOverrideAsync(string metricCode, [FromBody] AdoS8KpiTargetUpdateBody body)
- {
- try
- {
- return Ok(await _svc.UpsertFactoryOverrideAsync(
- metricCode, body?.TargetRatio ?? -1m, body?.Remark, await _scope.ResolveAsync()));
- }
- catch (S8NotFoundException) { return NotFound(); }
- catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
- }
- /// <summary>恢复平台默认:只删当前工厂覆盖行,平台默认行不受影响。</summary>
- [HttpDelete("{metricCode}/factory-override")]
- public async Task<IActionResult> ResetToGlobalDefaultAsync(string metricCode)
- {
- try { return Ok(await _svc.ResetToGlobalDefaultAsync(metricCode, await _scope.ResolveAsync())); }
- catch (S8NotFoundException) { return NotFound(); }
- catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
- }
- }
- /// <summary>S9 KPI 目标值编辑入参。只接受目标值与说明,归属字段一律不接受。</summary>
- public class AdoS8KpiTargetUpdateBody
- {
- /// <summary>目标值(百分比,0–100)。</summary>
- public decimal TargetRatio { get; set; }
- /// <summary>说明(可选)。</summary>
- public string? Remark { get; set; }
- }
|