diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs index b7deceba..b904a49f 100644 --- a/Bootstrap.DataAccess.SQLite/Exceptions.cs +++ b/Bootstrap.DataAccess.SQLite/Exceptions.cs @@ -56,7 +56,7 @@ namespace Bootstrap.DataAccess.SQLite cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace))); DbAccessManager.DBAccess.ExecuteNonQuery(cmd); - CacheManager.Clear(RetrieveExceptionsDataKey); + CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey); ClearExceptions(); } } @@ -66,31 +66,28 @@ namespace Bootstrap.DataAccess.SQLite /// public override IEnumerable RetrieveExceptions() { - return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => + string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc"; + List exceptions = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc"; - List exceptions = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + exceptions.Add(new Exceptions() { - exceptions.Add(new Exceptions() - { - Id = LgbConvert.ReadValue(reader[0], 0), - AppDomainName = (string)reader[1], - ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], - UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], - ExceptionType = (string)reader[5], - Message = (string)reader[6], - StackTrace = (string)reader[7], - LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue) - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + AppDomainName = (string)reader[1], + ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], + UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], + ExceptionType = (string)reader[5], + Message = (string)reader[6], + StackTrace = (string)reader[7], + LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue) + }); } - return exceptions; - }); + } + return exceptions; } } } diff --git a/Bootstrap.DataAccess.SQLite/Log.cs b/Bootstrap.DataAccess.SQLite/Log.cs index b4aa4d38..5ed0a37d 100644 --- a/Bootstrap.DataAccess.SQLite/Log.cs +++ b/Bootstrap.DataAccess.SQLite/Log.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using System.Linq; namespace Bootstrap.DataAccess.SQLite { @@ -21,30 +20,26 @@ namespace Bootstrap.DataAccess.SQLite /// public override IEnumerable RetrieveLogs(string tId = null) { - var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => + string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')"; + List logs = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')"; - List logs = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + logs.Add(new Log() { - logs.Add(new Log() - { - Id = LgbConvert.ReadValue(reader[0], 0), - CRUD = (string)reader[1], - UserName = (string)reader[2], - LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - ClientIp = (string)reader[4], - ClientAgent = (string)reader[5], - RequestUrl = (string)reader[6] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + CRUD = (string)reader[1], + UserName = (string)reader[2], + LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), + ClientIp = (string)reader[4], + ClientAgent = (string)reader[5], + RequestUrl = (string)reader[6] + }); } - return logs; - }); - return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase)); + } + return logs; } /// /// 删除日志信息 @@ -79,7 +74,7 @@ namespace Bootstrap.DataAccess.SQLite cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheManager.Clear(RetrieveLogsDataKey); + CacheManager.Clear(LogHelper.RetrieveLogsDataKey); DeleteLogAsync(); return ret; } diff --git a/Bootstrap.DataAccess.SQLite/Message.cs b/Bootstrap.DataAccess.SQLite/Message.cs index cc4db2e8..7d1c76fa 100644 --- a/Bootstrap.DataAccess.SQLite/Message.cs +++ b/Bootstrap.DataAccess.SQLite/Message.cs @@ -1,10 +1,8 @@ using Longbow; -using Longbow.Cache; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using System.Linq; namespace Bootstrap.DataAccess.SQLite { @@ -20,38 +18,33 @@ namespace Bootstrap.DataAccess.SQLite /// protected override IEnumerable RetrieveMessages(string userName) { - var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key => + string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; + List messages = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; - List messages = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + messages.Add(new Message() { - messages.Add(new Message() - { - Id = LgbConvert.ReadValue(reader[0], 0), - Title = (string)reader[1], - Content = (string)reader[2], - From = (string)reader[3], - To = (string)reader[4], - SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - Status = (string)reader[6], - Mark = LgbConvert.ReadValue(reader[7], 0), - IsDelete = LgbConvert.ReadValue(reader[8], 0), - Label = (string)reader[9], - LabelName = LgbConvert.ReadValue(reader[10], string.Empty), - FromIcon = (string)reader[11], - FromDisplayName = (string)reader[12] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + Title = (string)reader[1], + Content = (string)reader[2], + From = (string)reader[3], + To = (string)reader[4], + SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), + Status = (string)reader[6], + Mark = LgbConvert.ReadValue(reader[7], 0), + IsDelete = LgbConvert.ReadValue(reader[8], 0), + Label = (string)reader[9], + LabelName = LgbConvert.ReadValue(reader[10], string.Empty), + FromIcon = (string)reader[11], + FromDisplayName = (string)reader[12] + }); } - return messages; - - }); - return messageRet.OrderByDescending(n => n.SendTime); + } + return messages; } } } diff --git a/Bootstrap.DataAccess.SQLite/Task.cs b/Bootstrap.DataAccess.SQLite/Task.cs index f3b30ccf..a0924560 100644 --- a/Bootstrap.DataAccess.SQLite/Task.cs +++ b/Bootstrap.DataAccess.SQLite/Task.cs @@ -1,5 +1,4 @@ using Longbow; -using Longbow.Cache; using System; using System.Collections.Generic; using System.Data; @@ -15,30 +14,27 @@ namespace Bootstrap.DataAccess.SQLite /// public override IEnumerable RetrieveTasks() { - return CacheManager.GetOrAdd(RetrieveTasksDataKey, key => + string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000"; + List tasks = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000"; - List tasks = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + tasks.Add(new Task() { - tasks.Add(new Task() - { - Id = LgbConvert.ReadValue(reader[0], 0), - TaskName = (string)reader[1], - AssignName = (string)reader[2], - UserName = (string)reader[3], - TaskTime = LgbConvert.ReadValue(reader[4], 0), - TaskProgress = (double)reader[5], - AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue), - AssignDisplayName = (string)reader[7] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + TaskName = (string)reader[1], + AssignName = (string)reader[2], + UserName = (string)reader[3], + TaskTime = LgbConvert.ReadValue(reader[4], 0), + TaskProgress = (double)reader[5], + AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue), + AssignDisplayName = (string)reader[7] + }); } - return tasks; - }); + } + return tasks; } } } diff --git a/Bootstrap.DataAccess.SQLite/User.cs b/Bootstrap.DataAccess.SQLite/User.cs index f3d34034..920e8b6b 100644 --- a/Bootstrap.DataAccess.SQLite/User.cs +++ b/Bootstrap.DataAccess.SQLite/User.cs @@ -1,5 +1,4 @@ using Bootstrap.Security; -using Longbow.Cache; using Longbow.Data; using Longbow.Security.Cryptography; using System; @@ -8,7 +7,6 @@ using System.Data; using System.Data.Common; using System.Linq; - namespace Bootstrap.DataAccess.SQLite { /// @@ -245,29 +243,25 @@ namespace Bootstrap.DataAccess.SQLite /// public override BootstrapUser RetrieveUserByUserName(string userName) { - var key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName); - return CacheManager.GetOrAdd(key, k => + BootstrapUser user = null; + var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName"; + var db = DbAccessManager.DBAccess; + var cmd = db.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); + using (DbDataReader reader = db.ExecuteReader(cmd)) { - BootstrapUser user = null; - var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName"; - var db = DbAccessManager.DBAccess; - var cmd = db.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); - using (DbDataReader reader = db.ExecuteReader(cmd)) + if (reader.Read()) { - if (reader.Read()) + user = new BootstrapUser { - user = new BootstrapUser - { - UserName = (string)reader[0], - DisplayName = (string)reader[1], - Icon = (string)reader[2], - Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3] - }; - } + UserName = (string)reader[0], + DisplayName = (string)reader[1], + Icon = (string)reader[2], + Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3] + }; } - return user; - }, RetrieveUsersByNameDataKey); + } + return user; } } } diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 9795104f..a40e20da 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -27,54 +27,54 @@ namespace Bootstrap.DataAccess { roleIds.ToList().ForEach(id => { - cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByRoleIdDataKey, id)); - cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByRoleIdDataKey, id)); - cacheKeys.Add(string.Format("{0}-{1}", Menu.RetrieveMenusByRoleIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id)); }); - cacheKeys.Add(Role.RetrieveRolesDataKey + "*"); - cacheKeys.Add(Menu.RetrieveMenusDataKey + "*"); + cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); - corsKeys.Add(Menu.RetrieveMenusDataKey + "*"); + corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); } if (userIds != null) { userIds.ToList().ForEach(id => { - cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByUserIdDataKey, id)); - cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByUserIdDataKey, id)); - cacheKeys.Add(Menu.RetrieveMenusDataKey + "*"); - corsKeys.Add(Menu.RetrieveMenusDataKey + "*"); + 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(User.RetrieveNewUsersDataKey + "*"); - cacheKeys.Add(User.RetrieveUsersDataKey + "*"); - corsKeys.Add(User.RetrieveUsersDataKey + "*"); + cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); + cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); + corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); } if (groupIds != null) { groupIds.ToList().ForEach(id => { - cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByGroupIdDataKey, id)); - cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByGroupIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id)); }); - cacheKeys.Add(Group.RetrieveGroupsDataKey + "*"); - cacheKeys.Add(Menu.RetrieveMenusDataKey + "*"); - corsKeys.Add(Menu.RetrieveMenusDataKey + "*"); + cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); + corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); cacheKeys.Add(RetrieveAllRolesDataKey + "*"); } if (menuIds != null) { menuIds.ToList().ForEach(id => { - cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByMenuIdDataKey, id)); + cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id)); }); - cacheKeys.Add(Menu.RetrieveMenusByRoleIdDataKey + "*"); - cacheKeys.Add(Menu.RetrieveMenusDataKey + "*"); - corsKeys.Add(Menu.RetrieveMenusDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*"); + cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); + corsKeys.Add(MenuHelper.RetrieveMenusDataKey + "*"); } if (dictIds != null) { cacheKeys.Add(Dict.RetrieveDictsDataKey + "*"); - cacheKeys.Add(Dict.RetrieveCategoryDataKey); + cacheKeys.Add(DictHelper.RetrieveCategoryDataKey); corsKeys.Add(Dict.RetrieveDictsDataKey + "*"); } if (cacheKey != null) diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index 222e66c6..f6ec7bb1 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -1,6 +1,5 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; -using Longbow.Cache; using System; using System.Collections.Generic; using System.Data; @@ -17,7 +16,6 @@ namespace Bootstrap.DataAccess /// /// /// - public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; /// /// 缓存索引,BootstrapAdmin后台清理缓存时使用 /// @@ -92,20 +90,17 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveCategories() { - return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => + var ret = new List(); + string sql = "select distinct Category from Dicts"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - var ret = new List(); - string sql = "select distinct Category from Dicts"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) - { - ret.Add((string)reader[0]); - } + ret.Add((string)reader[0]); } - return ret; - }); + } + return ret; } /// /// diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs index 477d23c8..1e0dd920 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -14,10 +14,6 @@ namespace Bootstrap.DataAccess /// public class Exceptions { - /// - /// - /// - protected const string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions"; /// /// /// @@ -97,7 +93,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace))); DbAccessManager.DBAccess.ExecuteNonQuery(cmd); - CacheManager.Clear(RetrieveExceptionsDataKey); + CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey); ClearExceptions(); } } @@ -107,31 +103,28 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveExceptions() { - return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => + string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc"; + List exceptions = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc"; - List exceptions = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + exceptions.Add(new Exceptions() { - exceptions.Add(new Exceptions() - { - Id = (int)reader[0], - AppDomainName = (string)reader[1], - ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], - UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], - ExceptionType = (string)reader[5], - Message = (string)reader[6], - StackTrace = (string)reader[7], - LogTime = (DateTime)reader[8], - }); - } + Id = (int)reader[0], + AppDomainName = (string)reader[1], + ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], + UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], + ExceptionType = (string)reader[5], + Message = (string)reader[6], + StackTrace = (string)reader[7], + LogTime = (DateTime)reader[8], + }); } - return exceptions; - }); + } + return exceptions; } } } diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs index dd465c30..91075a6d 100644 --- a/Bootstrap.DataAccess/Group.cs +++ b/Bootstrap.DataAccess/Group.cs @@ -1,5 +1,4 @@ using Longbow; -using Longbow.Cache; using Longbow.Data; using System; using System.Collections.Generic; @@ -15,10 +14,6 @@ namespace Bootstrap.DataAccess /// public class Group { - public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups"; - public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId"; - public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId"; - public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName"; /// /// 获得/设置 群组主键ID /// @@ -45,26 +40,22 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveGroups(int id = 0) { - var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => + string sql = "select * from Groups"; + List groups = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Groups"; - List groups = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + groups.Add(new Group() { - groups.Add(new Group() - { - Id = LgbConvert.ReadValue(reader[0], 0), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + GroupName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] + }); } - return groups; - }); - return id == 0 ? ret : ret.Where(t => id == t.Id); + } + return groups; } /// /// 删除群组信息 @@ -112,29 +103,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveGroupsByUserId(int userId) { - string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId); - var ret = CacheManager.GetOrAdd(key, 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.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + groups.Add(new Group() { - groups.Add(new Group() - { - Id = LgbConvert.ReadValue(reader[0], 0), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + GroupName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + Checked = (string)reader[3] + }); } - return groups; - }, RetrieveGroupsByUserIdDataKey); - return ret; + } + return groups; } /// /// 保存用户部门关系 @@ -189,28 +175,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveGroupsByRoleId(int roleId) { - string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId); - return CacheManager.GetOrAdd(k, 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"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + groups.Add(new Group() { - groups.Add(new Group() - { - Id = LgbConvert.ReadValue(reader[0], 0), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + GroupName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + Checked = (string)reader[3] + }); } - return groups; - }, RetrieveGroupsByRoleIdDataKey); + } + return groups; } /// /// 根据角色ID以及选定的部门ID,保到角色部门表 @@ -260,27 +242,23 @@ namespace Bootstrap.DataAccess /// /// /// - /// /// public virtual IEnumerable RetrieveGroupsByUserName(string userName) { - return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => + var entities = new List(); + var db = DbAccessManager.DBAccess; + using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName")) { - var entities = new List(); - var db = DbAccessManager.DBAccess; - using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName")) + cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); + using (DbDataReader reader = db.ExecuteReader(cmd)) { - cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); - using (DbDataReader reader = db.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) - { - entities.Add((string)reader[0]); - } + entities.Add((string)reader[0]); } } - return entities; - }, RetrieveGroupsByUserNameDataKey); + } + return entities; } } } diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs index 1d23e168..b3a98c5c 100644 --- a/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -1,4 +1,5 @@ using Bootstrap.Security; +using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; @@ -9,6 +10,7 @@ namespace Bootstrap.DataAccess /// public static class DictHelper { + public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; /// /// /// @@ -38,7 +40,7 @@ namespace Bootstrap.DataAccess /// 获取字典分类名称 /// /// - public static IEnumerable RetrieveCategories() => DbAdapterManager.Create().RetrieveCategories(); + public static IEnumerable RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbAdapterManager.Create().RetrieveCategories()); /// /// /// diff --git a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs index 363a9754..85e7ec3e 100644 --- a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs +++ b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs @@ -1,4 +1,5 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -10,6 +11,10 @@ namespace Bootstrap.DataAccess /// public static class ExceptionsHelper { + /// + /// + /// + public const string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions"; /// /// /// @@ -21,6 +26,6 @@ namespace Bootstrap.DataAccess /// 查询一周内所有异常 /// /// - public static IEnumerable RetrieveExceptions() => DbAdapterManager.Create().RetrieveExceptions(); + public static IEnumerable RetrieveExceptions() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbAdapterManager.Create().RetrieveExceptions()); } } diff --git a/Bootstrap.DataAccess/Helper/GroupHelper.cs b/Bootstrap.DataAccess/Helper/GroupHelper.cs index 8aec4d4c..1a296e07 100644 --- a/Bootstrap.DataAccess/Helper/GroupHelper.cs +++ b/Bootstrap.DataAccess/Helper/GroupHelper.cs @@ -1,20 +1,30 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { /// - /// author:liuchun - /// date:2016.10.22 + /// /// public static class GroupHelper { + public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups"; + public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId"; + public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId"; + public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName"; /// /// 查询所有群组信息 /// /// /// - public static IEnumerable RetrieveGroups(int id = 0) => DbAdapterManager.Create().RetrieveGroups(id); + public static IEnumerable RetrieveGroups(int id = 0) + { + var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups(id)); + return id == 0 ? ret : ret.Where(t => id == t.Id); + } + /// /// 删除群组信息 /// @@ -31,7 +41,8 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByUserId(int userId) => DbAdapterManager.Create().RetrieveGroupsByUserId(userId); + public static IEnumerable RetrieveGroupsByUserId(int userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey); + /// /// 保存用户部门关系 /// @@ -44,7 +55,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByRoleId(int roleId) => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId); + public static IEnumerable RetrieveGroupsByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); /// /// 根据角色ID以及选定的部门ID,保到角色部门表 /// @@ -52,5 +63,11 @@ namespace Bootstrap.DataAccess /// /// public static bool SaveGroupsByRoleId(int id, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByRoleId(id, groupIds); + /// + /// + /// + /// + /// + public static IEnumerable RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey); } } diff --git a/Bootstrap.DataAccess/Helper/LogHelper.cs b/Bootstrap.DataAccess/Helper/LogHelper.cs index 9de1770b..1acff065 100644 --- a/Bootstrap.DataAccess/Helper/LogHelper.cs +++ b/Bootstrap.DataAccess/Helper/LogHelper.cs @@ -1,16 +1,30 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; +using System; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { + /// + /// + /// public static class LogHelper { + /// + /// + /// + public const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs"; /// /// 查询所有日志信息 /// /// /// - public static IEnumerable RetrieveLogs(string tId = null) => DbAdapterManager.Create().RetrieveLogs(tId); + public static IEnumerable RetrieveLogs(string tId = null) + { + var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create().RetrieveLogs(tId)); + return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase)); + } /// /// 保存新增的日志信息 /// diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index 3db2e986..9eec85aa 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -1,4 +1,5 @@ using Bootstrap.Security; +using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; @@ -9,6 +10,18 @@ namespace Bootstrap.DataAccess /// public static class MenuHelper { + /// + /// + /// + public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId"; + /// + /// + /// + public const string RetrieveMenusDataKey = "BootstrapMenu-RetrieveMenusByUserName"; + /// + /// + /// + public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus"; /// /// /// @@ -30,9 +43,12 @@ namespace Bootstrap.DataAccess /// /// /// - /// + /// /// - public static IEnumerable RetrieveMenusByRoleId(int id) => DbAdapterManager.Create().RetrieveMenusByRoleId(id); + public static IEnumerable RetrieveMenusByRoleId(int roleId) + { + return CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); + } /// /// /// diff --git a/Bootstrap.DataAccess/Helper/MessageHelper.cs b/Bootstrap.DataAccess/Helper/MessageHelper.cs index 66b6ae7b..a7d7daab 100644 --- a/Bootstrap.DataAccess/Helper/MessageHelper.cs +++ b/Bootstrap.DataAccess/Helper/MessageHelper.cs @@ -1,5 +1,7 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { @@ -8,6 +10,10 @@ namespace Bootstrap.DataAccess /// public static class MessageHelper { + /// + /// + /// + public const string RetrieveMessageDataKey = "MessageHelper-RetrieveMessages"; /// /// 收件箱 /// @@ -36,6 +42,6 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveMessagesHeader(string userName) => DbAdapterManager.Create().RetrieveMessagesHeader(userName); + public static IEnumerable RetrieveMessagesHeader(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbAdapterManager.Create().RetrieveMessagesHeader(userName).OrderByDescending(n => n.SendTime)); } } diff --git a/Bootstrap.DataAccess/Helper/RoleHelper.cs b/Bootstrap.DataAccess/Helper/RoleHelper.cs index 4cafdb3d..517a95c9 100644 --- a/Bootstrap.DataAccess/Helper/RoleHelper.cs +++ b/Bootstrap.DataAccess/Helper/RoleHelper.cs @@ -1,5 +1,7 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.DataAccess { @@ -8,24 +10,34 @@ namespace Bootstrap.DataAccess /// public static class RoleHelper { + public const string RetrieveRolesDataKey = "RoleHelper-RetrieveRoles"; + public const string RetrieveRolesByUserIdDataKey = "RoleHelper-RetrieveRolesByUserId"; + public const string RetrieveRolesByMenuIdDataKey = "RoleHelper-RetrieveRolesByMenuId"; + public const string RetrieveRolesByGroupIdDataKey = "RoleHelper-RetrieveRolesByGroupId"; + public const string RetrieveRolesByUserNameDataKey = "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName"; + public const string RetrieveRolesByUrlDataKey = "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl"; /// /// 查询所有角色 /// /// /// - public static IEnumerable RetrieveRoles(int id = 0) => DbAdapterManager.Create().RetrieveRoles(id); + public static IEnumerable RetrieveRoles(int id = 0) + { + var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create().RetrieveRoles(id)); + return id == 0 ? ret : ret.Where(t => id == t.Id); + } /// /// 保存用户角色关系 /// - /// + /// /// /// - public static bool SaveRolesByUserId(int id, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByUserId(id, roleIds); + public static bool SaveRolesByUserId(int userId, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByUserId(userId, roleIds); /// /// 查询某个用户所拥有的角色 /// /// - public static IEnumerable RetrieveRolesByUserId(int userId) => DbAdapterManager.Create().RetrieveRolesByUserId(userId); + public static IEnumerable RetrieveRolesByUserId(int userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey); /// /// 删除角色表 /// @@ -42,7 +54,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByMenuId(int menuId) => DbAdapterManager.Create().RetrieveRolesByMenuId(menuId); + public static IEnumerable RetrieveRolesByMenuId(int menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey); /// /// /// @@ -55,7 +67,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByGroupId(int groupId) => DbAdapterManager.Create().RetrieveRolesByGroupId(groupId); + public static IEnumerable RetrieveRolesByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey); /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 /// @@ -68,12 +80,12 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByUserName(string userName) => DbAdapterManager.Create().RetrieveRolesByUserName(userName); + public static IEnumerable RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => DbAdapterManager.Create().RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey); /// /// /// /// /// - public static IEnumerable RetrieveRolesByUrl(string url) => DbAdapterManager.Create().RetrieveRolesByUrl(url); + public static IEnumerable RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => DbAdapterManager.Create().RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey); } } \ No newline at end of file diff --git a/Bootstrap.DataAccess/Helper/TaskHelper.cs b/Bootstrap.DataAccess/Helper/TaskHelper.cs index 48c9a531..bde2deb1 100644 --- a/Bootstrap.DataAccess/Helper/TaskHelper.cs +++ b/Bootstrap.DataAccess/Helper/TaskHelper.cs @@ -1,14 +1,22 @@ -using Longbow.Data; +using Longbow.Cache; +using Longbow.Data; using System.Collections.Generic; namespace Bootstrap.DataAccess { + /// + /// + /// public static class TaskHelper { + /// + /// + /// + public const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks"; /// /// 查询所有任务 /// /// - public static IEnumerable RetrieveTasks() => DbAdapterManager.Create().RetrieveTasks(); + public static IEnumerable RetrieveTasks() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbAdapterManager.Create().RetrieveTasks()); } } diff --git a/Bootstrap.DataAccess/Helper/UserHelper.cs b/Bootstrap.DataAccess/Helper/UserHelper.cs index 6de19a36..6f14fdbd 100644 --- a/Bootstrap.DataAccess/Helper/UserHelper.cs +++ b/Bootstrap.DataAccess/Helper/UserHelper.cs @@ -1,4 +1,5 @@ using Bootstrap.Security; +using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; @@ -9,12 +10,17 @@ namespace Bootstrap.DataAccess /// public static class UserHelper { + public const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers"; + public const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId"; + public const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId"; + public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers"; + public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName"; /// /// 查询所有用户 /// /// /// - public static IEnumerable RetrieveUsers() => DbAdapterManager.Create().RetrieveUsers(); + public static IEnumerable RetrieveUsers() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbAdapterManager.Create().RetrieveUsers()); /// /// /// @@ -26,7 +32,7 @@ namespace Bootstrap.DataAccess /// 查询所有的新注册用户 /// /// - public static IEnumerable RetrieveNewUsers() => DbAdapterManager.Create().RetrieveNewUsers(); + public static IEnumerable RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbAdapterManager.Create().RetrieveNewUsers()); /// /// 删除用户 /// @@ -74,7 +80,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveUsersByRoleId(int roleId) => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId); + public static IEnumerable RetrieveUsersByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey); /// /// 通过角色ID保存当前授权用户(插入) /// @@ -87,7 +93,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveUsersByGroupId(int groupId) => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId); + public static IEnumerable RetrieveUsersByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey); /// /// 通过部门ID保存当前授权用户(插入) /// @@ -118,8 +124,8 @@ namespace Bootstrap.DataAccess /// /// /// - /// + /// /// - public static BootstrapUser RetrieveUserByUserName(string name) => DbAdapterManager.Create().RetrieveUserByUserName(name); + public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbAdapterManager.Create().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey); } } diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs index bf750cb1..75fc88c9 100644 --- a/Bootstrap.DataAccess/Log.cs +++ b/Bootstrap.DataAccess/Log.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using System.Linq; namespace Bootstrap.DataAccess { @@ -13,10 +12,6 @@ namespace Bootstrap.DataAccess /// public class Log { - /// - /// - /// - protected const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs"; /// /// 获得/设置 操作日志主键ID /// @@ -58,30 +53,26 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveLogs(string tId = null) { - var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => + string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0"; + List logs = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0"; - List logs = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + logs.Add(new Log() { - logs.Add(new Log() - { - Id = (int)reader[0], - CRUD = (string)reader[1], - UserName = (string)reader[2], - LogTime = (DateTime)reader[3], - ClientIp = (string)reader[4], - ClientAgent = (string)reader[5], - RequestUrl = (string)reader[6] - }); - } + Id = (int)reader[0], + CRUD = (string)reader[1], + UserName = (string)reader[2], + LogTime = (DateTime)reader[3], + ClientIp = (string)reader[4], + ClientAgent = (string)reader[5], + RequestUrl = (string)reader[6] + }); } - return logs; - }); - return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase)); + } + return logs; } /// /// 删除日志信息 @@ -116,7 +107,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheManager.Clear(RetrieveLogsDataKey); + CacheManager.Clear(LogHelper.RetrieveLogsDataKey); DeleteLogAsync(); return ret; } diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index a68bda8f..68ade37b 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -1,7 +1,6 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; using Longbow; -using Longbow.Cache; using Longbow.Data; using System; using System.Collections.Generic; @@ -17,18 +16,6 @@ namespace Bootstrap.DataAccess /// public class Menu : BootstrapMenu { - /// - /// - /// - public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId"; - /// - /// - /// - public const string RetrieveMenusDataKey = "BootstrapMenu-RetrieveMenusByUserName"; - /// - /// - /// - public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus"; /// /// 删除菜单信息 /// @@ -84,27 +71,23 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveMenusByRoleId(int roleId) { - string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId); - return CacheManager.GetOrAdd(key, k => + var menus = new List(); + string sql = "select NavigationID from NavigationRole where RoleID = @RoleID"; + using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) { - var menus = new List(); - string sql = "select NavigationID from NavigationRole where RoleID = @RoleID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + menus.Add(new BootstrapMenu() { - menus.Add(new BootstrapMenu() - { - Id = LgbConvert.ReadValue(reader[0], 0) - }); - } + Id = LgbConvert.ReadValue(reader[0], 0) + }); } } - return menus; - }, RetrieveMenusByRoleIdDataKey); + } + return menus; } /// /// 通过角色ID保存当前授权菜单 diff --git a/Bootstrap.DataAccess/Message.cs b/Bootstrap.DataAccess/Message.cs index c59bffa2..9f514b0e 100644 --- a/Bootstrap.DataAccess/Message.cs +++ b/Bootstrap.DataAccess/Message.cs @@ -1,5 +1,4 @@ using Longbow; -using Longbow.Cache; using System; using System.Collections.Generic; using System.Data; @@ -13,7 +12,6 @@ namespace Bootstrap.DataAccess /// public class Message { - protected const string RetrieveMessageDataKey = "MessageHelper-RetrieveMessages"; /// /// 消息主键 数据库自增 /// @@ -77,38 +75,33 @@ namespace Bootstrap.DataAccess /// protected virtual IEnumerable RetrieveMessages(string userName) { - var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key => + string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; + List messages = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; - List messages = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + messages.Add(new Message() { - messages.Add(new Message() - { - Id = (int)reader[0], - Title = (string)reader[1], - Content = (string)reader[2], - From = (string)reader[3], - To = (string)reader[4], - SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - Status = (string)reader[6], - Mark = (int)reader[7], - IsDelete = (int)reader[8], - Label = (string)reader[9], - LabelName = LgbConvert.ReadValue(reader[10], string.Empty), - FromIcon = (string)reader[11], - FromDisplayName = (string)reader[12] - }); - } + Id = (int)reader[0], + Title = (string)reader[1], + Content = (string)reader[2], + From = (string)reader[3], + To = (string)reader[4], + SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), + Status = (string)reader[6], + Mark = (int)reader[7], + IsDelete = (int)reader[8], + Label = (string)reader[9], + LabelName = LgbConvert.ReadValue(reader[10], string.Empty), + FromIcon = (string)reader[11], + FromDisplayName = (string)reader[12] + }); } - return messages; - - }); - return messageRet.OrderByDescending(n => n.SendTime); + } + return messages; } /// /// 收件箱 diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index b81288d2..3cd0c15d 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -1,6 +1,5 @@ using Bootstrap.Security.SQLServer; using Longbow; -using Longbow.Cache; using Longbow.Data; using System; using System.Collections.Generic; @@ -16,12 +15,6 @@ namespace Bootstrap.DataAccess /// public class Role { - public const string RetrieveRolesDataKey = "RoleHelper-RetrieveRoles"; - public const string RetrieveRolesByUserIdDataKey = "RoleHelper-RetrieveRolesByUserId"; - public const string RetrieveRolesByMenuIdDataKey = "RoleHelper-RetrieveRolesByMenuId"; - public const string RetrieveRolesByGroupIdDataKey = "RoleHelper-RetrieveRolesByGroupId"; - public const string RetrieveRolesByUserNameDataKey = "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName"; - public const string RetrieveRolesByUrlDataKey = "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl"; /// /// 获得/设置 角色主键ID /// @@ -45,26 +38,22 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveRoles(int id = 0) { - var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key => + string sql = "select * from Roles"; + var roles = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select * from Roles"; - var roles = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + roles.Add(new Role() { - roles.Add(new Role() - { - Id = LgbConvert.ReadValue(reader[0], 0), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + RoleName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] + }); } - return roles; - }); - return id == 0 ? ret : ret.Where(t => id == t.Id); + } + return roles; } /// /// 保存用户角色关系 @@ -119,28 +108,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveRolesByUserId(int userId) { - string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId); - return CacheManager.GetOrAdd(key, 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"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + roles.Add(new Role() { - roles.Add(new Role() - { - Id = LgbConvert.ReadValue(reader[0], 0), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + RoleName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + Checked = (string)reader[3] + }); } - return roles; - }, RetrieveRolesByUserIdDataKey); + } + return roles; } /// /// 删除角色表 @@ -188,29 +173,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveRolesByMenuId(int menuId) { - string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId); - var ret = CacheManager.GetOrAdd(key, 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.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + roles.Add(new Role() { - roles.Add(new Role() - { - Id = LgbConvert.ReadValue(reader[0], 0), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + RoleName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + Checked = (string)reader[3] + }); } - return roles; - }, RetrieveRolesByMenuIdDataKey); - return ret; + } + return roles; } /// /// @@ -265,28 +245,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveRolesByGroupId(int groupId) { - string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId); - return CacheManager.GetOrAdd(key, 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"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + roles.Add(new Role() { - roles.Add(new Role() - { - Id = LgbConvert.ReadValue(reader[0], 0), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + RoleName = (string)reader[1], + Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], + Checked = (string)reader[3] + }); } - return roles; - }, RetrieveRolesByGroupIdDataKey); + } + return roles; } /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 diff --git a/Bootstrap.DataAccess/Task.cs b/Bootstrap.DataAccess/Task.cs index 2780aca5..1d308504 100644 --- a/Bootstrap.DataAccess/Task.cs +++ b/Bootstrap.DataAccess/Task.cs @@ -1,5 +1,4 @@ -using Longbow.Cache; -using System; +using System; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -8,7 +7,6 @@ namespace Bootstrap.DataAccess { public class Task { - protected const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks"; /// /// 获取/设置 任务ID /// @@ -47,30 +45,27 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveTasks() { - return CacheManager.GetOrAdd(RetrieveTasksDataKey, key => + string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc"; + List tasks = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc"; - List tasks = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + tasks.Add(new Task() { - tasks.Add(new Task() - { - Id = (int)reader[0], - TaskName = (string)reader[1], - AssignName = (string)reader[2], - UserName = (string)reader[3], - TaskTime = (int)reader[4], - TaskProgress = (double)reader[5], - AssignTime = (DateTime)reader[6], - AssignDisplayName = (string)reader[7] - }); - } + Id = (int)reader[0], + TaskName = (string)reader[1], + AssignName = (string)reader[2], + UserName = (string)reader[3], + TaskTime = (int)reader[4], + TaskProgress = (double)reader[5], + AssignTime = (DateTime)reader[6], + AssignDisplayName = (string)reader[7] + }); } - return tasks; - }); + } + return tasks; } } } diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index 28aa43e2..af3e82c7 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -1,7 +1,6 @@ using Bootstrap.Security; using Bootstrap.Security.SQLServer; using Longbow; -using Longbow.Cache; using Longbow.Data; using Longbow.Security.Cryptography; using System; @@ -18,11 +17,6 @@ namespace Bootstrap.DataAccess /// public class User : BootstrapUser { - public const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers"; - public const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId"; - public const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId"; - public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers"; - protected const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName"; /// /// 获得/设置 用户主键ID /// @@ -126,29 +120,26 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveUsers() { - return CacheManager.GetOrAdd(RetrieveUsersDataKey, key => - { - List users = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); + List users = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + { + while (reader.Read()) { - while (reader.Read()) + users.Add(new User() { - users.Add(new User() - { - Id = LgbConvert.ReadValue(reader[0], 0), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue), - ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5], - Description = (string)reader[6] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + UserName = (string)reader[1], + DisplayName = (string)reader[2], + RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), + ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue), + ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5], + Description = (string)reader[6] + }); } - return users; - }); + } + return users; } /// /// 查询所有的新注册用户 @@ -156,27 +147,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveNewUsers() { - return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => + string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc"; + List users = new List(); + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc"; - List users = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + users.Add(new User() { - users.Add(new User() - { - Id = LgbConvert.ReadValue(reader[0], 0), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - Description = (string)reader[4] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + UserName = (string)reader[1], + DisplayName = (string)reader[2], + RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), + Description = (string)reader[4] + }); } - return users; - }); + } + return users; } /// /// 删除用户 @@ -289,28 +277,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveUsersByRoleId(int roleId) { - string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId); - return CacheManager.GetOrAdd(key, 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 where u.ApprovedTime is not null"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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 where u.ApprovedTime is not null"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + users.Add(new User() { - users.Add(new User() - { - Id = LgbConvert.ReadValue(reader[0], 0), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + UserName = (string)reader[1], + DisplayName = (string)reader[2], + Checked = (string)reader[3] + }); } - return users; - }, RetrieveUsersByRoleIdDataKey); + } + return users; } /// /// 通过角色ID保存当前授权用户(插入) @@ -362,28 +346,24 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveUsersByGroupId(int groupId) { - string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId); - return CacheManager.GetOrAdd(key, 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 where u.ApprovedTime is not null"; + DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); + cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); + using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) { - 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 where u.ApprovedTime is not null"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) + while (reader.Read()) { - while (reader.Read()) + users.Add(new User() { - users.Add(new User() - { - Id = LgbConvert.ReadValue(reader[0], 0), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - Checked = (string)reader[3] - }); - } + Id = LgbConvert.ReadValue(reader[0], 0), + UserName = (string)reader[1], + DisplayName = (string)reader[2], + Checked = (string)reader[3] + }); } - return users; - }, RetrieveUsersByRoleIdDataKey); + } + return users; } /// /// 通过部门ID保存当前授权用户(插入) @@ -444,7 +424,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@iconName", iconName)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*"); + if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*"); } return ret; } @@ -463,7 +443,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*"); + if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*"); } return ret; } @@ -482,7 +462,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAdapterManager.ToDBValue(cssName))); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*"); + if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*"); } return ret; }