Commit 4d875969 authored by 黄奎's avatar 黄奎

新增功能权限验证

parent 58053a1f
...@@ -94,5 +94,10 @@ namespace Edu.Model.CacheModel ...@@ -94,5 +94,10 @@ namespace Edu.Model.CacheModel
/// 岗位名称 /// 岗位名称
/// </summary> /// </summary>
public string PostName { get; set; } public string PostName { get; set; }
/// <summary>
/// 功能权限列表
/// </summary>
public object ActionMenuList { get; set; }
} }
} }
\ No newline at end of file
...@@ -11,5 +11,10 @@ namespace Edu.Model.ViewModel.System ...@@ -11,5 +11,10 @@ namespace Edu.Model.ViewModel.System
/// 菜单名称 /// 菜单名称
/// </summary> /// </summary>
public string MenuName { get; set; } public string MenuName { get; set; }
/// <summary>
/// 菜单列表
/// </summary>
public string MenuUrl { get; set; }
} }
} }
...@@ -251,6 +251,27 @@ namespace Edu.Module.System ...@@ -251,6 +251,27 @@ namespace Edu.Module.System
return functionRepository.GetMenuFunctionListRepository(query); return functionRepository.GetMenuFunctionListRepository(query);
} }
/// <summary>
/// 根据岗位编号获取岗位角色菜单功能权限
/// </summary>
/// <param name="postIds">岗位编号</param>
/// <returns></returns>
public List<RB_Menu_Function_ViewModel> GetPostMenuFunctionListModule(string postIds)
{
return functionRepository.GetPostMenuFunctionListRepository(postIds);
}
/// <summary>
/// 判断用户是否有某项功能权限
/// </summary>
/// <param name="actionCode">权限编码</param>
/// <param name="postIds">岗位编号【可以多个】</param>
/// <returns></returns>
public bool CheckUserFunctionModule(string actionCode, string postIds)
{
return functionRepository.CheckUserFunctionRepository(actionCode, postIds);
}
/// <summary> /// <summary>
/// 新增修改菜单功能权限 /// 新增修改菜单功能权限
/// </summary> /// </summary>
......
using Edu.Common.Enum; using Edu.Common.Enum;
using Edu.Model.Entity.System; using Edu.Model.Entity.System;
using Edu.Model.ViewModel.System; using Edu.Model.ViewModel.System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -78,5 +79,44 @@ WHERE 1=1 ...@@ -78,5 +79,44 @@ WHERE 1=1
return new List<RB_Menu_Function_ViewModel>(); return new List<RB_Menu_Function_ViewModel>();
} }
} }
/// <summary>
/// 根据岗位编号获取岗位角色菜单功能权限
/// </summary>
/// <param name="postIds">岗位编号</param>
/// <returns></returns>
public List<RB_Menu_Function_ViewModel> GetPostMenuFunctionListRepository(string postIds)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*,IFNULL(B.MenuName,'') AS MenuName,IFNULL(B.MenuUrl,'') AS MenuUrl
FROM RB_Menu_Function AS A LEFT JOIN rb_menu AS B ON A.MenuId=B.MenuId
WHERE 1=1 AND A.Id IN(SELECT Action_Id FROM rb_role_functionpermission WHERE Role_Id IN (SELECT RoleId FROM rb_post_role WHERE PostId IN({0})))
", postIds);
return Get<RB_Menu_Function_ViewModel>(builder.ToString()).ToList();
}
/// <summary>
/// 判断用户是否有某项功能权限
/// </summary>
/// <param name="actionCode">权限编码</param>
/// <param name="postIds">岗位编号【可以多个】</param>
/// <returns></returns>
public bool CheckUserFunctionRepository(string actionCode, string postIds)
{
int result = 0;
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT 1
FROM RB_Menu_Function AS A
WHERE 1=1 AND A.FunctionCode='{0}' AND A.Id IN(SELECT Action_Id FROM rb_role_functionpermission WHERE Role_Id IN (SELECT RoleId FROM rb_post_role WHERE PostId IN({1})))
", actionCode.Trim(), postIds);
var obj = base.ExecuteScalar(builder.ToString());
if (obj != null)
{
Int32.TryParse(obj.ToString(), out result);
}
return result > 0;
}
} }
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ using Newtonsoft.Json; ...@@ -8,6 +8,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Edu.Model.CacheModel; using Edu.Model.CacheModel;
using Edu.Cache.User; using Edu.Cache.User;
using Edu.Module.System;
namespace Edu.WebApi.Controllers namespace Edu.WebApi.Controllers
{ {
...@@ -17,6 +18,10 @@ namespace Edu.WebApi.Controllers ...@@ -17,6 +18,10 @@ namespace Edu.WebApi.Controllers
[EnableCors("AllowCors")] [EnableCors("AllowCors")]
public class BaseController : ControllerBase public class BaseController : ControllerBase
{ {
/// <summary>
/// 菜单处理类对象
/// </summary>
private readonly MenuModule menuModule = new MenuModule();
/// <summary> /// <summary>
/// 整理前端传递的post参数 /// 整理前端传递的post参数
...@@ -72,5 +77,20 @@ namespace Edu.WebApi.Controllers ...@@ -72,5 +77,20 @@ namespace Edu.WebApi.Controllers
return userInfo; return userInfo;
} }
} }
/// <summary>
/// 判断用户是否有功能权限
/// </summary>
/// <param name="actionCode">权限编码</param>
/// <returns></returns>
public bool CheckUserActionAuth(string actionCode)
{
bool flag = false;
if (this.UserInfo != null && this.UserInfo.PostId > 0)
{
flag = menuModule.CheckUserFunctionModule(actionCode, this.UserInfo.PostId.ToString());
}
return flag;
}
} }
} }
\ No newline at end of file
...@@ -91,6 +91,8 @@ namespace Edu.WebApi.Controllers.User ...@@ -91,6 +91,8 @@ namespace Edu.WebApi.Controllers.User
{ {
MenuType = accountType MenuType = accountType
}, postIds: model.Post_Id.ToString()); }, postIds: model.Post_Id.ToString());
//获取功能权限列表
var actionList = menuModule.GetPostMenuFunctionListModule(model.Post_Id.ToString());
UserInfo obj = new UserInfo UserInfo obj = new UserInfo
{ {
Id = model.Id, Id = model.Id,
...@@ -110,6 +112,7 @@ namespace Edu.WebApi.Controllers.User ...@@ -110,6 +112,7 @@ namespace Edu.WebApi.Controllers.User
DeptName = model.DeptName, DeptName = model.DeptName,
PostId = model.Post_Id, PostId = model.Post_Id,
PostName = model.PostName, PostName = model.PostName,
ActionMenuList= actionList?.Select(qitem => new {qitem.FunctionCode,qitem.FunctionName,qitem.MenuName,qitem.MenuUrl }),
}; };
UserReidsCache.UserInfoSet(Cache.CacheKey.User_Login_Key + model.Id, obj, Common.Config.JwtExpirTime); UserReidsCache.UserInfoSet(Cache.CacheKey.User_Login_Key + model.Id, obj, Common.Config.JwtExpirTime);
return ApiResult.Success(data: obj); return ApiResult.Success(data: obj);
...@@ -143,6 +146,9 @@ namespace Edu.WebApi.Controllers.User ...@@ -143,6 +146,9 @@ namespace Edu.WebApi.Controllers.User
MenuType = (int)userInfo.AccountType MenuType = (int)userInfo.AccountType
}, userInfo.PostId.ToString()); }, userInfo.PostId.ToString());
userInfo.MenuList = treeList; userInfo.MenuList = treeList;
//获取功能权限列表
var actionList = menuModule.GetPostMenuFunctionListModule(userInfo.PostId.ToString());
userInfo.ActionMenuList = actionList?.Select(qitem => new { qitem.FunctionCode, qitem.FunctionName, qitem.MenuName, qitem.MenuUrl });
} }
return ApiResult.Success(data: userInfo); return ApiResult.Success(data: userInfo);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment