using System.Text.Json;
namespace Admin.NET.Plugin.AiDOP.Controllers;
///
/// S9 API_OUT:受控只读 KPI 出站(字段白名单 + 访问日志)。禁止任意 SQL。
///
[ApiDescriptionSettings(Order = 330, Description = "MDP API_OUT 受控只读")]
[Route("api/aidop/out")]
[AllowAnonymous]
[NonUnify]
public class MdpApiOutController : IDynamicApiController, ITransient
{
private static readonly Dictionary ResourceSql = new(StringComparer.OrdinalIgnoreCase)
{
["kpi_l1_day"] = "SELECT metric_code, metric_value, biz_date, tenant_id, factory_id FROM ado_s9_kpi_value_l1_day WHERE tenant_id=@tid ORDER BY biz_date DESC LIMIT @limit",
["kpi_l2_day"] = "SELECT metric_code, metric_value, biz_date, tenant_id, factory_id FROM ado_s9_kpi_value_l2_day WHERE tenant_id=@tid ORDER BY biz_date DESC LIMIT @limit",
["kpi_l3_day"] = "SELECT metric_code, metric_value, biz_date, tenant_id, factory_id FROM ado_s9_kpi_value_l3_day WHERE tenant_id=@tid ORDER BY biz_date DESC LIMIT @limit",
["kpi_l4_day"] = "SELECT metric_code, metric_value, biz_date, tenant_id, factory_id FROM ado_s9_kpi_value_l4_day WHERE tenant_id=@tid ORDER BY biz_date DESC LIMIT @limit",
};
private readonly ISqlSugarClient _db;
public MdpApiOutController(ISqlSugarClient db) => _db = db;
[DisplayName("API_OUT 资源列表")]
[HttpGet("resources")]
public object ListResources() => new { resources = ResourceSql.Keys.OrderBy(x => x).ToArray() };
[DisplayName("API_OUT 查询")]
[HttpGet("{resourceCode}")]
public async Task