2018-10-28 15:03:59 +08:00
|
|
|
|
using Longbow.Cache;
|
|
|
|
|
using Longbow.Data;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-10-28 15:03:59 +08:00
|
|
|
|
///
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static class GroupHelper
|
|
|
|
|
{
|
2018-10-28 15:03:59 +08:00
|
|
|
|
public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
|
|
|
|
|
public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
|
|
|
|
|
public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
|
2018-10-28 21:14:03 +08:00
|
|
|
|
public const string RetrieveGroupsByUserNameDataKey = "GroupHelper-RetrieveGroupsByUserName";
|
2018-10-31 09:51:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询所有群组信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public static IEnumerable<Group> RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create<Group>().RetrieveGroups());
|
2018-10-31 09:51:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除群组信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
2018-10-31 09:51:28 +08:00
|
|
|
|
public static bool DeleteGroup(IEnumerable<string> value)
|
|
|
|
|
{
|
|
|
|
|
var ret = DbAdapterManager.Create<Group>().DeleteGroup(value);
|
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(groupIds: value);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存新建/更新的群组信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-31 09:51:28 +08:00
|
|
|
|
public static bool SaveGroup(Group p)
|
|
|
|
|
{
|
|
|
|
|
var ret = DbAdapterManager.Create<Group>().SaveGroup(p);
|
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户查询部门信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public static IEnumerable<Group> RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create<Group>().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey);
|
2018-10-28 15:03:59 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存用户部门关系
|
|
|
|
|
/// </summary>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
/// <param name="userId"></param>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-31 09:51:28 +08:00
|
|
|
|
public static bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
|
|
|
|
|
{
|
|
|
|
|
var ret = DbAdapterManager.Create<Group>().SaveGroupsByUserId(userId, groupIds);
|
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<string>() { userId });
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色ID指派部门
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
public static IEnumerable<Group> RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create<Group>().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
|
2018-10-31 09:51:28 +08:00
|
|
|
|
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
|
|
|
|
/// </summary>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
/// <param name="roleId"></param>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <param name="groupIds"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-31 09:51:28 +08:00
|
|
|
|
public static bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
|
|
|
|
|
{
|
|
|
|
|
var ret = DbAdapterManager.Create<Group>().SaveGroupsByRoleId(roleId, groupIds);
|
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<string>() { roleId });
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 15:03:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IEnumerable<string> RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create<Group>().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey);
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|