代码拉取完成,页面将自动刷新
同步操作将从 magicodes/CodeSpirit 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using CodeSpirit.Core;
using CodeSpirit.IdentityApi.Constants;
using CodeSpirit.IdentityApi.Controllers;
using CodeSpirit.IdentityApi.Dtos.Role;
using CodeSpirit.IdentityApi.Services;
using CodeSpirit.Shared.Dtos.Common;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
[DisplayName("角色管理")]
[Page(Label = "角色管理", ParentLabel = "用户中心", Icon = "fa-solid fa-user-shield", PermissionCode = PermissionCodes.RoleManagement)]
[Permission(code: PermissionCodes.RoleManagement)]
public class RolesController : ApiControllerBase
{
private readonly IRoleService _roleService;
public RolesController(IRoleService roleService)
{
_roleService = roleService;
}
[HttpGet]
public async Task<ActionResult<ApiResponse<PageList<RoleDto>>>> GetRoles([FromQuery] RoleQueryDto queryDto)
{
PageList<RoleDto> result = await _roleService.GetRolesAsync(queryDto);
return SuccessResponse(result);
}
[HttpGet("{id}")]
public async Task<ActionResult<ApiResponse<RoleDto>>> GetRole(long id)
{
RoleDto role = await _roleService.GetAsync(id);
return SuccessResponse(role);
}
[HttpPost]
public async Task<ActionResult<ApiResponse<RoleDto>>> Create(RoleCreateDto createDto)
{
RoleDto roleDto = await _roleService.CreateAsync(createDto);
return SuccessResponseWithCreate<RoleDto>(nameof(GetRole), roleDto);
}
[HttpPut("{id}")]
public async Task<ActionResult<ApiResponse>> Update(long id, RoleUpdateDto updateDto)
{
await _roleService.UpdateAsync(id, updateDto);
return SuccessResponse();
}
[HttpDelete("{id}")]
[Operation("删除角色", "ajax", null, "确定要删除此角色吗?", "permissionIds.length == 0")]
public async Task<ActionResult<ApiResponse>> Delete(long id)
{
await _roleService.DeleteAsync(id);
return SuccessResponse();
}
/// <summary>
/// 批量导入角色
/// </summary>
/// <param name="importDto">批量导入角色 DTO 列表</param>
/// <returns>操作结果</returns>
[HttpPost("batch/import")]
public async Task<ActionResult<ApiResponse>> BatchImport([FromBody] BatchImportDtoBase<RoleBatchImportItemDto> importDto)
{
(int successCount, List<string> failedIds) = await _roleService.BatchImportRolesAsync(importDto.ImportData);
return failedIds.Count > 0
? SuccessResponse($"角色批量导入完成。成功:{successCount}个,失败:{failedIds.Count}个。失败的角色:{string.Join(", ", failedIds)}")
: SuccessResponse($"角色批量导入成功,共导入{successCount}个角色");
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。