重构代码:根据最新的Longbow.Caching.CacheManager方法重构,调整函数接口,支持相对过期时间

This commit is contained in:
Argo-Lenovo 2017-04-05 11:54:21 +08:00
parent ba08d6ceac
commit dddb07d623
11 changed files with 38 additions and 48 deletions

View File

@ -36,9 +36,8 @@ namespace Bootstrap.Admin.Controllers
string password = user.password; string password = user.password;
if (LgbPrincipal.Authenticate(userName, password) || BootstrapUser.Authenticate(userName, password)) if (LgbPrincipal.Authenticate(userName, password) || BootstrapUser.Authenticate(userName, password))
{ {
var interval = int.Parse(Math.Round(FormsAuthentication.Timeout.TotalSeconds).ToString(CultureInfo.InvariantCulture)); var token = CacheManager.AddOrUpdate(string.Format("WebApi-{0}", userName), k => new LoginInfo() { UserName = userName, Token = Guid.NewGuid().ToString() }, (k, info) => info, "WebApi");
var token = CacheManager.AddOrUpdate(string.Format("WebApi-{0}", userName), interval, k => new LoginInfo() { UserName = userName, Token = Guid.NewGuid().ToString() }, (k, info) => info, "WebApi 数据缓存"); CacheManager.AddOrUpdate(token.Token, k => token, (k, info) => info, "Token");
CacheManager.AddOrUpdate(token.Token, interval, k => token, (k, info) => info, "Token 数据缓存");
return token; return token;
} }
return new LoginInfo() { UserName = userName }; return new LoginInfo() { UserName = userName };

View File

@ -1,6 +1,5 @@
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -123,7 +122,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveCategories() public static IEnumerable<BootstrapDict> RetrieveCategories()
{ {
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, CacheSection.RetrieveIntervalByKey(RetrieveCategoryDataKey), key => return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
{ {
var ret = new List<BootstrapDict>(); var ret = new List<BootstrapDict>();
string sql = "select distinct Category from Dicts"; string sql = "select distinct Category from Dicts";
@ -140,7 +139,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return ret; return ret;
}, CacheSection.RetrieveDescByKey(RetrieveCategoryDataKey)); });
} }
/// <summary> /// <summary>
/// ///

View File

@ -1,5 +1,4 @@
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data; using Longbow.Data;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
@ -53,7 +52,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Exceptions> RetrieveExceptions() public static IEnumerable<Exceptions> RetrieveExceptions()
{ {
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveExceptionsDataKey), key => return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
{ {
string sql = "select top 1000 * from Exceptions order by LogTime desc"; string sql = "select top 1000 * from Exceptions order by LogTime desc";
List<Exceptions> exceptions = new List<Exceptions>(); List<Exceptions> exceptions = new List<Exceptions>();
@ -81,7 +80,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return exceptions; return exceptions;
}, CacheSection.RetrieveDescByKey(RetrieveExceptionsDataKey)); });
} }
} }
} }

View File

@ -1,5 +1,4 @@
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data; using Longbow.Data;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
@ -27,7 +26,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Group> RetrieveGroups(int id = 0) public static IEnumerable<Group> RetrieveGroups(int id = 0)
{ {
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveGroupsDataKey), key => var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
{ {
string sql = "select * from Groups"; string sql = "select * from Groups";
List<Group> groups = new List<Group>(); List<Group> groups = new List<Group>();
@ -49,7 +48,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups; return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsDataKey)); });
return id == 0 ? ret : ret.Where(t => id == t.Id); return id == 0 ? ret : ret.Where(t => id == t.Id);
} }
/// <summary> /// <summary>
@ -115,7 +114,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId) public static IEnumerable<Group> RetrieveGroupsByUserId(int userId)
{ {
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId); string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByUserIdDataKey), k => 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"; 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<Group> groups = new List<Group>(); List<Group> groups = new List<Group>();
@ -139,7 +138,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups; return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsByUserIdDataKey)); }, RetrieveGroupsByUserIdDataKey);
return ret; return ret;
} }
/// <summary> /// <summary>
@ -197,7 +196,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId) public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
{ {
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId); string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByRoleIdDataKey), key => return CacheManager.GetOrAdd(k, key =>
{ {
List<Group> groups = new List<Group>(); List<Group> groups = new List<Group>();
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"; 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";
@ -221,7 +220,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups; return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsByRoleIdDataKey)); }, RetrieveGroupsByRoleIdDataKey);
} }
/// <summary> /// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表 /// 根据角色ID以及选定的部门ID保到角色部门表

