public void ClearRoleUserCache(long roleId) { //user2role 找到userid var userIdLst = User2RoleRepository .QueryEnable() .Where(m => m.RoleId == roleId) .Select(m => m.UserId) .ToList(); //user2apart role2apart 找到userid var user2ApartQuery = User2ApartRepository .QueryEnable(); var role2ApartQuery = Role2ApartRepository .QueryEnable() .Where(m => m.RoleId == roleId); var apart2UserIdList = user2ApartQuery .Join(role2ApartQuery, u2a => u2a.ApartmentId, r2a => r2a.ApartmentId, (u2a, r2a) => u2a.UserId); //合集 userIdLst.AddRange(apart2UserIdList); //剔除重复 userIdLst = userIdLst.Distinct().ToList(); //清除缓存 foreach (var userId in userIdLst) { Cache.Remove(Users.GIdPrefix + userId); } }
public List <long> GetRoleIdList(long userId) { if (userId == 0) { return(new List <long>()); } //用户x角色 var user2RoleIdList = User2RoleRepository .QueryEnable() .Where(m => m.UserId == userId) .Select(m => m.RoleId) .ToList(); //用户x部门x角色 var user2ApartQuery = User2ApartRepository .QueryEnable() .Where(m => m.UserId == userId); var role2ApartQuery = Role2ApartRepository .QueryEnable(); var apart2RoleIdList = user2ApartQuery .Join(role2ApartQuery, u2a => u2a.ApartmentId, r2a => r2a.ApartmentId, (u2a, r2a) => r2a.RoleId); //RoleIdList user2RoleIdList.AddRange(apart2RoleIdList); var roleIdList = user2RoleIdList .Distinct() .ToList(); return(roleIdList); }