feat: 搭建任务框架
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
public enum AssignmentStateEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 正在进行
|
||||
/// </summary>
|
||||
Progress,
|
||||
|
||||
/// <summary>
|
||||
/// 已完成
|
||||
/// </summary>
|
||||
Completed,
|
||||
|
||||
/// <summary>
|
||||
/// 已过期
|
||||
/// </summary>
|
||||
Expired
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
public enum AssignmentTypeEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 新手任务
|
||||
/// </summary>
|
||||
Novice,
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务
|
||||
/// </summary>
|
||||
Daily,
|
||||
|
||||
/// <summary>
|
||||
/// 每周任务
|
||||
/// </summary>
|
||||
Weekly
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Core.Data;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
/// <summary>
|
||||
/// 任务实例表
|
||||
/// </summary>
|
||||
[SugarTable("Assignment")]
|
||||
public class AssignmentAggregateRoot : AggregateRoot<Guid>, IHasCreationTime, IOrderNum, IHasModificationTime
|
||||
{
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务定义ID
|
||||
/// </summary>
|
||||
public Guid AssignmentDefineId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务接收者用户id
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总共步骤数
|
||||
/// </summary>
|
||||
public int TotalStepNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前步骤数
|
||||
/// </summary>
|
||||
public int CurrentStepNumber { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 任务状态
|
||||
/// </summary>
|
||||
public AssignmentStateEnum AssignmentState { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 任务过期时间
|
||||
/// </summary>
|
||||
public DateTime? ExpireTime { get; set; }
|
||||
|
||||
public DateTime CreationTime { get; }
|
||||
public int OrderNum { get; set; }
|
||||
public DateTime? LastModificationTime { get; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Core.Data;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
/// <summary>
|
||||
/// 任务定义表
|
||||
/// </summary>
|
||||
[SugarTable("AssignmentDefine")]
|
||||
|
||||
public class AssignmentDefineAggregateRoot: AggregateRoot<Guid>, IHasCreationTime,IOrderNum
|
||||
{
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remarks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务类型
|
||||
/// </summary>
|
||||
public AssignmentTypeEnum AssignmentType{ get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 前置任务id
|
||||
/// </summary>
|
||||
public Guid? PreAssignmentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务奖励的钱钱数量
|
||||
/// </summary>
|
||||
public decimal RewardsMoneyNumber { get; set; }
|
||||
|
||||
public DateTime CreationTime { get; }
|
||||
public int OrderNum { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers;
|
||||
|
||||
/// <summary>
|
||||
/// 任务领域,任务相关核心逻辑
|
||||
/// </summary>
|
||||
public class AssignmentManager : DomainService
|
||||
{
|
||||
/// <summary>
|
||||
/// 接受任务
|
||||
/// </summary>
|
||||
/// <param name="userId">领取用户</param>
|
||||
/// <param name="asignmentDefineId">任务定义id</param>
|
||||
/// <returns></returns>
|
||||
public Task AcceptAsync(Guid userId, Guid asignmentDefineId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 领取任务奖励
|
||||
/// </summary>
|
||||
/// <param name="asignmentId">任务id</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task ReceiveRewardsAsync(Guid asignmentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户id获取能够领取的任务列表
|
||||
/// </summary>
|
||||
/// <param name="userId">用户id</param>
|
||||
/// <returns></returns>
|
||||
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
public class AssignmentContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 全部的任务定义
|
||||
/// </summary>
|
||||
public List<AssignmentDefineAggregateRoot> AllAssignmentDefine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户的全部任务数据
|
||||
/// </summary>
|
||||
public List<AssignmentAggregateRoot> CurrentUserAssignments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户id
|
||||
/// </summary>
|
||||
public Guid CurrentUserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 任务提供者接口
|
||||
/// </summary>
|
||||
public interface IAssignmentProvider : ITransientDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取可领取的任务定义,该方法需全部AssignmentProvider去重
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 校验是否能够被领取,该方法还需工厂进行代理执行一次
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
Task VerifyCanAcceptAsync(AssignmentContext context);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 每日任务提供者
|
||||
/// </summary>
|
||||
public class DailyProvider : TimerProvider
|
||||
{
|
||||
protected override TimeSpan TimeCycle => TimeSpan.FromDays(1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 新手任务提供者
|
||||
/// </summary>
|
||||
public class NoviceProvider : IAssignmentProvider
|
||||
{
|
||||
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task VerifyCanAcceptAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 每周任务提供者
|
||||
/// </summary>
|
||||
public class WeeklyProvider : TimerProvider
|
||||
{
|
||||
protected override TimeSpan TimeCycle => TimeSpan.FromDays(7);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Yi.Framework.Bbs.Domain.Entities.Assignment;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务提供者
|
||||
/// </summary>
|
||||
public abstract class TimerProvider : IAssignmentProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间周期
|
||||
/// </summary>
|
||||
protected abstract TimeSpan TimeCycle { get; }
|
||||
|
||||
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task VerifyCanAcceptAsync(AssignmentContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user