1
This commit is contained in:
154
iMES.WebApi/Controllers/System/Partial/Sys_RoleController.cs
Normal file
154
iMES.WebApi/Controllers/System/Partial/Sys_RoleController.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using iMES.Core.Controllers.Basic;
|
||||
using iMES.Core.Enums;
|
||||
using iMES.Core.Extensions;
|
||||
using iMES.Core.Filters;
|
||||
using iMES.Core.ManageUser;
|
||||
using iMES.Core.UserManager;
|
||||
using iMES.Core.Utilities;
|
||||
using iMES.Entity.AttributeManager;
|
||||
using iMES.Entity.DomainModels;
|
||||
using iMES.System.IServices;
|
||||
using iMES.System.Repositories;
|
||||
using iMES.System.Services;
|
||||
|
||||
namespace iMES.System.Controllers
|
||||
{
|
||||
[Route("api/role")]
|
||||
public partial class Sys_RoleController
|
||||
{
|
||||
[HttpPost, Route("getCurrentTreePermission")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
public async Task<IActionResult> GetCurrentTreePermission()
|
||||
{
|
||||
return Json(await Service.GetCurrentTreePermission());
|
||||
}
|
||||
|
||||
[HttpPost, Route("getUserTreePermission")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
public async Task<IActionResult> GetUserTreePermission(int roleId)
|
||||
{
|
||||
return Json(await Service.GetUserTreePermission(roleId));
|
||||
}
|
||||
|
||||
[HttpPost, Route("savePermission")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Update)]
|
||||
public async Task<IActionResult> SavePermission([FromBody] List<UserPermissions> userPermissions, int roleId)
|
||||
{
|
||||
return Json(await Service.SavePermission(userPermissions, roleId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前角色下的所有角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost, Route("getUserChildRoles")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
public IActionResult GetUserChildRoles()
|
||||
{
|
||||
int roleId = UserContext.Current.RoleId;
|
||||
var data = RoleContext.GetAllChildren(UserContext.Current.RoleId);
|
||||
|
||||
if (UserContext.Current.IsSuperAdmin)
|
||||
{
|
||||
return Json(WebResponseContent.Instance.OK(null, data));
|
||||
}
|
||||
//不是超级管理,将自己的角色查出来,在树形菜单上作为根节点
|
||||
var self = Sys_RoleRepository.Instance.FindAsIQueryable(x => x.Role_Id == roleId)
|
||||
.Select(s => new iMES.Core.UserManager.RoleNodes()
|
||||
{
|
||||
Id = s.Role_Id,
|
||||
ParentId = 0,//将自己的角色作为root节点
|
||||
RoleName = s.RoleName
|
||||
}).ToList();
|
||||
data.AddRange(self);
|
||||
return Json(WebResponseContent.Instance.OK(null, data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// treetable 获取子节点数据(2021.05.02)
|
||||
/// </summary>
|
||||
/// <param name="loadData"></param>
|
||||
/// <returns></returns>
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
[HttpPost, Route("GetPageData")]
|
||||
public override ActionResult GetPageData([FromBody] PageDataOptions loadData)
|
||||
{
|
||||
//获取根节点数据(对应Sys_Role1.js中searchBefore方法)
|
||||
if (loadData.Value.GetInt() == 1)
|
||||
{
|
||||
return GetTreeTableRootData(loadData).Result;
|
||||
}
|
||||
return base.GetPageData(loadData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// treetable 获取子节点数据(2021.05.02)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("getTreeTableRootData")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
public async Task<ActionResult> GetTreeTableRootData([FromBody] PageDataOptions options)
|
||||
{
|
||||
//页面加载根节点数据条件x => x.ParentId == 0,自己根据需要设置
|
||||
var query = Sys_RoleRepository.Instance.FindAsIQueryable(x => x.ParentId == 0);
|
||||
var rows = await query.TakeOrderByPage(options.Page, options.Rows)
|
||||
.OrderBy(x => x.Role_Id).Select(s => new
|
||||
{
|
||||
s.Role_Id,
|
||||
s.ParentId,
|
||||
s.RoleName,
|
||||
s.DeptName,
|
||||
s.Dept_Id,
|
||||
s.Enable,
|
||||
s.CreateDate,
|
||||
s.Creator,
|
||||
s.Modifier,
|
||||
s.ModifyDate,
|
||||
s.OrderNo,
|
||||
hasChildren = true
|
||||
}).ToListAsync();
|
||||
return JsonNormal(new { total = await query.CountAsync(), rows });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///treetable 获取子节点数据(2021.05.02)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("getTreeTableChildrenData")]
|
||||
[ApiActionPermission(ActionPermissionOptions.Search)]
|
||||
public async Task<ActionResult> GetTreeTableChildrenData(int roleId)
|
||||
{
|
||||
//点击节点时,加载子节点数据
|
||||
var roleRepository = Sys_RoleRepository.Instance.FindAsIQueryable(x => true);
|
||||
var rows = await roleRepository.Where(x => x.ParentId == roleId)
|
||||
.Select(s => new
|
||||
{
|
||||
s.Role_Id,
|
||||
s.ParentId,
|
||||
s.RoleName,
|
||||
s.DeptName,
|
||||
s.Dept_Id,
|
||||
s.Enable,
|
||||
s.CreateDate,
|
||||
s.Creator,
|
||||
s.Modifier,
|
||||
s.ModifyDate,
|
||||
s.OrderNo,
|
||||
hasChildren = roleRepository.Any(x => x.ParentId == s.Role_Id)
|
||||
}).ToListAsync();
|
||||
return JsonNormal(new { rows });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user