namespace Yw.Application
|
{
|
/// <summary>
|
/// RoleUserMapping
|
/// </summary>
|
[Route("Auth/Role/User/Mapping")]
|
[ApiDescriptionSettings("Auth", Name = "角色与用户映射", Order = 5800)]
|
public class RoleUser_Controller : IDynamicApiController
|
{
|
private readonly Service.UserRoleMapping _service = new();
|
|
/// <summary>
|
/// 获取下发用户列表
|
/// </summary>
|
[Route("GetAuthorizeUserList@V1.0")]
|
[HttpGet]
|
public List<RoleUserHaveDto> GetAuthorizeUserList([FromQuery][Required] RoleIDInput input)
|
{
|
var role = new Service.Role().GetByID(input.RoleID);
|
if (role == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
|
}
|
var dict = _service.GetAuthorizeUserList(input.RoleID);
|
if (dict.Count < 1)
|
{
|
return default;
|
}
|
var vmList = new List<RoleUserHaveDto>();
|
foreach (var item in dict)
|
{
|
var vm = new RoleUserHaveDto(item.Key, item.Value);
|
vmList.Add(vm);
|
}
|
return vmList;
|
}
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
[Route("Set@V1.0")]
|
[HttpPost]
|
public bool Set([Required] SetRoleUserInput input)
|
{
|
var role = new Service.Role().GetByID(input.RoleID);
|
if (role == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
|
}
|
if (input.UserIds != null && input.UserIds.Count > 0)
|
{
|
var userList = new Service.User().GetByIds(input.UserIds);
|
if (userList == null || userList.Count < 1)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"用户id列表与数据库不匹配");
|
}
|
var corpIds = userList.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count != 1 || corpIds[0] != role.CorpID)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"用户id列表与数据库不匹配");
|
}
|
}
|
|
var bol = _service.SetByRole(input.RoleID, input.UserIds);
|
return bol;
|
}
|
|
|
|
}
|
}
|