重构代码:重写梳理BASQLHelper静态类方法缓存逻辑移动到Helper类中
This commit is contained in:
parent
2a39f1db4c
commit
53b2a2e666
|
@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
|
||||
break;
|
||||
case "user":
|
||||
ret = MenuHelper.RetrieveAllMenus(User.Identity.Name).ToList();
|
||||
ret = MenuHelper.RetrieveMenus(User.Identity.Name).ToList();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Key": "BootstrapMenu-RetrieveMenusByUserName",
|
||||
"Key": "BootstrapMenu-RetrieveMenus",
|
||||
"Interval": 600,
|
||||
"SlidingExpiration": true,
|
||||
"Desc": "用户所有菜单数据缓存"
|
||||
|
|
|
@ -32,9 +32,9 @@ namespace Bootstrap.DataAccess
|
|||
cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
}
|
||||
if (userIds != null)
|
||||
{
|
||||
|
@ -42,8 +42,8 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
});
|
||||
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
||||
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
||||
|
@ -57,8 +57,8 @@ namespace Bootstrap.DataAccess
|
|||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||
}
|
||||
if (menuIds != null)
|
||||
|
@ -68,8 +68,8 @@ namespace Bootstrap.DataAccess
|
|||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
||||
});
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
|
||||
cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
corsKeys.Add(MenuHelper.RetrieveMenusAll + "*");
|
||||
}
|
||||
if (dictIds != null)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.SQLServer;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
|
@ -17,10 +19,6 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public const string RetrieveMenusDataKey = "BootstrapMenu-RetrieveMenusByUserName";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus";
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -35,20 +33,17 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public static bool DeleteMenu(IEnumerable<int> value) => DbAdapterManager.Create<Menu>().DeleteMenu(value);
|
||||
/// <summary>
|
||||
///
|
||||
/// 通过用户名获得所有菜单
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName) => DbAdapterManager.Create<Menu>().RetrieveMenusByUserName(userName);
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName) => RetrieveAllMenus(userName);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
||||
{
|
||||
return CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
|
||||
}
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -60,21 +55,50 @@ namespace Bootstrap.DataAccess
|
|||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string url) => DbAdapterManager.Create<Menu>().RetrieveAppMenus(appId, userName, url);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="activeUrl"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null) => DbAdapterManager.Create<Menu>().RetrieveSystemMenus(userName, activeUrl);
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string activeUrl)
|
||||
{
|
||||
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0);
|
||||
if (appId != "0") menus = menus.Where(m => m.ApplicationCode == appId);
|
||||
BASQLHelper.ActiveMenu(null, menus, activeUrl);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 通过当前用户名获得后台菜单,层次化后集合
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <param name="activeUrl">当前访问菜单</param>
|
||||
/// <param name="connName">连接字符串名称,默认为ba</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string name) => DbAdapterManager.Create<Menu>().RetrieveAllMenus(name);
|
||||
public static IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null)
|
||||
{
|
||||
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0);
|
||||
BASQLHelper.ActiveMenu(null, menus, activeUrl);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得所有菜单,层次化后集合
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveMenus(string userName)
|
||||
{
|
||||
var menus = RetrieveAllMenus(userName);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过用户获得所有菜单
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbAdapterManager.Create<Menu>().RetrieveAllMenus(userName), RetrieveMenusAll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,45 +136,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 通过当前用户名获得所有菜单,层次化后集合
|
||||
/// </summary>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <param name="activeUrl">当前访问菜单</param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName, string activeUrl = null)
|
||||
{
|
||||
var menus = RetrieveMenusByUserName(userName, activeUrl);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.Category).ThenBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得前台菜单,层次化后集合
|
||||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <param name="activeUrl">当前访问菜单</param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string activeUrl = null) => BASQLHelper.RetrieveAppMenus(appId, userName, activeUrl);
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得后台菜单,层次化后集合
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <param name="activeUrl">当前访问菜单</param>
|
||||
/// <param name="connName">连接字符串名称,默认为ba</param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null)
|
||||
{
|
||||
var menus = RetrieveMenusByUserName(userName, activeUrl).Where(m => m.Category == "0" && m.IsResource == 0);
|
||||
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||
BASQLHelper.CascadeMenus(menus, root);
|
||||
return root;
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过当前用户名获得所有菜单
|
||||
/// </summary>
|
||||
/// <param name="userName">当前登陆的用户名</param>
|
||||
/// <param name="activeUrl">当前访问菜单</param>
|
||||
/// <param name="appId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName, string activeUrl = null, string appId = "0") => BASQLHelper.RetrieveMenusByUserName(userName, activeUrl, appId);
|
||||
public virtual IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => BASQLHelper.RetrieveAllMenus(userName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue