public async Task <JsonResult> GetPageList()
        {
            var jm = new AdminUiCallBack();

            //获取数据
            var list = await _sysOrganizationServices.QueryAsync();

            //返回数据
            jm.data  = list;
            jm.code  = 0;
            jm.count = list.Count;
            jm.msg   = "数据调用成功!";
            return(new JsonResult(jm));
        }
예제 #2
0
        public async Task <JsonResult> GetPageList()
        {
            var jm          = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize    = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);

            var where = PredicateBuilder.True <SysUser>();
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
            Expression <Func <SysUser, object> > orderEx;

            switch (orderField)
            {
            case "id":
                orderEx = p => p.id;
                break;

            case "userName":
                orderEx = p => p.userName;
                break;

            case "passWord":
                orderEx = p => p.passWord;
                break;

            case "nickName":
                orderEx = p => p.nickName;
                break;

            case "avatar":
                orderEx = p => p.avatar;
                break;

            case "sex":
                orderEx = p => p.sex;
                break;

            case "phone":
                orderEx = p => p.phone;
                break;

            case "email":
                orderEx = p => p.email;
                break;

            case "emailVerified":
                orderEx = p => p.emailVerified;
                break;

            case "trueName":
                orderEx = p => p.trueName;
                break;

            case "idCard":
                orderEx = p => p.idCard;
                break;

            case "birthday":
                orderEx = p => p.birthday;
                break;

            case "introduction":
                orderEx = p => p.introduction;
                break;

            case "organizationId":
                orderEx = p => p.organizationId;
                break;

            case "state":
                orderEx = p => p.state;
                break;

            case "deleted":
                orderEx = p => p.deleted;
                break;

            case "createTime":
                orderEx = p => p.createTime;
                break;

            case "updateTime":
                orderEx = p => p.updateTime;
                break;

            default:
                orderEx = p => p.id;
                break;
            }

            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy        = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选

            //用户id int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);

            if (id > 0)
            {
                @where = @where.And(p => p.id == id);
            }
            //账号 nvarchar
            var userName = Request.Form["userName"].FirstOrDefault();

            if (!string.IsNullOrEmpty(userName))
            {
                @where = @where.And(p => p.userName.Contains(userName));
            }
            //密码 nvarchar
            var passWord = Request.Form["passWord"].FirstOrDefault();

            if (!string.IsNullOrEmpty(passWord))
            {
                @where = @where.And(p => p.passWord.Contains(passWord));
            }
            //昵称 nvarchar
            var nickName = Request.Form["nickName"].FirstOrDefault();

            if (!string.IsNullOrEmpty(nickName))
            {
                @where = @where.And(p => p.nickName.Contains(nickName));
            }
            //头像 nvarchar
            var avatar = Request.Form["avatar"].FirstOrDefault();

            if (!string.IsNullOrEmpty(avatar))
            {
                @where = @where.And(p => p.avatar.Contains(avatar));
            }
            //性别 int
            var sex = Request.Form["sex"].FirstOrDefault().ObjectToInt(0);

            if (sex > 0)
            {
                @where = @where.And(p => p.sex == sex);
            }
            //手机号 nvarchar
            var phone = Request.Form["phone"].FirstOrDefault();

            if (!string.IsNullOrEmpty(phone))
            {
                @where = @where.And(p => p.phone.Contains(phone));
            }
            //邮箱 nvarchar
            var email = Request.Form["email"].FirstOrDefault();

            if (!string.IsNullOrEmpty(email))
            {
                @where = @where.And(p => p.email.Contains(email));
            }
            //邮箱是否验证 bit
            var emailVerified = Request.Form["emailVerified"].FirstOrDefault();

            if (!string.IsNullOrEmpty(emailVerified) && emailVerified.ToLowerInvariant() == "true")
            {
                @where = @where.And(p => p.emailVerified);
            }
            else if (!string.IsNullOrEmpty(emailVerified) && emailVerified.ToLowerInvariant() == "false")
            {
                @where = @where.And(p => p.emailVerified == false);
            }
            //真实姓名 nvarchar
            var trueName = Request.Form["trueName"].FirstOrDefault();

            if (!string.IsNullOrEmpty(trueName))
            {
                @where = @where.And(p => p.trueName.Contains(trueName));
            }
            //身份证号 nvarchar
            var idCard = Request.Form["idCard"].FirstOrDefault();

            if (!string.IsNullOrEmpty(idCard))
            {
                @where = @where.And(p => p.idCard.Contains(idCard));
            }
            //个人简介 nvarchar
            var introduction = Request.Form["introduction"].FirstOrDefault();

            if (!string.IsNullOrEmpty(introduction))
            {
                @where = @where.And(p => p.introduction.Contains(introduction));
            }
            //机构id int
            var organizationId = Request.Form["organizationId"].FirstOrDefault().ObjectToInt(0);

            if (organizationId > 0)
            {
                //where = where.And(p => p.organizationId == organizationId);
                var o = await _sysOrganizationServices.QueryAsync();

                var ids = new List <int>();
                SysOrganizationHelper.GetOrganizeChildIds(o, organizationId, ref ids);
                if (ids.Any())
                {
                    jm.otherData = ids;
                    where        = where.And(p => ids.Contains((int)p.organizationId));
                }
            }

            //状态,0正常,1冻结 int
            var state = Request.Form["state"].FirstOrDefault().ObjectToInt(0);

            if (state > 0)
            {
                @where = @where.And(p => p.state == state);
            }
            //是否删除,0否,1是 bit
            var deleted = Request.Form["deleted"].FirstOrDefault();

            if (!string.IsNullOrEmpty(deleted) && deleted.ToLowerInvariant() == "true")
            {
                @where = @where.And(p => p.deleted);
            }
            else if (!string.IsNullOrEmpty(deleted) && deleted.ToLowerInvariant() == "false")
            {
                @where = @where.And(p => p.deleted == false);
            }
            //注册时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();

            if (!string.IsNullOrEmpty(createTime))
            {
                if (createTime.Contains("到"))
                {
                    var dts     = createTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.createTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.createTime < dtEnd);
                }
                else
                {
                    var dt = createTime.ObjectToDate();
                    where = where.And(p => p.createTime > dt);
                }
            }

            //修改时间 datetime
            var updateTime = Request.Form["updateTime"].FirstOrDefault();

            if (!string.IsNullOrEmpty(updateTime))
            {
                if (updateTime.Contains("到"))
                {
                    var dts     = updateTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.updateTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.updateTime < dtEnd);
                }
                else
                {
                    var dt = updateTime.ObjectToDate();
                    where = where.And(p => p.updateTime > dt);
                }
            }

            //获取数据
            var list = await _sysUserServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize);

            //返回数据
            jm.data  = list;
            jm.code  = 0;
            jm.count = list.TotalCount;
            jm.msg   = "数据调用成功!";

            if (list.Any())
            {
                var sysRoles = await _sysRoleServices.QueryAsync();

                var sysUserRoles = await _sysUserRoleServices.QueryAsync();

                foreach (var user in list)
                {
                    var roleIds = sysUserRoles.Where(p => p.userId == user.id).Select(p => p.roleId).ToList();
                    if (roleIds.Any())
                    {
                        user.roles = sysRoles.Where(p => roleIds.Contains(p.id)).ToList();
                    }
                }
            }


            return(new JsonResult(jm));
        }