feat: add points rule domain entities
This commit is contained in:
parent
90c6912fd5
commit
176120d51f
@ -0,0 +1,65 @@
|
|||||||
|
using Fengling.Member.Domain.Aggregates.PointsRuleModel.Enums;
|
||||||
|
|
||||||
|
namespace Fengling.Member.Domain.Aggregates.PointsRuleModel;
|
||||||
|
|
||||||
|
public class PointsRule : Entity<PointsRuleId>, IAggregateRoot
|
||||||
|
{
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
public string Code { get; private set; } = string.Empty;
|
||||||
|
public RuleType RuleType { get; private set; }
|
||||||
|
public int BasePoints { get; private set; }
|
||||||
|
public decimal? WeightFactor { get; private set; }
|
||||||
|
public int ValidityDays { get; private set; }
|
||||||
|
public int Priority { get; private set; }
|
||||||
|
public CalculationMode CalculationMode { get; private set; }
|
||||||
|
public bool IsActive { get; private set; }
|
||||||
|
public DateTime EffectiveFrom { get; private set; }
|
||||||
|
public DateTime? EffectiveTo { get; private set; }
|
||||||
|
public DateTime CreatedAt { get; private set; }
|
||||||
|
public DateTime UpdatedAt { get; private set; }
|
||||||
|
|
||||||
|
private readonly List<PointsRuleCondition> _conditions = new();
|
||||||
|
public IReadOnlyCollection<PointsRuleCondition> Conditions => _conditions.AsReadOnly();
|
||||||
|
|
||||||
|
private PointsRule() { }
|
||||||
|
|
||||||
|
public static PointsRule Create(
|
||||||
|
string name,
|
||||||
|
string code,
|
||||||
|
RuleType ruleType,
|
||||||
|
int basePoints,
|
||||||
|
int validityDays,
|
||||||
|
int priority = 0,
|
||||||
|
CalculationMode calculationMode = CalculationMode.Synchronous,
|
||||||
|
decimal? weightFactor = null)
|
||||||
|
{
|
||||||
|
return new PointsRule
|
||||||
|
{
|
||||||
|
Id = PointsRuleId.New(),
|
||||||
|
Name = name,
|
||||||
|
Code = code,
|
||||||
|
RuleType = ruleType,
|
||||||
|
BasePoints = basePoints,
|
||||||
|
ValidityDays = validityDays,
|
||||||
|
Priority = priority,
|
||||||
|
CalculationMode = calculationMode,
|
||||||
|
WeightFactor = weightFactor,
|
||||||
|
IsActive = true,
|
||||||
|
EffectiveFrom = DateTime.UtcNow,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
UpdatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddCondition(PointsRuleCondition condition)
|
||||||
|
{
|
||||||
|
_conditions.Add(condition);
|
||||||
|
UpdatedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deactivate()
|
||||||
|
{
|
||||||
|
IsActive = false;
|
||||||
|
UpdatedAt = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
using Fengling.Member.Domain.Aggregates.PointsRuleModel.Enums;
|
||||||
|
|
||||||
|
namespace Fengling.Member.Domain.Aggregates.PointsRuleModel;
|
||||||
|
|
||||||
|
public class PointsRuleCondition : Entity<PointsRuleConditionId>
|
||||||
|
{
|
||||||
|
public PointsRuleId RuleId { get; private set; } = default!;
|
||||||
|
public DimensionType DimensionType { get; private set; }
|
||||||
|
public string DimensionValue { get; private set; } = string.Empty;
|
||||||
|
public string? Operator { get; private set; }
|
||||||
|
public DateTime CreatedAt { get; private set; }
|
||||||
|
|
||||||
|
private PointsRuleCondition() { }
|
||||||
|
|
||||||
|
public static PointsRuleCondition Create(
|
||||||
|
PointsRuleId ruleId,
|
||||||
|
DimensionType dimensionType,
|
||||||
|
string dimensionValue,
|
||||||
|
string? op = null)
|
||||||
|
{
|
||||||
|
return new PointsRuleCondition
|
||||||
|
{
|
||||||
|
Id = PointsRuleConditionId.New(),
|
||||||
|
RuleId = ruleId,
|
||||||
|
DimensionType = dimensionType,
|
||||||
|
DimensionValue = dimensionValue,
|
||||||
|
Operator = op,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Fengling.Member.Domain.Aggregates.PointsRuleModel;
|
||||||
|
|
||||||
|
public partial record PointsRuleConditionId : IGuidStronglyTypedId
|
||||||
|
{
|
||||||
|
public static PointsRuleConditionId New() => new(Guid.NewGuid());
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Fengling.Member.Domain.Aggregates.PointsRuleModel;
|
||||||
|
|
||||||
|
public partial record PointsRuleId : IGuidStronglyTypedId
|
||||||
|
{
|
||||||
|
public static PointsRuleId New() => new(Guid.NewGuid());
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user