feat: 修该用户明细展示内容添加统计隐藏明细

develop
zhangyousheng 2023-08-27 23:08:45 +08:00
parent 32ea7191ee
commit 20158c37d6
5 changed files with 38 additions and 23 deletions

View File

@ -8,7 +8,7 @@ namespace UserPointManagement.Application.Services;
public interface IUserPointService
{
Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req);
Task<PageResultDto<UserPointInfoDto>> GetUserPoints(GetUserPointDto req);
Task CreateUserPoint(CreateUserPointDto input);
@ -24,26 +24,39 @@ public class UserPointService : IUserPointService
_dbContextFactory = dbContextFactory;
}
public async Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req)
public async Task<PageResultDto<UserPointInfoDto>> GetUserPoints(GetUserPointDto req)
{
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
var queryable = from userPoint in _userPointManagementDbContext.UserPoints
join user in _userPointManagementDbContext.Users on userPoint.UserId equals user.Id
var queryable = _userPointManagementDbContext.Users
.Where(x => x.Id == req.UserId, req.UserId.HasValue);
// 分页筛选只能针对用户
var users = await queryable.OrderByDescending(x => x.Id).Paging(req).ToListAsync();
// 查出用户底下积分明细
var userPoints = await (from userPoint in _userPointManagementDbContext.UserPoints
where users.Select(x => x.Id).Contains(userPoint.UserId)
select new UserPointDto()
{
UserPointId = userPoint.Id,
UserId = user.Id,
Name = user.Name,
UserId = userPoint.UserId,
Point = userPoint.Point,
CreateTime = userPoint.CreateTime
};
}).ToListAsync();
queryable = queryable.Where(x => x.UserId == req.UserId, req.UserId.HasValue);
var data = userPoints.GroupBy(x => x.UserId)
.Select(x => new UserPointInfoDto()
{
UserId = x.Key,
Name = users.First(p => p.Id == x.Key).Name,
TotalPoint = x.Sum(p => p.Point),
Items = x.ToList()
}).ToList();
var count = queryable.Count();
var data = await queryable.OrderByDescending(x => x.CreateTime).Paging(req).ToListAsync().ConfigureAwait(false);
return new PageResultDto<UserPointDto>()
return new PageResultDto<UserPointInfoDto>()
{
Items = data,
TotalCount = count

View File

@ -6,8 +6,6 @@ public class UserPointDto
public int UserId { get; set; }
public string Name { get; set; }
public int Point { get; set; }
public DateTime CreateTime { get; set; }

View File

@ -0,0 +1,12 @@
namespace UserPointManagement.Model.Dtos.UserPoint;
public class UserPointInfoDto
{
public int UserId { get; set; }
public string Name { get; set; }
public int TotalPoint { get; set; }
public List<UserPointDto> Items { get; set; }
}

View File

@ -36,7 +36,7 @@
</Space>
</GridCol>
</GridRow>
<Table TItem="UserPointDto" DataSource="@_userPoints"
<Table TItem="UserPointInfoDto" DataSource="@_userPoints"
Total="_total"
Loading="_loading"
PageIndex="@_pageIndex"
@ -44,15 +44,7 @@
OnPageIndexChange="OnPageIndexChanged"
OnPageSizeChange="OnPageSizeChange">
<PropertyColumn Property="c => c.Name" title="用户姓名"/>
<PropertyColumn Property="c => c.Point" title="积分"/>
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd HH:mm"/>
<ActionColumn Title="操作" Width="220">
<Space Size=@("middle")>
<SpaceItem>
<Button Danger OnClick="()=>Delete(context.UserPointId)">删除</Button>
</SpaceItem>
</Space>
</ActionColumn>
<PropertyColumn Property="c => c.TotalPoint" title="总积分"/>
</Table>
</PageContainer>

View File

@ -15,7 +15,7 @@ public class UserPointDetailBase : ComponentBase
[Inject] private IUserService UserService { get; set; }
[Inject] private MessageService MessageService { get; set; }
protected List<UserPointDto> _userPoints;
protected List<UserPointInfoDto> _userPoints;
protected List<UserDto> _users;
protected int _pageIndex = 1;
protected int _pageSize = 20;