Files
Yi.Admin/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Integral/IntegralService.cs

83 lines
3.0 KiB
C#
Raw Normal View History

2024-01-11 18:51:53 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-01-11 22:06:15 +08:00
using Microsoft.AspNetCore.Authorization;
2024-01-15 15:28:32 +08:00
using Microsoft.AspNetCore.Mvc;
2024-01-11 18:51:53 +08:00
using Volo.Abp.Application.Services;
2024-02-26 18:44:11 +08:00
using Volo.Abp.EventBus.Local;
2024-01-11 22:06:15 +08:00
using Volo.Abp.Users;
2024-01-15 15:28:32 +08:00
using Yi.Framework.Bbs.Application.Contracts.Dtos.Integral;
2024-01-11 18:51:53 +08:00
using Yi.Framework.Bbs.Domain.Managers;
2024-02-26 18:44:11 +08:00
using Yi.Framework.Bbs.Domain.Shared.Etos;
using Yi.Framework.Rbac.Domain.Authorization;
2024-01-11 18:51:53 +08:00
namespace Yi.Framework.Bbs.Application.Services.Integral
{
2024-01-11 22:06:15 +08:00
public class IntegralService : ApplicationService
2024-01-11 18:51:53 +08:00
{
private IntegralManager _integralManager;
2024-01-11 22:06:15 +08:00
private ICurrentUser _currentUser;
2024-02-26 18:44:11 +08:00
private ILocalEventBus _localEventBus;
public IntegralService(IntegralManager integralManager, ICurrentUser currentUser, ILocalEventBus localEventBus)
2024-01-11 18:51:53 +08:00
{
2024-01-11 22:06:15 +08:00
_integralManager = integralManager;
_currentUser = currentUser;
2024-02-26 18:44:11 +08:00
_localEventBus = localEventBus;
2024-01-11 18:51:53 +08:00
}
2024-01-11 22:06:15 +08:00
/// <summary>
/// 签到
/// </summary>
/// <returns></returns>
[Authorize]
public async Task<object> PostSignInAsync()
{
var value = await _integralManager.SignInAsync(_currentUser.Id ?? Guid.Empty);
return new { value };
}
2024-01-15 15:28:32 +08:00
/// <summary>
/// 获取本月签到记录
2024-03-07 11:44:27 +08:00
/// Todo: 可放入领域层
2024-01-15 15:28:32 +08:00
/// </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);
2024-01-15 15:28:32 +08:00
//获取当前用户本月的数据+上个月最后一天的数据
var entities = await _integralManager._signInRepository.GetListAsync(x => x.CreatorId == CurrentUser.Id
&& x.CreationTime >= startOfLastDay);
2024-01-15 15:28:32 +08:00
if (entities.Count() == 0)
{
//返回默认值
return output;
}
//拿到最末尾的数据
var lastEntity = entities.OrderBy(x => x.CreationTime).LastOrDefault();
2024-01-15 15:28:32 +08:00
//判断当前时间和最后时间是否为连续的
if (lastEntity.CreationTime.Day >= DateTime.Now.AddDays(-1).Day)
{
2024-01-15 15:28:32 +08:00
output.CurrentContinuousNumber = lastEntity.ContinuousNumber;
}
2024-01-15 15:28:32 +08:00
//去除上个月查询的数据
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;
2024-01-15 15:28:32 +08:00
}
2024-01-11 18:51:53 +08:00
}
}