View File

@ -1,5 +1,4 @@
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -20,7 +19,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Log> RetrieveLogs(string tId = null) public static IEnumerable<Log> RetrieveLogs(string tId = null)
{ {
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveLogsDataKey), key => var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
{ {
string sql = "select top 1000 * from Logs"; string sql = "select top 1000 * from Logs";
List<Log> logs = new List<Log>(); List<Log> logs = new List<Log>();
@ -46,7 +45,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return logs; return logs;
}, CacheSection.RetrieveDescByKey(RetrieveLogsDataKey)); });
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase)); return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,5 @@
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data; using Longbow.Data;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
@ -91,7 +90,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId) public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
{ {
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId); string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusByRoleIdDataKey), k => return CacheManager.GetOrAdd(key, k =>
{ {
var menus = new List<BootstrapMenu>(); var menus = new List<BootstrapMenu>();
try try
@ -114,7 +113,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return menus; return menus;
}, CacheSection.RetrieveDescByKey(RetrieveMenusByRoleIdDataKey)); }, RetrieveMenusByRoleIdDataKey);
} }
/// <summary> /// <summary>
/// 通过角色ID保存当前授权菜单 /// 通过角色ID保存当前授权菜单

View File

@ -1,6 +1,5 @@
using Longbow; using Longbow;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -23,7 +22,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
private static IEnumerable<Message> RetrieveMessages(string userName) private static IEnumerable<Message> RetrieveMessages(string userName)
{ {
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageDataKey), key => var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
{ {
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/Content/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"; string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/Content/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<Message> messages = new List<Message>(); List<Message> messages = new List<Message>();
@ -57,7 +56,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return messages; return messages;
}, CacheSection.RetrieveDescByKey(RetrieveMessageDataKey)); });
return messageRet.OrderByDescending(n => n.SendTime); return messageRet.OrderByDescending(n => n.SendTime);
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,5 @@
using Longbow; using Longbow;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,7 +21,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Notification> RetrieveNotifications() public static IEnumerable<Notification> RetrieveNotifications()
{ {
var notifies = CacheManager.GetOrAdd(RetrieveNotificationsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotificationsDataKey), key => var notifies = CacheManager.GetOrAdd(RetrieveNotificationsDataKey, key =>
{ {
string sql = "select * from Notifications"; string sql = "select * from Notifications";
List<Notification> notifications = new List<Notification>(); List<Notification> notifications = new List<Notification>();
@ -51,7 +50,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return notifications; return notifications;
}, CacheSection.RetrieveDescByKey(RetrieveNotificationsDataKey)); });
notifies.AsParallel().ForAll(n => notifies.AsParallel().ForAll(n =>
{ {
var ts = DateTime.Now - n.RegisterTime; var ts = DateTime.Now - n.RegisterTime;

View File

@ -27,7 +27,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Role> RetrieveRoles(int id = 0) public static IEnumerable<Role> RetrieveRoles(int id = 0)
{ {
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, CacheSection.RetrieveIntervalByKey(RetrieveRolesDataKey), key => var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
{ {
string sql = "select * from Roles"; string sql = "select * from Roles";
List<Role> roles = new List<Role>(); List<Role> roles = new List<Role>();
@ -49,7 +49,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles; return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesDataKey)); });
return id == 0 ? ret : ret.Where(t => id == t.Id); return id == 0 ? ret : ret.Where(t => id == t.Id);
} }
/// <summary> /// <summary>
@ -107,7 +107,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByUserId(int userId) public static IEnumerable<Role> RetrieveRolesByUserId(int userId)
{ {
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId); string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByUserIdDataKey), k => return CacheManager.GetOrAdd(key, k =>
{ {
List<Role> roles = new List<Role>(); List<Role> roles = new List<Role>();
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"; 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";
@ -131,7 +131,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles; return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByUserIdDataKey)); }, RetrieveRolesByUserIdDataKey);
} }
/// <summary> /// <summary>
/// 删除角色表 /// 删除角色表
@ -196,7 +196,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId) public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
{ {
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId); string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByMenuIdDataKey), k => 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"; 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<Role> roles = new List<Role>(); List<Role> roles = new List<Role>();
@ -220,7 +220,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles; return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByMenuIdDataKey)); }, RetrieveRolesByMenuIdDataKey);
return ret; return ret;
} }
public static bool SavaRolesByMenuId(int id, string roleIds) public static bool SavaRolesByMenuId(int id, string roleIds)
@ -272,7 +272,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId) public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
{ {
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId); string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByGroupIdDataKey), k => return CacheManager.GetOrAdd(key, k =>
{ {
List<Role> roles = new List<Role>(); List<Role> roles = new List<Role>();
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"; 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";
@ -296,7 +296,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles; return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByGroupIdDataKey)); }, RetrieveRolesByGroupIdDataKey);
} }
/// <summary> /// <summary>

