using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using SqlSugar; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Users; using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles; using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market; using Yi.Framework.DigitalCollectibles.Domain.Entities; using Yi.Framework.DigitalCollectibles.Domain.Managers; using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.DigitalCollectibles.Application.Services; /// /// 藏品应用服务 /// public class CollectiblesService : ApplicationService { private readonly ISqlSugarRepository _collectiblesUserStoreRepository; private readonly CollectiblesManager _collectiblesManager; public CollectiblesService(ISqlSugarRepository collectiblesUserStoreRepository, CollectiblesManager collectiblesManager) { _collectiblesUserStoreRepository = collectiblesUserStoreRepository; _collectiblesManager = collectiblesManager; } public bool GetEnable() { return LazyServiceProvider.LazyGetRequiredService().GetValue("IsEnableCollectibles"); } public bool GetEnable2() { return LazyServiceProvider.LazyGetRequiredService().GetValue("IsEnableCollectibles2"); } /// /// 获取该用户的信息 /// [HttpGet("collectibles/account")] [Authorize] public async Task GetAccountInfoAsync() { var userId = CurrentUser.GetId(); var value = await _collectiblesManager.GetAccountValueAsync(userId); return new CollectiblesAccountInfoDto { TotalValue = value }; } /// /// 获取当前用户的藏品 /// /// /// /// [HttpGet("collectibles/user")] [Authorize] public async Task> GetForAccountUserAsync( CollectiblesUserGetInput input) { var userId = CurrentUser.GetId(); RefAsync total = 0; var output = await _collectiblesUserStoreRepository._DbQueryable .Where(x => x.UserId == userId) .WhereIF( input.StartTime is not null && input.EndTime is not null, u => u.CreationTime >= input.StartTime && u.CreationTime <= input.EndTime) .LeftJoin((u, c) => u.CollectiblesId == c.Id) .OrderBy((u, c) => c.CreationTime) .GroupBy((u, c) => u.CollectiblesId) .Select((u, c) => new CollectiblesUserGetOutputDto { Id = c.Id, Collectibles = new CollectiblesDto { Id = c.Id, Code = c.Code, Name = c.Name, Describe = c.Describe, ValueNumber = c.ValueNumber, Url = c.Url, Rarity = c.Rarity, FindTotal = c.FindTotal, OrderNum = c.OrderNum }, Number = SqlFunc.AggregateCount(u.CollectiblesId) }) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); return new PagedResultDto(total, output); } }