From 33e9c09c01d0cf04a91fce663b53bc693e302f39 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Sun, 28 Oct 2018 21:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E6=95=B4=E7=90=86Bootstrap.Security.Client=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Client.DataAccess.csproj | 1 + Bootstrap.Client.DataAccess/DictHelper.cs | 10 ++++- Bootstrap.Client.DataAccess/MenuHelper.cs | 25 +++++++++++-- Bootstrap.Client.DataAccess/RoleHelper.cs | 10 +++-- Bootstrap.Client.DataAccess/UserHelper.cs | 4 +- Bootstrap.Client/appsettings.json | 37 ++++++++----------- 6 files changed, 56 insertions(+), 31 deletions(-) diff --git a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index e0456f90..6d40feb5 100644 --- a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -12,6 +12,7 @@ + diff --git a/Bootstrap.Client.DataAccess/DictHelper.cs b/Bootstrap.Client.DataAccess/DictHelper.cs index 07e7fdee..5f196621 100644 --- a/Bootstrap.Client.DataAccess/DictHelper.cs +++ b/Bootstrap.Client.DataAccess/DictHelper.cs @@ -1,5 +1,6 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; +using Longbow.Cache; using Longbow.Configuration; using System; using System.Collections.Generic; @@ -12,6 +13,13 @@ namespace Bootstrap.Client.DataAccess /// public static class DictHelper { + /// + /// + /// + /// + /// 缓存索引,BootstrapAdmin后台清理缓存时使用 + /// + public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts"; /// /// /// @@ -48,7 +56,7 @@ namespace Bootstrap.Client.DataAccess /// /// /// - private static IEnumerable RetrieveDicts() => BASQLHelper.RetrieveDicts(); + private static IEnumerable RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => BASQLHelper.RetrieveDicts()); private static string RetrieveAppName(string name, string defaultValue = "未设置") { diff --git a/Bootstrap.Client.DataAccess/MenuHelper.cs b/Bootstrap.Client.DataAccess/MenuHelper.cs index 1ccb7d98..5e72bbfc 100644 --- a/Bootstrap.Client.DataAccess/MenuHelper.cs +++ b/Bootstrap.Client.DataAccess/MenuHelper.cs @@ -1,7 +1,9 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; +using Longbow.Cache; using Longbow.Configuration; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.Client.DataAccess { @@ -13,9 +15,26 @@ namespace Bootstrap.Client.DataAccess /// /// /// - /// - /// + public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus"; + /// + /// + /// + /// + /// /// - public static IEnumerable RetrieveAppMenus(string userName, string url) => BASQLHelper.RetrieveAppMenus(ConfigurationManager.AppSettings["AppId"], userName, url); + public static IEnumerable RetrieveAppMenus(string userName, string activeUrl) + { + var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0 && m.ApplicationCode == ConfigurationManager.AppSettings["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; + } + /// + /// 通过用户获得所有菜单 + /// + /// + /// + private static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => BASQLHelper.RetrieveAllMenus(userName), RetrieveMenusAll); } } diff --git a/Bootstrap.Client.DataAccess/RoleHelper.cs b/Bootstrap.Client.DataAccess/RoleHelper.cs index efd9ce2f..b88ff2fe 100644 --- a/Bootstrap.Client.DataAccess/RoleHelper.cs +++ b/Bootstrap.Client.DataAccess/RoleHelper.cs @@ -1,5 +1,5 @@ -using Bootstrap.Security; -using Bootstrap.Security.SQLServer; +using Bootstrap.Security.SQLServer; +using Longbow.Cache; using System.Collections.Generic; namespace Bootstrap.Client.DataAccess @@ -9,17 +9,19 @@ namespace Bootstrap.Client.DataAccess /// public static class RoleHelper { + public const string RetrieveRolesByUserNameDataKey = "BootstrapRole-RetrieveRolesByUserName"; + public const string RetrieveRolesByUrlDataKey = "BootstrapRole-RetrieveRolesByUrl"; /// /// /// /// /// - public static IEnumerable RetrieveRolesByUserName(string userName) => BASQLHelper.RetrieveRolesByUserName(userName); + public static IEnumerable RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => BASQLHelper.RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey); /// /// /// /// /// - public static IEnumerable RetrieveRolesByUrl(string url) => BASQLHelper.RetrieveRolesByUrl(url); + public static IEnumerable RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => BASQLHelper.RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey); } } \ No newline at end of file diff --git a/Bootstrap.Client.DataAccess/UserHelper.cs b/Bootstrap.Client.DataAccess/UserHelper.cs index fd4d7171..3d896dd2 100644 --- a/Bootstrap.Client.DataAccess/UserHelper.cs +++ b/Bootstrap.Client.DataAccess/UserHelper.cs @@ -1,5 +1,6 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; +using Longbow.Cache; namespace Bootstrap.Client.DataAccess { @@ -8,11 +9,12 @@ namespace Bootstrap.Client.DataAccess /// public static class UserHelper { + public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName"; /// /// /// /// /// - public static BootstrapUser RetrieveUserByUserName(string userName) => BASQLHelper.RetrieveUserByUserName(userName); + public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => BASQLHelper.RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey); } } diff --git a/Bootstrap.Client/appsettings.json b/Bootstrap.Client/appsettings.json index a8a14ce1..d472b47e 100644 --- a/Bootstrap.Client/appsettings.json +++ b/Bootstrap.Client/appsettings.json @@ -35,27 +35,6 @@ } ], "CacheItems": [ - { - "Enabled": true, - "Key": "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl", - "Interval": 600, - "SlidingExpiration": true, - "Desc": "通过菜单获得所有角色数据" - }, - { - "Enabled": true, - "Key": "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName", - "Interval": 600, - "SlidingExpiration": true, - "Desc": "指定用户所有组数据缓存" - }, - { - "Enabled": true, - "Key": "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName", - "Interval": 600, - "SlidingExpiration": true, - "Desc": "指定用户角色数据缓存" - }, { "Enabled": true, "Key": "BootstrapDict-RetrieveDicts", @@ -65,11 +44,25 @@ }, { "Enabled": true, - "Key": "BootstrapMenu-RetrieveMenusByUserName", + "Key": "BootstrapMenu-RetrieveMenus", "Interval": 600, "SlidingExpiration": true, "Desc": "用户所有菜单数据缓存" }, + { + "Enabled": true, + "Key": "BootstrapRole-RetrieveRolesByUserName", + "Interval": 600, + "SlidingExpiration": true, + "Desc": "指定用户角色数据缓存" + }, + { + "Enabled": true, + "Key": "BootstrapRole-RetrieveRolesByUrl", + "Interval": 600, + "SlidingExpiration": true, + "Desc": "通过菜单获得所有角色数据" + }, { "Enabled": true, "Key": "BootstrapUser-RetrieveUsersByName",