public IActionResult GetAdminRoleBindUserList(string userName, string roleId, int limit, int page)
        {
            if (string.IsNullOrEmpty(roleId))
            {
                return(Json(new RoleAndUserRelationResponse()
                {
                    msg = "关联角色信息失败", code = -1
                }));
            }
            try
            {
                var paramRequest = new RoleAndUserRelationRequest
                {
                    UserName  = userName,
                    RoleId    = roleId,
                    PageIndex = page,
                    PageSize  = limit
                };
                var result = _roleService.QueryRoleBindUser(paramRequest);

                return(Json(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"获取角色绑定列表异常:{ex.ToString() + ex.StackTrace}");
                return(Json(new RoleAndUserRelationResponse()
                {
                    msg = "异常", code = -1
                }));
            }
        }
Exemplo n.º 2
0
        public RoleAndUserRelationResponse QueryRoleBindUser(RoleAndUserRelationRequest request)
        {
            int total    = 0;
            var pageList = roleAndUserRelation.QueryRoleBindUser(request, out total);

            RoleAndUserRelationResponse page = new RoleAndUserRelationResponse();

            if (pageList != null && pageList.Count > 0)
            {
                page.code  = 0;
                page.msg   = "success";
                page.count = total;
                page.data  = pageList;
            }
            else
            {
                page.msg  = "无数据";
                page.code = -1;
            }
            return(page);
        }
        public List <RoleAndUserRelationEntity> QueryRoleBindUser(RoleAndUserRelationRequest request, out int total)
        {
            total = 0;
            List <RoleAndUserRelationEntity> list = new List <RoleAndUserRelationEntity>();
            StringBuilder sq = new StringBuilder();

            sq.Append(" select * from ( ");
            sq.Append(" select {2} from tblRoleAndUserRelation r inner join tblAdminUser u on r.UserMasterId = u.Id   ");
            sq.Append(" inner join tblAdminRole o on o.Id = r.RoleId ");
            sq.Append(" where {0} ");
            sq.Append(" ) c where {1} ");
            DynamicParameters dp      = new DynamicParameters();
            string            where_1 = " 1=1 ";

            if (!string.IsNullOrWhiteSpace(request.UserName))
            {
                where_1 += " and u.UserName=@UserName";
                dp.Add("UserName", request.UserName, DbType.String, ParameterDirection.Input, 50);
            }
            if (!string.IsNullOrWhiteSpace(request.RoleId))
            {
                where_1 += " and r.RoleId=@RoleId";
                dp.Add("RoleId", request.RoleId, DbType.String, ParameterDirection.Input, 50);
            }
            dp.Add("PageIndex", request.PageIndex, DbType.Int32, ParameterDirection.Input);
            dp.Add("PageSize", request.PageSize, DbType.Int32, ParameterDirection.Input);

            string sql_list = string.Format(sq.ToString(), where_1, " c.Num > (@PageIndex - 1) * @PageSize and c.Num <= @PageIndex * @PageSize", "ROW_NUMBER() over(order by r.CreateTime desc) as Num,o.RoleName,u.UserName,r.CreateTime,r.CreateUser,u.RealName,u.MobilePhone ");

            string sql_count = string.Format(sq.ToString(), where_1, "1=1", "count(0) as nums");

            using (IDbConnection conn = new SqlConnection(DbConnectionStringConfig.Default.MyShopConnectionString))
            {
                total = conn.Query <int>(sql_count, dp).FirstOrDefault();
                list  = conn.Query <RoleAndUserRelationEntity>(sql_list, dp).ToList();
            }
            return(list);
        }