From e6f310fe89d5bd247f4b45f3977074930952f6ae Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Fri, 4 Nov 2016 16:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E7=B3=BB=E7=BB=9F=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 2 + Bootstrap.Admin/Content/css/tasks.css | 182 ++++++++++++++++++ Bootstrap.Admin/Scripts/Profiles.js | 22 +++ Bootstrap.Admin/Scripts/_references.js | Bin 2524 -> 2668 bytes Bootstrap.Admin/Views/Admin/Profiles.cshtml | 14 +- Bootstrap.Admin/Web.config | 34 ++-- .../Bootstrap.DataAccess.csproj | 1 + Bootstrap.DataAccess/ClassDiagram1.cd | 46 +++++ Bootstrap.DataAccess/DictHelper.cs | 12 +- Bootstrap.DataAccess/GroupHelper.cs | 41 ++-- Bootstrap.DataAccess/LogHelper.cs | 51 ++--- Bootstrap.DataAccess/MenuHelper.cs | 24 +-- Bootstrap.DataAccess/RoleHelper.cs | 72 ++++--- Bootstrap.DataAccess/UserHelper.cs | 54 +++--- 14 files changed, 403 insertions(+), 152 deletions(-) create mode 100644 Bootstrap.Admin/Content/css/tasks.css create mode 100644 Bootstrap.Admin/Scripts/Profiles.js create mode 100644 Bootstrap.DataAccess/ClassDiagram1.cd diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index c66e0882..c6bae360 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -112,6 +112,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/Bootstrap.Admin/Content/css/tasks.css b/Bootstrap.Admin/Content/css/tasks.css new file mode 100644 index 00000000..6c14aacd --- /dev/null +++ b/Bootstrap.Admin/Content/css/tasks.css @@ -0,0 +1,182 @@ +/*--------------Tasks Widget--------------*/ + +.task-content { + margin-bottom: 30px; +} + +.tasks-widget .task-content:after { + clear: both; +} + +.tasks-widget .task-footer { + margin-top: 5px; +} + + .tasks-widget .task-footer:after, + .tasks-widget .task-footer:before { + content: ""; + display: table; + line-height: 0; + } + + .tasks-widget .task-footer:after { + clear: both; + } + +.tasks-widget .task-list { + padding: 0; + margin: 0; +} + + .tasks-widget .task-list > li { + position: relative; + padding: 10px 5px; + border-bottom: 1px dashed #eaeaea; + } + + .tasks-widget .task-list li.last-line { + border-bottom: none; + } + + .tasks-widget .task-list li > .task-bell { + margin-left: 10px; + } + + .tasks-widget .task-list li > .task-checkbox { + float: left; + width: 30px; + } + + .tasks-widget .task-list li > .task-title { + overflow: hidden; + margin-right: 10px; + } + + .tasks-widget .task-list li > .task-title .task-value { + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + position: absolute; + left: 190px; + right: 40px; + display: inline-block; + } + + .tasks-widget .task-list li > .task-title .badge { + position: absolute; + display: inline-block; + left: 25px; + top: 2px; + } + + .tasks-widget .task-list li > .task-title .label-success { + background-color: #5cb85c; + } + + .tasks-widget .task-list li > .task-config { + position: absolute; + top: 10px; + right: 10px; + } + + .tasks-widget .task-list li .task-title .task-title-sp { + margin-right: 5px; + max-width: 170px; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + display: inline-block; + } + + .tasks-widget .task-list li.task-done .task-title-sp { + text-decoration: line-through; + color: #bbbbbb; + } + + .tasks-widget .task-list li.task-done { + background: #f6f6f6; + } + + .tasks-widget .task-list li.task-done:hover { + background: #f4f4f4; + } + + .tasks-widget .task-list li:hover { + background: #f9f9f9; + } + + .tasks-widget .task-list li .task-config { + display: none; + } + + .tasks-widget .task-list li:hover > .task-config { + display: block; + margin-bottom: 0 !important; + } + +#sortable { + list-style-type: none; + margin: 0 0 20px 0; + padding: 0; + width: 100%; +} + + #sortable li { + padding-left: 3em; + font-size: 12px; + } + + #sortable li i { + position: absolute; + left: 6px; + padding: 4px 10px 0 10px; + cursor: pointer; + } + + #sortable li input[type=checkbox] { + margin-top: 0; + } + +.ui-sortable > li { + padding: 18px 0 15px 35px !important; + position: relative; + background: #f5f6f8; + margin-bottom: 2px; + border-bottom: none !important; +} + +.ui-sortable li.list-primary { + border-left: 3px solid #41CAC0; +} + +.ui-sortable li.list-success { + border-left: 3px solid #78CD51; +} + +.ui-sortable li.list-danger { + border-left: 3px solid #FF6C60; +} + +.ui-sortable li.list-warning { + border-left: 3px solid #F1C500; +} + +.ui-sortable li.list-info { + border-left: 3px solid #58C9F3; +} + +.ui-sortable li.list-inverse { + border-left: 3px solid #BEC3C7; +} + +@media only screen and (max-width: 320px) { + + .tasks-widget .task-config-btn { + float: inherit; + display: block; + } + + .tasks-widget .task-list-projects li > .label { + margin-bottom: 5px; + } +} diff --git a/Bootstrap.Admin/Scripts/Profiles.js b/Bootstrap.Admin/Scripts/Profiles.js new file mode 100644 index 00000000..5d66b8aa --- /dev/null +++ b/Bootstrap.Admin/Scripts/Profiles.js @@ -0,0 +1,22 @@ +$(function () { + var html = '
  • {2}{0}{3}
  • '; + $.ajax({ + url: '../../CacheList.axd', + type: 'GET', + success: function (result) { + if (result) { + result = $.parseJSON(result); + if ($.isArray(result)) { + var content = result.map(function (ele) { + return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value); + }).join(''); + $('#sortable').append(content); + } + } + else { + } + }, + error: function (XMLHttpRequest, textStatus, errorThrown) { + } + }); +}); \ No newline at end of file diff --git a/Bootstrap.Admin/Scripts/_references.js b/Bootstrap.Admin/Scripts/_references.js index b67affb32f1d900f3c6ae14c65d58904407b097a..be3cc7c41f789e7f3e8bc42a84a6d21af6cf845f 100644 GIT binary patch delta 43 ucmca3{6=Jh2`8%$Lq0?L +} +@section css { + } @section header { @Html.Partial("Header", Model) @@ -34,5 +37,14 @@ +
    +
    网站缓存
    +
    +
    +
      +
    +
    +
    +
    diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config index 203f81ba..0186597a 100644 --- a/Bootstrap.Admin/Web.config +++ b/Bootstrap.Admin/Web.config @@ -23,21 +23,23 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -85,8 +87,10 @@ + + diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 07245110..fabc7e76 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -72,6 +72,7 @@ + diff --git a/Bootstrap.DataAccess/ClassDiagram1.cd b/Bootstrap.DataAccess/ClassDiagram1.cd new file mode 100644 index 00000000..5fbf3219 --- /dev/null +++ b/Bootstrap.DataAccess/ClassDiagram1.cd @@ -0,0 +1,46 @@ + + + + + + AAAQAAACAAAAAAAAAAAACAAQAAAAAAAAAAAACAAAAAA= + DictHelper.cs + + + + + + AAAAAAABAAAIAAAAAAAAAAIAABABAAQAAIAAAABAQBA= + GroupHelper.cs + + + + + + AAAAAAAAAAAAAAAIACACEAAAAAAAAAAAAAAACAAAAAA= + LogHelper.cs + + + + + + AEAAAAAAAhAAAIAAAAAAAAAAAAAAAEIAAAAAAAAAAAA= + MenuHelper.cs + + + + + + RQQQAAAAAAAAgEAiIAEAAERAAACAAAAAAAAggAAAAAA= + RoleHelper.cs + + + + + + AAAAAAAAAAgAAAAEIQAkAAIEgEAIEAAAAAAAAAAAAAg= + UserHelper.cs + + + + \ No newline at end of file diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs index 11d5cf48..d133cef3 100644 --- a/Bootstrap.DataAccess/DictHelper.cs +++ b/Bootstrap.DataAccess/DictHelper.cs @@ -10,9 +10,9 @@ using System.Linq; namespace Bootstrap.DataAccess { - public class DictHelper + public static class DictHelper { - private const string DictDataKey = "DictData-CodeDictHelper"; + private const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts"; /// /// 查询所有字典信息 @@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveDicts(int id = 0) { - var ret = CacheManager.GetOrAdd(DictDataKey, CacheSection.RetrieveIntervalByKey(DictDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveDictsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveDictsDataKey), key => { string sql = "select ID, Category, Name, Code, Define, case Define when 0 then '系统使用' else '用户自定义' end DefineName from Dicts"; List Dicts = new List(); @@ -46,7 +46,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Dicts; - }, CacheSection.RetrieveDescByKey(DictDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveDictsDataKey)); return id == 0 ? ret : ret.Where(t => id == t.ID); } @@ -75,7 +75,6 @@ namespace Bootstrap.DataAccess } return ret; } - /// /// 保存新建/更新的字典信息 /// @@ -111,13 +110,12 @@ namespace Bootstrap.DataAccess } return ret; } - /// /// 更新缓存 /// private static void ClearCache() { - CacheManager.Clear(key => key == DictDataKey); + CacheManager.Clear(key => key == RetrieveDictsDataKey); } } } diff --git a/Bootstrap.DataAccess/GroupHelper.cs b/Bootstrap.DataAccess/GroupHelper.cs index 89bfd44f..10896e73 100644 --- a/Bootstrap.DataAccess/GroupHelper.cs +++ b/Bootstrap.DataAccess/GroupHelper.cs @@ -18,9 +18,9 @@ namespace Bootstrap.DataAccess /// public static class GroupHelper { - private const string GroupDataKey = "GroupData-CodeGroupHelper"; - private const string GroupUserIDDataKey = "GroupData-CodeGroupHelper-"; - private const string GroupRoleIDDataKey = "GroupData-CodeGroupHelper-Role-"; + private const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups"; + internal const string RetrieveGroupsByUserIDDataKey = "GroupHelper-RetrieveGroupsByUserId"; + internal const string RetrieveGroupsByRoleIDDataKey = "GroupHelper-RetrieveGroupsByRoleId"; /// /// 查询所有群组信息 /// @@ -28,9 +28,9 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveGroups(string tId = null) { - string sql = "select * from Groups"; - var ret = CacheManager.GetOrAdd(GroupDataKey, CacheSection.RetrieveIntervalByKey(GroupDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveGroupsDataKey), key => { + string sql = "select * from Groups"; List Groups = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); try @@ -50,7 +50,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Groups; - }, CacheSection.RetrieveDescByKey(GroupDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveGroupsDataKey)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); } /// @@ -67,7 +67,7 @@ namespace Bootstrap.DataAccess using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - ClearCache(); + CacheManager.Clear(key => key == RetrieveGroupsDataKey); ret = true; } } @@ -101,7 +101,7 @@ namespace Bootstrap.DataAccess DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } ret = true; - ClearCache(); + CacheManager.Clear(key => key == RetrieveGroupsDataKey); } catch (DbException ex) { @@ -116,10 +116,10 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveGroupsByUserId(int userId) { - string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID"; - string k = string.Format("{0}{1}", GroupUserIDDataKey, userId); - var ret = CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(GroupUserIDDataKey), key => + string key = string.Format("{0}-{1}", RetrieveGroupsByUserIDDataKey, userId); + var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByUserIDDataKey), k => { + string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID"; List Groups = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId, ParameterDirection.Input)); @@ -141,7 +141,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Groups; - }, CacheSection.RetrieveDescByKey(GroupUserIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveGroupsByUserIDDataKey)); return ret; } /// @@ -180,8 +180,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() +.ForAll(g => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveGroupsByUserIDDataKey, id) || key == string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIDDataKey, g))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -191,11 +192,6 @@ namespace Bootstrap.DataAccess } return ret; } - // 更新缓存 - private static void ClearCache(string cacheKey = null) - { - CacheManager.Clear(key => string.IsNullOrEmpty(cacheKey) || key == cacheKey); - } /// /// 根据角色ID指派部门 /// @@ -203,8 +199,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveGroupsByRoleId(int roleId) { - string k = string.Format("{0}{1}", GroupRoleIDDataKey, roleId); - return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(GroupRoleIDDataKey), key => + string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIDDataKey, roleId); + return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByRoleIDDataKey), key => { List Groups = new List(); string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID"; @@ -228,7 +224,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Groups; - }, CacheSection.RetrieveDescByKey(GroupRoleIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveGroupsByRoleIDDataKey)); } /// /// 根据角色ID以及选定的部门ID,保到角色部门表 @@ -264,8 +260,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() + .ForAll(g => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveGroupsByRoleIDDataKey, id) || key == string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIDDataKey, g))); ret = true; - ClearCache(); } catch (Exception ex) { diff --git a/Bootstrap.DataAccess/LogHelper.cs b/Bootstrap.DataAccess/LogHelper.cs index e5ee78c0..0c0361c0 100644 --- a/Bootstrap.DataAccess/LogHelper.cs +++ b/Bootstrap.DataAccess/LogHelper.cs @@ -1,4 +1,5 @@ -using Longbow.Caching; +using Longbow; +using Longbow.Caching; using Longbow.Caching.Configuration; using Longbow.ExceptionManagement; using System; @@ -11,9 +12,9 @@ using System.Web; namespace Bootstrap.DataAccess { - public class LogHelper + public static class LogHelper { - private const string LogDataKey = "LogData-CodeLogHelper"; + private const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs"; /// /// 查询所有日志信息 /// @@ -21,33 +22,33 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveLogs(string tId = null) { - string sql = "select * from Logs"; - var ret = CacheManager.GetOrAdd(LogDataKey, CacheSection.RetrieveIntervalByKey(LogDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveLogsDataKey), key => + { + string sql = "select * from Logs"; + List Logs = new List(); + DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); + try { - List Logs = new List(); - DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); - try + using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) { - using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + Logs.Add(new Log() { - Logs.Add(new Log() - { - ID = (int)reader[0], - OperationType = (int)reader[1], - UserName = (string)reader[2], - OperationTime = (DateTime)reader[3], - OperationIp = (string)reader[4], - Remark = (string)reader[5], - OperationModule = (string)reader[6] - }); - } + ID = (int)reader[0], + OperationType = (int)reader[1], + UserName = (string)reader[2], + OperationTime = (DateTime)reader[3], + OperationIp = (string)reader[4], + Remark = (string)reader[5], + OperationModule = (string)reader[6] + }); } } - catch (Exception ex) { ExceptionManager.Publish(ex); } - return Logs; - }, CacheSection.RetrieveDescByKey(LogDataKey)); + } + catch (Exception ex) { ExceptionManager.Publish(ex); } + return Logs; + }, CacheSection.RetrieveDescByKey(RetrieveLogsDataKey)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); } /// @@ -109,7 +110,7 @@ namespace Bootstrap.DataAccess //更新缓存 private static void ClearCache() { - CacheManager.Clear(key => key == LogDataKey); + CacheManager.Clear(key => key == RetrieveLogsDataKey); } /// diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index e67fd7b7..f7dfda27 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -14,8 +14,8 @@ namespace Bootstrap.DataAccess { public static class MenuHelper { - private const string MenuDataKey = "MenuHelper-RetrieveMenus"; - private const string MenuByUserDataKey = "MenuHelper-RetrieveMenusByUserId-userId"; + private const string RetrieveMenusDataKey = "MenuHelper-RetrieveMenus"; + internal const string RetrieveMenusByUserIDDataKey = "MenuHelper-RetrieveMenusByUserId"; /// /// 查询所有菜单信息 /// @@ -24,7 +24,7 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveMenus(string tId = null) { string sql = "select n.*, d.Name as CategoryName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = N'菜单' and d.Define = 0"; - var ret = CacheManager.GetOrAdd(MenuDataKey, CacheSection.RetrieveIntervalByKey(MenuDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveMenusDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMenusDataKey), key => { List Menus = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); @@ -50,7 +50,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Menus; - }, CacheSection.RetrieveDescByKey(MenuDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveMenusDataKey)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); } /// @@ -60,9 +60,10 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveMenusByUserId(int userId) { - string sql = "select distinct n.* from UserRole ur,NavigationRole nr,Navigations n where ur.RoleID=nr.RoleID and nr.NavigationID=n.ID and ur.UserID = @UserID"; - return CacheManager.GetOrAdd(MenuByUserDataKey, CacheSection.RetrieveIntervalByKey(MenuByUserDataKey), key => + string key = string.Format("{0}-{1}", RetrieveMenusByUserIDDataKey, userId); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusByUserIDDataKey), k => { + string sql = "select distinct n.* from UserRole ur,NavigationRole nr,Navigations n where ur.RoleID=nr.RoleID and nr.NavigationID=n.ID and ur.UserID = @UserID"; List Menus = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); try @@ -87,7 +88,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Menus; - }, CacheSection.RetrieveDescByKey(MenuByUserDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveMenusByUserIDDataKey)); } /// /// 删除菜单信息 @@ -104,7 +105,7 @@ namespace Bootstrap.DataAccess { DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } - ClearCache(); + ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => CacheManager.Clear(key => key == string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIDDataKey, id))); ret = true; } catch (Exception ex) @@ -143,7 +144,7 @@ namespace Bootstrap.DataAccess DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } ret = true; - ClearCache(); + CacheManager.Clear(key => key == RetrieveMenusDataKey); } catch (DbException ex) { @@ -151,10 +152,5 @@ namespace Bootstrap.DataAccess } return ret; } - // 更新缓存 - private static void ClearCache() - { - CacheManager.Clear(key => key == MenuDataKey); - } } } diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs index b86edba2..2a854d5d 100644 --- a/Bootstrap.DataAccess/RoleHelper.cs +++ b/Bootstrap.DataAccess/RoleHelper.cs @@ -16,12 +16,14 @@ namespace Bootstrap.DataAccess /// /// /// - public class RoleHelper + public static class RoleHelper { - private const string RoleDataKey = "RoleData-CodeRoleHelper"; - private const string RolebyGroupDataKey = "RoleData-CodeRoleHelper-"; - private const string RoleUserIDDataKey = "RoleData-CodeRoleHelper-"; - private const string RoleNavigationIDDataKey = "RoleHelper-RetrieveRolesByMenuId-menuId"; + private const string RetrieveRolesDataKey = "RoleHelper-RetrieveRoles"; + private const string RetrieveRolesByUrlDataKey = "RoleHelper-RetrieveRolesByUrl"; + private const string RetrieveRolesByUserNameDataKey = "RoleHelper-RetrieveRolesByUserName"; + internal const string RetrieveRolesByUserIDDataKey = "RoleHelper-RetrieveRolesByUserId"; + internal const string RetrieveRolesByMenuIDDataKey = "RoleHelper-RetrieveRolesByMenuId"; + internal const string RetrieveRolesByGroupIDDataKey = "RoleHelper-RetrieveRolesByGroupId"; /// /// 查询所有角色 /// @@ -29,9 +31,9 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRoles(string tId = null) { - string sql = "select * from Roles"; - var ret = CacheManager.GetOrAdd(RoleDataKey, CacheSection.RetrieveIntervalByKey(RoleDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, CacheSection.RetrieveIntervalByKey(RetrieveRolesDataKey), key => { + string sql = "select * from Roles"; List roles = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); try @@ -51,7 +53,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return roles; - }, CacheSection.RetrieveDescByKey(RoleDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesDataKey)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); } /// @@ -90,8 +92,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() + .ForAll(r => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveRolesByUserIDDataKey, id) || key == string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIDDataKey, r))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -107,8 +110,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRolesByUserId(int userId) { - string k = string.Format("{0}{1}", RoleUserIDDataKey, userId); - return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleUserIDDataKey), key => + string key = string.Format("{0}-{1}", RetrieveRolesByUserIDDataKey, userId); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByUserIDDataKey), k => { List Roles = new List(); string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID"; @@ -132,9 +135,8 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Roles; - }, CacheSection.RetrieveDescByKey(RoleUserIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesByUserIDDataKey)); } - /// /// 删除角色表 /// @@ -149,7 +151,7 @@ namespace Bootstrap.DataAccess using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - ClearCache(); + CacheManager.Clear(key => key == RetrieveRolesDataKey); ret = true; } } @@ -182,8 +184,8 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", p.Description, ParameterDirection.Input)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } + CacheManager.Clear(key => key == RetrieveRolesDataKey); ret = true; - ClearCache(); } catch (DbException ex) { @@ -191,7 +193,6 @@ namespace Bootstrap.DataAccess } return ret; } - /// /// 查询某个菜单所拥有的角色 /// @@ -199,10 +200,10 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRolesByMenuId(int menuId) { - string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID"; - string k = string.Format("{0}{1}", RoleNavigationIDDataKey, menuId); - var ret = CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleNavigationIDDataKey), key => + string key = string.Format("{0}-{1}", RetrieveRolesByMenuIDDataKey, menuId); + var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByMenuIDDataKey), k => { + string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID"; List Roles = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId, ParameterDirection.Input)); @@ -224,7 +225,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Roles; - }, CacheSection.RetrieveDescByKey(RoleNavigationIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesByMenuIDDataKey)); return ret; } public static bool SavaRolesByMenuId(int id, string roleIds) @@ -257,8 +258,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() + .ForAll(r => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveRolesByMenuIDDataKey, id) || key.Contains(MenuHelper.RetrieveMenusByUserIDDataKey))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -268,12 +270,6 @@ namespace Bootstrap.DataAccess } return ret; } - // 更新缓存 - private static void ClearCache(string cacheKey = null) - { - CacheManager.Clear(key => string.IsNullOrEmpty(cacheKey) || key == cacheKey); - } - /// /// 根据GroupId查询和该Group有关的所有Roles /// author:liuchun @@ -281,8 +277,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRolesByGroupId(int groupID) { - string key = string.Format("{0}{1}", RolebyGroupDataKey, groupID); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RolebyGroupDataKey), k => + string key = string.Format("{0}-{1}", RetrieveRolesByGroupIDDataKey, groupID); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByGroupIDDataKey), k => { List Roles = new List(); string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID"; @@ -306,7 +302,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Roles; - }, CacheSection.RetrieveDescByKey(RolebyGroupDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesByGroupIDDataKey)); } /// @@ -344,8 +340,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() + .ForAll(r => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveRolesByGroupIDDataKey, id) || key == string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIDDataKey, r))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -355,7 +352,6 @@ namespace Bootstrap.DataAccess } return ret; } - /// /// 根据用户名查询某个用户所拥有的角色 /// 从UserRole表查 @@ -364,8 +360,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRolesByUserName(string username) { - string key = string.Format("{0}{1}", RoleDataKey, username); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RoleDataKey), k => + string key = string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, username); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByUserNameDataKey), k => { List Roles = new List(); try @@ -388,7 +384,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Roles; - }, CacheSection.RetrieveDescByKey(RoleDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesByUserNameDataKey)); } /// /// 根据菜单url查询某个所拥有的角色 @@ -398,8 +394,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveRolesByUrl(string url) { - string key = string.Format("{0}{1}", RoleDataKey, url); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RoleDataKey), k => + string key = string.Format("{0}-{1}", RetrieveRolesDataKey, url); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesDataKey), k => { string sql = "select r.ID, r.RoleName, r.[Description] from Roles r inner join NavigationRole nr on r.ID = nr.RoleID inner join Navigations n on nr.NavigationID = n.ID and n.Url = @URl"; List Roles = new List(); @@ -422,7 +418,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Roles; - }, CacheSection.RetrieveDescByKey(RoleDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveRolesDataKey)); } } } \ No newline at end of file diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs index 063c7fa5..a13e1695 100644 --- a/Bootstrap.DataAccess/UserHelper.cs +++ b/Bootstrap.DataAccess/UserHelper.cs @@ -3,6 +3,7 @@ using Longbow.Caching.Configuration; using Longbow.Data; using Longbow.ExceptionManagement; using Longbow.Security; +using Longbow.Security.Principal; using System; using System.Collections.Generic; using System.Data; @@ -18,10 +19,10 @@ namespace Bootstrap.DataAccess /// public static class UserHelper { - private const string UserDataKey = "UserData-CodeUserHelper"; - private const string UserDisplayNameDataKey = "UserData-CodeUserHelper-"; - private const string UserRoleIDDataKey = "UserData-CodeUserHelper-Role-"; - private const string UserGroupIDDataKey = "UserData-CodeUserHelper-Group-"; + private const string RetrieveUsersDataKey = "UserHelper-RetrieveUsers"; + internal const string RetrieveUsersByNameDataKey = "UserHelper-RetrieveUsersByName"; + internal const string RetrieveUsersByRoleIDDataKey = "UserHelper-RetrieveUsersByRoleId"; + internal const string RetrieveUsersByGroupIDDataKey = "UserHelper-RetrieveUsersByGroupId"; /// /// 查询所有用户 /// @@ -30,7 +31,7 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveUsers(string tId = null) { string sql = "select ID, UserName, DisplayName from Users"; - var ret = CacheManager.GetOrAdd(UserDataKey, CacheSection.RetrieveIntervalByKey(UserDataKey), key => + var ret = CacheManager.GetOrAdd(RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersDataKey), key => { List Users = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); @@ -51,7 +52,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Users; - }, CacheSection.RetrieveDescByKey(UserDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveUsersDataKey)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.ID.ToString(), StringComparison.OrdinalIgnoreCase)); } /// @@ -61,9 +62,9 @@ namespace Bootstrap.DataAccess /// public static User RetrieveUsersByName(string userName) { - if (Longbow.Security.Principal.LgbPrincipal.IsAdmin(userName)) return new User() { DisplayName = "网站管理员", UserName = userName }; - string key = string.Format("{0}{1}", UserDisplayNameDataKey, userName); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserDisplayNameDataKey), k => + if (LgbPrincipal.IsAdmin(userName)) return new User() { DisplayName = "网站管理员", UserName = userName }; + string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k => { User user = null; string sql = "select ID, UserName, [Password], PassSalt, DisplayName from Users where UserName = @UserName"; @@ -88,7 +89,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return user; - }, CacheSection.RetrieveDescByKey(UserDisplayNameDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveUsersByNameDataKey)); } /// /// 删除用户 @@ -105,7 +106,7 @@ namespace Bootstrap.DataAccess { DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } - ClearCache(); + CacheManager.Clear(key => key == RetrieveUsersDataKey); ret = true; } catch (Exception ex) @@ -142,7 +143,7 @@ namespace Bootstrap.DataAccess DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } ret = true; - ClearCache(); + CacheManager.Clear(key => key == RetrieveUsersDataKey || key == RetrieveUsersByNameDataKey); } catch (DbException ex) { @@ -161,12 +162,6 @@ namespace Bootstrap.DataAccess var user = RetrieveUsersByName(userName); return user != null && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt); } - // 更新缓存 - private static void ClearCache(string cacheKey = null) - { - CacheManager.Clear(key => string.IsNullOrEmpty(cacheKey) || key == cacheKey); - } - /// /// 通过roleId获取所有用户 /// @@ -174,9 +169,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveUsersByRoleId(int roleId) { - - string key = string.Format("{0}{1}", UserRoleIDDataKey, roleId); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserDisplayNameDataKey), k => + string key = string.Format("{0}-{1}", RetrieveUsersByRoleIDDataKey, roleId); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k => { List Users = new List(); string sql = "select u.ID,u.UserName,u.DisplayName,case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID=ur.UserID and RoleID =@RoleID"; @@ -200,7 +194,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Users; - }, CacheSection.RetrieveDescByKey(UserRoleIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIDDataKey)); } /// /// 通过角色ID保存当前授权用户(插入) @@ -235,8 +229,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + userIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() +.ForAll(u => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveUsersByRoleIDDataKey, id) || key == string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIDDataKey, u))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -246,7 +241,6 @@ namespace Bootstrap.DataAccess } return ret; } - /// /// 通过groupId获取所有用户 /// @@ -254,9 +248,8 @@ namespace Bootstrap.DataAccess /// public static IEnumerable RetrieveUsersByGroupId(int groupId) { - - string key = string.Format("{0}{1}", UserGroupIDDataKey, groupId); - return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(UserGroupIDDataKey), k => + string key = string.Format("{0}-{1}", RetrieveUsersByGroupIDDataKey, groupId); + return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByGroupIDDataKey), k => { List Users = new List(); string sql = "select u.ID,u.UserName,u.DisplayName,case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID=ur.UserID and GroupID =@groupId"; @@ -280,7 +273,7 @@ namespace Bootstrap.DataAccess } catch (Exception ex) { ExceptionManager.Publish(ex); } return Users; - }, CacheSection.RetrieveDescByKey(UserRoleIDDataKey)); + }, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIDDataKey)); } /// /// 通过部门ID保存当前授权用户(插入) @@ -315,8 +308,9 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } + userIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).AsParallel() +.ForAll(u => CacheManager.Clear(key => key == string.Format("{0}-{1}", RetrieveUsersByGroupIDDataKey, id) || key == string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, u))); ret = true; - ClearCache(); } catch (Exception ex) { @@ -327,4 +321,4 @@ namespace Bootstrap.DataAccess return ret; } } -} +} \ No newline at end of file