/// <summary>
 /// 获取用户列表
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public BsTableDataSource <UserInfoViewModel> GET(GetUserInfoList request)
 {
     return(SysManager.GetUserInfoList(request));
 }
        /// <summary>
        /// 获取用户列表  返回总数量total和列表row
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BsTableDataSource <UserInfoViewModel> GetUserInfoList(GetUserInfoList request)
        {
            using (var db = DbFactory.Open())
            {
                var builder = db.From <UserInfo>();
                builder.LeftJoin <UserInfo, UserRoleInfo>((x, y) => x.Id == y.UserID);
                //builder.LeftJoin<UserRoleInfo, Role>((y, z) =>y.RoleID==z.Id);
                if (!string.IsNullOrEmpty(request.userName))
                {
                    builder.Where(x => x.UserName.Contains(request.userName));
                }
                if (!string.IsNullOrEmpty(request.name))
                {
                    builder.Where(x => x.RealName.Contains(request.name));
                }

                if (!string.IsNullOrEmpty(request.adcd) && request.adcd.IndexOf("00000000000") > 0)//地级市
                {
                    builder.Where(x => x.adcd.StartsWith(request.adcd.Substring(0, 4)));
                }
                else if (!string.IsNullOrEmpty(request.adcd) && request.adcd.IndexOf("000000000") > 0)//县级市区
                {
                    builder.Where(x => x.adcd.StartsWith(request.adcd.Substring(0, 6)));
                }

                if (!string.IsNullOrEmpty(request.Sort))
                {
                    if (request.Order == "desc")
                    {
                        builder.OrderByFieldsDescending(request.Sort);
                    }
                    else
                    {
                        builder.OrderByFields(request.Sort);
                    }
                }
                else
                {
                    builder.OrderBy(x => x.adcd);
                }
                var count     = db.Count(builder);
                var PageSize  = request.PageSize == 0 ? 15 : request.PageSize;
                var PageIndex = request.PageIndex == 0 ? 0 : (request.PageIndex) * PageSize;
                builder.Limit(PageIndex, PageSize);
                builder.Select <UserInfo, UserRoleInfo>((x, y) => new
                {
                    Id           = x.Id,
                    UserName     = x.UserName,
                    RealName     = x.RealName,
                    adcd         = x.adcd,
                    Mobile       = x.Mobile,
                    isEnable     = x.isEnable,
                    RoleID       = y.RoleID,
                    UserRealName = x.UserRealName,
                    Unit         = x.Unit,
                    Position     = x.Position
                });
                var list     = db.Select <UserInfoViewModel>(builder);
                var roleList = db.Select <Role>();
                list.ForEach(x =>
                {
                    x.City = db.Single <ADCDInfo>(y => y.adcd == x.adcd.Substring(0, 6) + "000000000").adnm;
                    x.Role = roleList.Where(w => w.Id == x.RoleID).FirstOrDefault().RoleName;
                });
                return(new BsTableDataSource <UserInfoViewModel>()
                {
                    total = count, rows = list
                });
            }
        }