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/roles")] [NonUnify] public class AdoS8ConfigRolesController : ControllerBase { private readonly S8RoleConfigService _svc; private readonly S8TrustedScopeResolver _scope; public AdoS8ConfigRolesController(S8RoleConfigService 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] AdoS8RolePermissionConfig 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] AdoS8RolePermissionConfig 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(); } /// /// 从系统角色表一键导入,返回本次新增条数。 /// [HttpPost("import-from-sys")] public async Task ImportFromSysAsync( [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(new { imported = await _svc.ImportFromSysRolesAsync(scope.TenantId, scope.FactoryId) }); } }