using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; namespace Bootstrap.DataAccess { /// /// /// 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 = "GroupHelper-RetrieveGroupsByUserName"; /// /// 查询所有群组信息 /// /// /// public static IEnumerable RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups()); /// /// 删除群组信息 /// /// public static bool DeleteGroup(IEnumerable value) => DbAdapterManager.Create().DeleteGroup(value); /// /// 保存新建/更新的群组信息 /// /// /// public static bool SaveGroup(Group p) => DbAdapterManager.Create().SaveGroup(p); /// /// 根据用户查询部门信息 /// /// /// public static IEnumerable RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey); /// /// 保存用户部门关系 /// /// /// /// public static bool SaveGroupsByUserId(string userId, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByUserId(userId, groupIds); /// /// 根据角色ID指派部门 /// /// /// public static IEnumerable RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); /// /// 根据角色ID以及选定的部门ID,保到角色部门表 /// /// /// /// public static bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByRoleId(roleId, groupIds); /// /// /// /// /// public static IEnumerable RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey); } }