/// <summary>
        ///     根据组织机构Id查询角色信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IEnumerable <SystemRoleOutput> > GetRolesByOrganizationId(SystemRolesGetByOrganizationId input)
        {
            var data    = (await _roleRepository.GetRolesByOrganizationId(input)).ToList();
            var allOrgs = (await _organizationRepository.FindAllAsync()).ToList();

            foreach (var user in data)
            {
                var organization = allOrgs.FirstOrDefault(w => w.OrganizationId == user.OrganizationId);
                if (organization != null && !organization.ParentIds.IsNullOrEmpty())
                {
                    foreach (var parent in organization.ParentIds.Split(','))
                    {
                        //查找上级
                        var dicinfo = allOrgs.FirstOrDefault(w => w.OrganizationId.ToString() == parent);
                        if (dicinfo != null)
                        {
                            user.OrganizationNames += dicinfo.Name + ">";
                        }
                    }
                    if (!user.OrganizationNames.IsNullOrEmpty())
                    {
                        user.OrganizationNames = user.OrganizationNames.TrimEnd('>');
                    }
                }
            }
            return(data);
        }
Exemple #2
0
        /// <summary>
        ///     根据组织机构获取角色信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Task <IEnumerable <SystemRoleOutput> > GetRolesByOrganizationId(SystemRolesGetByOrganizationId input)
        {
            var sql =
                new StringBuilder(
                    @"SELECT role.*,org.CreateUserId,org.CreateUserName,org.UpdateTime,org.UpdateUserId,org.UpdateUserName,org.Name OrganizationName FROM System_Role role
                                                    LEFT JOIN System_Organization org ON org.OrganizationId=role.OrganizationId WHERE 1=1");

            if (input != null && !input.Id.IsNullOrEmptyGuid())
            {
                sql.Append(@" AND role.OrganizationId in(
                select org.OrganizationId from System_Organization org where org.ParentIds  like '" + (input.Id + ",").Replace(",", @"\,") + "%" + "' escape '\\' OR OrganizationId = '" + input.Id + "') ");
            }
            if (input != null)
            {
                sql.Append(input.Sql);
            }
            sql.Append(" ORDER BY role.OrganizationId,role.OrderNo");
            if (input != null && !input.Id.IsNullOrEmptyGuid())
            {
                return(SqlMapperUtil.SqlWithParams <SystemRoleOutput>(sql.ToString(), new { orgId = input.Id }));
            }
            return(SqlMapperUtil.SqlWithParams <SystemRoleOutput>(sql.ToString()));
        }
 public async Task <JsonResult> GetRolesByOrganization(SystemRolesGetByOrganizationId input)
 {
     return(JsonForGridLoadOnce(await _roleLogic.GetRolesByOrganizationId(input)));
 }