View File

@ -1,5 +1,4 @@
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -17,7 +16,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Task> RetrieveTasks() public static IEnumerable<Task> RetrieveTasks()
{ {
return CacheManager.GetOrAdd(RetrieveTasksDataKey, CacheSection.RetrieveIntervalByKey(RetrieveTasksDataKey), key => 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"; 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<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();
@ -44,7 +43,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return tasks; return tasks;
}, CacheSection.RetrieveDescByKey(RetrieveTasksDataKey)); });
} }
} }
} }

View File

@ -1,7 +1,6 @@
using Bootstrap.Security; using Bootstrap.Security;
using Longbow; using Longbow;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data; using Longbow.Data;
using Longbow.ExceptionManagement; using Longbow.ExceptionManagement;
using Longbow.Security; using Longbow.Security;
@ -30,7 +29,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<User> RetrieveUsers() public static IEnumerable<User> RetrieveUsers()
{ {
return CacheManager.GetOrAdd(BootstrapUser.RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(BootstrapUser.RetrieveUsersDataKey), key => return CacheManager.GetOrAdd(BootstrapUser.RetrieveUsersDataKey, key =>
{ {
List<User> users = new List<User>(); List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
@ -55,7 +54,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return users; return users;
}, CacheSection.RetrieveDescByKey(BootstrapUser.RetrieveUsersDataKey)); });
} }
/// <summary> /// <summary>
/// 查询所有的新注册用户 /// 查询所有的新注册用户
@ -63,7 +62,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns> /// <returns></returns>
public static IEnumerable<User> RetrieveNewUsers() public static IEnumerable<User> RetrieveNewUsers()
{ {
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNewUsersDataKey), key => return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
{ {
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null order by RegisterTime desc"; string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null order by RegisterTime desc";
List<User> users = new List<User>(); List<User> users = new List<User>();
@ -87,7 +86,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return users; return users;
}, CacheSection.RetrieveDescByKey(RetrieveNewUsersDataKey)); });
} }
/// <summary> /// <summary>
/// 删除用户 /// 删除用户
@ -161,7 +160,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId) public static IEnumerable<User> RetrieveUsersByRoleId(int roleId)
{ {
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId); string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k => return CacheManager.GetOrAdd(key, k =>
{ {
List<User> users = new List<User>(); List<User> users = new List<User>();
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"; 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";
@ -185,7 +184,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return users; return users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIdDataKey)); }, RetrieveUsersByRoleIdDataKey);
} }
/// <summary> /// <summary>
/// 通过角色ID保存当前授权用户插入 /// 通过角色ID保存当前授权用户插入
@ -239,7 +238,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId) public static IEnumerable<User> RetrieveUsersByGroupId(int groupId)
{ {
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId); string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByGroupIdDataKey), k => return CacheManager.GetOrAdd(key, k =>
{ {
List<User> users = new List<User>(); List<User> users = new List<User>();
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"; 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";
@ -263,7 +262,7 @@ namespace Bootstrap.DataAccess
} }
catch (Exception ex) { ExceptionManager.Publish(ex); } catch (Exception ex) { ExceptionManager.Publish(ex); }
return users; return users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIdDataKey)); }, RetrieveUsersByRoleIdDataKey);
} }
/// <summary> /// <summary>
/// 通过部门ID保存当前授权用户插入 /// 通过部门ID保存当前授权用户插入