feat: 完成任务系统的领域服务
This commit is contained in:
@@ -4,6 +4,13 @@ namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
public class AssignmentContext
|
||||
{
|
||||
public AssignmentContext( Guid currentUserId,List<AssignmentDefineAggregateRoot> allAssignmentDefine, List<AssignmentAggregateRoot> currentUserAssignments)
|
||||
{
|
||||
AllAssignmentDefine = allAssignmentDefine;
|
||||
CurrentUserAssignments = currentUserAssignments;
|
||||
CurrentUserId = currentUserId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部的任务定义
|
||||
/// </summary>
|
||||
@@ -17,5 +24,5 @@ public class AssignmentContext
|
||||
/// <summary>
|
||||
/// 当前用户id
|
||||
/// </summary>
|
||||
public Guid CurrentUserId { get; set; }
|
||||
public Guid CurrentUserId { get; }
|
||||
}
|
||||
@@ -14,11 +14,4 @@ public interface IAssignmentProvider : ITransientDependency
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 校验是否能够被领取,该方法还需工厂进行代理执行一次
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
Task VerifyCanAcceptAsync(AssignmentContext context);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务提供者
|
||||
/// </summary>
|
||||
public class DailyProvider : TimerProvider
|
||||
{
|
||||
protected override TimeSpan TimeCycle => TimeSpan.FromDays(1);
|
||||
protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Daily;
|
||||
}
|
||||
@@ -9,11 +9,7 @@ public class NoviceProvider : IAssignmentProvider
|
||||
{
|
||||
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task VerifyCanAcceptAsync(AssignmentContext context)
|
||||
{
|
||||
//新手任务是要有前置依赖关系的,链表类型依赖
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 每周任务提供者
|
||||
/// </summary>
|
||||
public class WeeklyProvider : TimerProvider
|
||||
{
|
||||
protected override TimeSpan TimeCycle => TimeSpan.FromDays(7);
|
||||
protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Weekly;
|
||||
}
|
||||
@@ -1,24 +1,41 @@
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务提供者
|
||||
/// 循环任务提供者
|
||||
/// </summary>
|
||||
public abstract class TimerProvider : IAssignmentProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间周期
|
||||
/// 任务类型
|
||||
/// </summary>
|
||||
protected abstract TimeSpan TimeCycle { get; }
|
||||
protected abstract AssignmentTypeEnum AssignmentType { get; }
|
||||
|
||||
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
//先获取到对应任务定义列表
|
||||
var assignmentDefines = context.AllAssignmentDefine.Where(x => x.AssignmentType == AssignmentType).ToList();
|
||||
|
||||
public Task VerifyCanAcceptAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//满足以下1个条件
|
||||
//1:没有正在运行的
|
||||
//2: 存在已完成,但是完成时间是过期的
|
||||
var assignmentFilterIds = context.CurrentUserAssignments
|
||||
.Where(x =>
|
||||
//正在进行的,要去掉
|
||||
x.AssignmentState == AssignmentStateEnum.Progress||
|
||||
//已完成,但是还没过期,要去掉
|
||||
(x.AssignmentState == AssignmentStateEnum.Completed&&!AssignmentType.IsExpire(x.CompleteTime!.Value)))
|
||||
.Select(x => x.AssignmentDefineId)
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
//出去不可接收的任务,就是可接收任务
|
||||
var output = assignmentDefines.Where(x => !assignmentFilterIds.Contains(x.Id)).ToList();
|
||||
return Task.FromResult(output);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user