namespace Yw.Application
|
{
|
/// <summary>
|
/// RoleProjectMenuMapping
|
/// </summary>
|
[Route("Auth/Role/Project/Menu/Mapping")]
|
[ApiDescriptionSettings("Auth", Name = "角色与项目菜单映射", Order = 5900)]
|
public class RoleProjectMenu_Controller : IDynamicApiController
|
{
|
private Service.RoleProjectMenuMapping _service = new();
|
|
/// <summary>
|
/// 获取产品下发菜单列表
|
/// </summary>
|
[Route("GetAuthorizeMenuList@V1.0")]
|
[HttpGet]
|
public List<RoleProjectMenuHaveDto> GetAuthorizeMenuList([FromQuery][Required] QueryProjectAuthorizeMenuListInput input)
|
{
|
var project = new Service.Project().GetByID(input.ProjectID);
|
if (project == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ProjectID:{input.ProjectID} 数据不存在");
|
}
|
|
var role = new Service.Role().GetByID(input.RoleID);
|
if (role == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
|
}
|
|
var bol = new Service.ProjectRoleMapping().IsExistByProjectIDAndRoleID(input.ProjectID, input.RoleID);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, $"ProjectID:{input.ProjectID}, RoleID:{input.RoleID},项目角色不匹配");
|
}
|
|
var dict = _service.GetAuthorizeMenuList(input.ProjectID, input.RoleID);
|
if (dict == null || dict.Count < 1)
|
{
|
return default;
|
}
|
|
var vmList = new List<RoleProjectMenuHaveDto>();
|
foreach (var item in dict)
|
{
|
var vm = new RoleProjectMenuHaveDto(item.Key, item.Value);
|
var vmParent = vmList.Find(x => x.ID == vm.ParentID);
|
if (vmParent != null)
|
{
|
if (vm.Have)
|
{
|
vmParent.Have = true;
|
}
|
}
|
vmList.Add(vm);
|
}
|
return vmList;
|
}
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
[Route("Set@V1.0")]
|
[HttpPost]
|
public bool Set([Required] SetRoleProjectMenuInput input)
|
{
|
var project = new Service.Project().GetByID(input.ProjectID);
|
if (project == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ProjectID:{input.ProjectID} 数据不存在");
|
}
|
|
var role = new Service.Role().GetByID(input.RoleID);
|
if (role == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"RoleID:{input.RoleID} 数据不存在");
|
}
|
|
var exist = new Service.ProjectRoleMapping().IsExistByProjectIDAndRoleID(input.ProjectID, input.RoleID);
|
if (!exist)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, $"ProjectID:{input.ProjectID}, RoleID:{input.RoleID},项目角色不匹配");
|
}
|
|
if (input.MenuIds != null && input.MenuIds.Count > 0)
|
{
|
var menuList = new Service.ProjectMenu().GetByIds(input.MenuIds);
|
if (menuList == null || menuList.Count < 1)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "菜单id列表与数据库不匹配");
|
}
|
var projectIds = menuList.Select(x => x.ProjectID).Distinct().ToList();
|
if (projectIds.Count != 1 || projectIds[0] != project.ID)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "菜单id列表与数据库不匹配");
|
}
|
}
|
|
var bol = _service.Set(input.RoleID, input.ProjectID, input.MenuIds);
|
return bol;
|
}
|
|
|
|
|
}
|
}
|