Esempio n. 1
0
        /// <summary>
        /// 映射Dto
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="statement"></param>
        /// <returns></returns>
        private T MapToDto <T>(StatementEntity statement) where T : MapDto
        {
            T dto = Mapper.Map <T>(statement);

            if (statement.CategoryId != null)
            {
                var category = _categoryRepo.Get(statement.CategoryId.Value) ?? throw new KnownException("账单分类数据查询失败!", ServiceResultCode.NotFound);
                dto.CategoryName     = category.Name;
                dto.CategoryIconPath = _fileRepo.GetFileUrl(category.IconUrl);
            }
            else
            {
                if (statement.Type.Equals(StatementTypeEnum.transfer.ToString()))
                {
                    dto.CategoryIconPath = _fileRepo.GetFileUrl("core/images/category/icon_transfer_64.png");
                }
                else if (statement.Type.Equals(StatementTypeEnum.repayment.ToString()))
                {
                    dto.CategoryIconPath = _fileRepo.GetFileUrl("core/images/category/icon_repayment_64.png");
                }
            }
            var asset = _assetRepo.Get(statement.AssetId) ?? throw new KnownException("资产分类数据查询失败!", ServiceResultCode.NotFound);

            if (statement.TargetAssetId != null)
            {
                var targetAsset = _assetRepo.Get(statement.TargetAssetId.Value);
                dto.TargetAssetName = targetAsset.Name;
            }
            dto.AssetName = asset.Name;
            dto.TypeName  = Switcher.StatementType(statement.Type);

            return(dto);
        }
Esempio n. 2
0
        public async Task <PagedDto <AssetPageDto> > GetPageAsync(AssetPagingDto pagingDto)
        {
            if (pagingDto.CreateStartTime != null && pagingDto.CreateEndTime == null)
            {
                throw new KnownException("创建时间参数有误", ServiceResultCode.ParameterError);
            }
            pagingDto.Sort = pagingDto.Sort.IsNullOrEmpty() ? "id ASC" : pagingDto.Sort.Replace("-", " ");
            var parentIds = new List <string>();

            if (!string.IsNullOrWhiteSpace(pagingDto.ParentIds))
            {
                parentIds = pagingDto.ParentIds.Split(",").ToList();
            }
            var assets = await _assetRepo
                         .Select
                         .WhereIf(!string.IsNullOrWhiteSpace(pagingDto.AssetName), a => a.Name.Contains(pagingDto.AssetName))
                         .WhereIf(parentIds != null && parentIds.Any(), a => parentIds.Contains(a.ParentId.ToString()))
                         .WhereIf(!string.IsNullOrWhiteSpace(pagingDto.Type), c => c.Type.Equals(pagingDto.Type))
                         .WhereIf(pagingDto.CreateStartTime != null, a => a.CreateTime >= pagingDto.CreateStartTime && a.CreateTime <= pagingDto.CreateEndTime)
                         .OrderBy(pagingDto.Sort)
                         .ToPageListAsync(pagingDto, out long totalCount);

            var assetDtos = assets.Select(a =>
            {
                var dto = Mapper.Map <AssetPageDto>(a);
                AssetEntity category = null;
                if (a.ParentId != 0)
                {
                    category = _assetRepo.Get(a.ParentId);
                }
                dto.ParentName = category?.Name;
                dto.TypeName   = SystemConst.Switcher.AssetType(a.Type);
                dto.IconUrl    = _fileRepo.GetFileUrl(a.IconUrl);
                return(dto);
            }).ToList();

            return(new PagedDto <AssetPageDto>(assetDtos, totalCount));
        }