示例#1
0
        /// <summary>
        ///     获取s the 视图 bill 分页 list.
        /// </summary>
        /// <param name="userInput">The 会员 input.</param>
        public PagedList <ViewAdminBill> GetViewBillPageList(BillInput userInput)
        {
            if (!userInput.Serial.IsNullOrEmpty() && userInput.Serial.Length > 8)
            {
                userInput.Id = long.Parse(userInput.Serial.Substring(1, userInput.Serial.Length - 1).TrimStart('0'));
            }

            var billList = _billRepository.GetBillList(userInput, out var count);

            var userIds      = billList.Select(r => r.UserId).Distinct().ToList();
            var otherUserIds = billList.Select(r => r.OtherUserId).Distinct().ToList();

            userIds.AddRange(otherUserIds);
            var users      = _userRepository.GetList(userIds);
            var moneyTypes = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>();
            IList <ViewAdminBill> result = new List <ViewAdminBill>();

            foreach (var item in billList)
            {
                var viewUser = new ViewAdminBill
                {
                    Bill = item,
                    Id   = item.Id
                };
                var user = users.FirstOrDefault(r => r.Id == item.UserId);
                if (user != null)
                {
                    viewUser.User     = user;
                    viewUser.UserId   = viewUser.User.Id;
                    viewUser.UserName = Resolve <IUserService>().GetUserStyle(user);
                }
                else
                {
                    viewUser.User = new User();
                }

                var otherUser = users.FirstOrDefault(r => r.Id == item.OtherUserId);
                if (otherUser != null)
                {
                    viewUser.OtherUser     = otherUser;
                    viewUser.OtherUserName = Resolve <IUserService>().GetUserStyle(otherUser);
                    viewUser.OtherUserId   = viewUser.OtherUser.Id;
                }

                viewUser.Serial        = item.Serial;
                viewUser.MoneyTypeName = moneyTypes.FirstOrDefault(e => e.Id == item.MoneyTypeId)?.Name;
                viewUser.FlowAmoumtStr = item.Flow.GetHtmlName();
                viewUser.Amount        = item.Amount;
                viewUser.AfterAmount   = item.AfterAmount;
                viewUser.BillTypeName  = item.Type.GetHtmlName();
                viewUser.CreatimeStr   = item.CreateTime.ToString();
                viewUser.Intro         = item.Intro;
                result.Add(viewUser);
            }

            return(PagedList <ViewAdminBill> .Create(result, count, userInput.PageSize, userInput.PageIndex));
        }
示例#2
0
        public IList <Bill> GetBillList(BillInput userInput, out long count)
        {
            if (userInput.PageIndex < 0)
            {
                throw new ArgumentNullException("pageIndex", "pageindex has to be greater than 1");
            }

            // TODO: ??? why set this at first??
            //if (userInput.PageSize > 100) {
            //    userInput.PageSize = 100;
            //}

            var sqlWhere = string.Empty;

            if (userInput.Flow.HasValue)
            {
                sqlWhere = $"{sqlWhere} AND Flow={(int)userInput.Flow}";
            }

            if (userInput.OtherUserId > 0)
            {
                sqlWhere = $"{sqlWhere} AND ParentId={userInput.OtherUserId}";
            }

            if (userInput.Id > 0)
            {
                sqlWhere = $"{sqlWhere} AND Id= '{userInput.Id}' ";
            }

            if (!userInput.MoneyTypeId.IsGuidNullOrEmpty())
            {
                sqlWhere = $"{sqlWhere} AND MoneyTypeId= '{userInput.MoneyTypeId}' ";
            }

            if (userInput.UserId > 0)
            {
                sqlWhere = $"{sqlWhere} AND UserId='{userInput.UserId}' ";
            }

            var sqlCount = $"SELECT COUNT(Id) [Count] FROM [Asset_Bill] where 1=1 {sqlWhere}";

            count = RepositoryContext.ExecuteScalar(sqlCount)?.ConvertToLong() ?? 0;

            var result = new List <Bill>();
            var sql    = $@"SELECT TOP {userInput.PageSize} * FROM (
                        SELECT  ROW_NUMBER() OVER (ORDER BY id desc) AS RowNumber,[Id] ,[UserId] ,[OtherUserId] ,[Type],[Flow],[MoneyTypeId],[Amount] ,[AfterAmount] ,[Intro] ,[CreateTime] FROM [Asset_Bill] where 1=1 {
                    sqlWhere
                }
                               ) as A
                        WHERE RowNumber > {userInput.PageSize}*({userInput.PageIndex}-1)  ";

            using (var dr = RepositoryContext.ExecuteDataReader(sql))
            {
                while (dr.Read())
                {
                    result.Add(ReadBill(dr));
                }
            }

            return(result);
        }