feat: 新增显示签到记录

This commit is contained in:
陈淳
2024-01-15 15:28:32 +08:00
parent 40195ea993
commit a06c8c00b3
7 changed files with 142 additions and 17 deletions

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Integral
{
public class SignInDto
{
/// <summary>
/// 签到数据
/// </summary>
public List<SignInItemDto> SignInItem { get; set; }=new List<SignInItemDto>();
/// <summary>
/// 当前连续签到次数
/// </summary>
public int CurrentContinuousNumber { get; set; }
}
public class SignInItemDto : EntityDto<Guid>
{
/// <summary>
/// 签到时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}

View File

@@ -4,8 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.Users;
using Yi.Framework.Bbs.Application.Contracts.Dtos.Integral;
using Yi.Framework.Bbs.Domain.Managers;
namespace Yi.Framework.Bbs.Application.Services.Integral
@@ -31,5 +33,43 @@ namespace Yi.Framework.Bbs.Application.Services.Integral
var value = await _integralManager.SignInAsync(_currentUser.Id ?? Guid.Empty);
return new { value };
}
/// <summary>
/// 获取本月签到记录
/// </summary>
/// <returns></returns>
[Authorize]
[HttpGet("integral/sign-in/record")]
public async Task<SignInDto> GetSignInRecordAsync()
{
var output = new SignInDto();
DateTime lastMonth = DateTime.Now.AddMonths(-1);
DateTime lastDayOfMonth = new DateTime(lastMonth.Year, lastMonth.Month, 1).AddMonths(1).AddDays(-1);
DateTime startOfLastDay = new DateTime(lastDayOfMonth.Year, lastDayOfMonth.Month, lastDayOfMonth.Day, 0, 0, 0);
//获取当前用户本月的数据+上个月最后一天的数据
var entities = await _integralManager._signInRepository.GetListAsync(x => x.CreatorId == CurrentUser.Id
&& x.CreationTime >= startOfLastDay);
if (entities is null)
{
//返回默认值
return output;
}
//拿到最末尾的数据
var lastEntity = entities.OrderBy(x => x.CreationTime).LastOrDefault();
//判断当前时间和最后时间是否为连续的
if (lastEntity.CreationTime.Day >= DateTime.Now.AddDays(-1).Day)
{
output.CurrentContinuousNumber = lastEntity.ContinuousNumber;
}
//去除上个月查询的数据
output.SignInItem = entities.Where(x=>x.CreationTime.Month==DateTime.Now.Month) .Select(x => new SignInItemDto { Id = x.Id, CreationTime = x.CreationTime }).OrderBy(x=>x.CreationTime).ToList();
return output;
}
}
}

View File

@@ -10,8 +10,8 @@ namespace Yi.Framework.Bbs.Domain.Managers
{
public class IntegralManager : DomainService
{
private ISqlSugarRepository<LevelEntity> _levelRepository;
private ISqlSugarRepository<SignInEntity> _signInRepository;
public ISqlSugarRepository<LevelEntity> _levelRepository;
public ISqlSugarRepository<SignInEntity> _signInRepository;
private readonly ILocalEventBus _localEventBus;
public IntegralManager(ISqlSugarRepository<LevelEntity> levelRepository, ISqlSugarRepository<SignInEntity> signInRepository, ILocalEventBus localEventBus)
{