using Admin.NET.Plugin.AiDOP.Entity.S8; using Admin.NET.Plugin.AiDOP.Infrastructure; using Admin.NET.Plugin.AiDOP.Service.S8; namespace Admin.NET.Plugin.AiDOP.Controllers.S8; [ApiController] [Route("api/aidop/s8/config/dashboard-cells")] [NonUnify] public class AdoS8ConfigDashboardCellsController : ControllerBase { private readonly S8DashboardCellConfigService _svc; private readonly S8TrustedScopeResolver _scope; public AdoS8ConfigDashboardCellsController(S8DashboardCellConfigService svc, S8TrustedScopeResolver scope) { _svc = svc; _scope = scope; } [HttpGet] public async Task ListAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1) { // Compatibility-only. Security scope is resolved server-side. _ = tenantId; _ = factoryId; var scope = await _scope.ResolveAsync(); return Ok(await _svc.ListAsync(scope.TenantId, scope.FactoryId)); } [HttpPost] public async Task CreateAsync([FromBody] AdoS8DashboardCellConfig body) { try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); } catch (S8NotFoundException) { return NotFound(); } catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); } } [HttpPut("{id:long}")] public async Task UpdateAsync(long id, [FromBody] AdoS8DashboardCellConfig body) { try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); } catch (S8NotFoundException) { return NotFound(); } catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); } } [HttpDelete("{id:long}")] public async Task DeleteAsync(long id) { try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); } catch (S8NotFoundException) { return NotFound(); } return Ok(); } /// /// S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1:自定义本工厂。 /// 入参是平台默认行的 Id;服务端复制其业务字段并盖章可信租户 / 工厂,存为工厂覆盖行。 /// 平台默认行不被修改。 /// [HttpPost("{globalId:long}/factory-override")] public async Task CreateFactoryOverrideAsync(long globalId) { try { return Ok(await _svc.CreateFactoryOverrideAsync(globalId, await _scope.ResolveAsync())); } catch (S8NotFoundException) { return NotFound(); } catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); } } /// /// S8-CONFIG-GLOBAL-ROW-SEMANTICS-AND-KPI-TARGET-1:恢复平台默认。 /// 入参是当前工厂覆盖行的 Id;只删除该覆盖行,平台默认行不受影响。 /// [HttpDelete("{overrideId:long}/factory-override")] public async Task ResetToGlobalDefaultAsync(long overrideId) { try { await _svc.ResetToGlobalDefaultAsync(overrideId, await _scope.ResolveAsync()); return Ok(new { overrideId, reset = true }); } catch (S8NotFoundException) { return NotFound(); } catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); } } }