Example #1
0
        public async Task <IEnumerable <AssetGroupDto> > GetGroupsAsync(string type)
        {
            List <AssetEntity> entities = await _assetRepo
                                          .Select
                                          .Where(c => c.IsDeleted == false)
                                          .WhereIf(type.IsNotNullOrEmpty(), c => c.Type.Equals(type))
                                          .ToListAsync();

            List <AssetEntity>   parents = entities.FindAll(c => c.ParentId == 0);
            List <AssetGroupDto> dtos    = parents
                                           .Select(c =>
            {
                var dto    = new AssetGroupDto();
                dto.Name   = c.Name;
                dto.Childs = entities
                             .FindAll(d => d.ParentId == c.Id)
                             .Select(d =>
                {
                    var s     = Mapper.Map <AssetDto>(d);
                    s.IconUrl = _fileRepo.GetFileUrl(s.IconUrl);
                    return(s);
                })
                             .ToList();
                return(dto);
            })
                                           .ToList();

            return(dtos);
        }
Example #2
0
        public async Task <StatementExpendCategoryDto> GetExpendCategoryStatisticsAsync(StatementDateInputDto input)
        {
            var dto        = new StatementExpendCategoryDto();
            var statements = await _statementRepo
                             .Select
                             .Where(s => s.IsDeleted == false)
                             .Where(s => s.Type.Equals("expend"))
                             .WhereIf(input.UserId != null, s => s.CreateUserId == input.UserId)
                             .WhereIf(input.Year != null, s => s.Year == input.Year)
                             .WhereIf(input.Month != null, s => s.Month == input.Month)
                             .WhereIf(input.Day != null, s => s.Day == input.Day)
                             .ToListAsync();

            decimal total = 0;
            // 根据CategoryId分组,并统计总额
            var childDetails = statements.GroupBy(s => s.CategoryId).Select(g =>
            {
                var info       = _categoryRepo.GetAsync(g.Key.Value).Result;
                var parentInfo = _categoryRepo.GetCategoryParentAsync(g.Key.Value).Result;
                var amount     = g.Sum(s => s.Amount);
                total         += amount;
                return(new
                {
                    CategoryId = g.Key,
                    Amount = amount,
                    Info = info,
                    ParentInfo = parentInfo
                });
            });

            var childDtos  = new List <ChildGroupDto>();
            var parentDtos = childDetails.GroupBy(p => new { p.ParentInfo.Id, p.ParentInfo.Name }).Select(g =>
            {
                var childDto        = new ChildGroupDto();
                var childTotal      = g.Sum(s => s.Amount);
                childDto.ParentName = g.Key.Name;
                childDto.Childs     = childDetails.Where(d => d.Info.ParentId == g.Key.Id).Select(d => new
                {
                    Id               = d.Info.Id,
                    Name             = d.Info.Name,
                    Data             = d.Amount,
                    Percent          = Math.Round(d.Amount / childTotal, 4) * 100,
                    CategoryIconPath = _fileRepo.GetFileUrl(d.Info.IconUrl)
                });
                childDtos.Add(childDto);
                return(new StatisticsDto
                {
                    Id = g.Key.Id,
                    Name = g.Key.Name,
                    Data = Math.Round(g.Sum(s => s.Amount) / total, 4) * 100
                });
            }).ToList();

            dto.ParentCategoryStas = parentDtos;
            dto.ChildCategoryStas  = childDtos;
            return(dto);
        }
Example #3
0
        public async Task <UserDto> GetAsync(long?id)
        {
            var userId = id ?? CurrentUser.Id;
            var user   = await _userRepo
                         .Select
                         .IncludeMany(u => u.Roles)
                         .Where(r => r.Id == userId).FirstAsync();

            user.AvatarUrl = _fileRepo.GetFileUrl(user.AvatarUrl);
            return(Mapper.Map <UserDto>(user));
        }