| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> DeleteAsync(long id)
- {
- try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); }
- catch (S8NotFoundException) { return NotFound(); }
- return Ok();
- }
- /// <summary>
- /// 从系统角色表一键导入,返回本次新增条数。
- /// </summary>
- [HttpPost("import-from-sys")]
- public async Task<IActionResult> 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) });
- }
- }
|