fix: resolve strongly typed ID compilation errors
- Change PointsAccountId to IGuidStronglyTypedId - Update PointsTransaction to use PointsAccountId - Update Domain Events and Command responses - Fix Member and Activity endpoint references - Remove duplicate PointsChangedEvent in Application layer
This commit is contained in:
parent
ab3d755f63
commit
73f84a1237
@ -16,7 +16,7 @@ public class AddPointsCommand : IRequest<AddPointsResponse>
|
|||||||
|
|
||||||
public class AddPointsResponse
|
public class AddPointsResponse
|
||||||
{
|
{
|
||||||
public long AccountId { get; set; }
|
public PointsAccountId AccountId { get; set; } = PointsAccountId.New();
|
||||||
public long MemberId { get; set; }
|
public long MemberId { get; set; }
|
||||||
public int AddedPoints { get; set; }
|
public int AddedPoints { get; set; }
|
||||||
public int TotalPoints { get; set; }
|
public int TotalPoints { get; set; }
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public class DeductPointsCommand : IRequest<DeductPointsResponse>
|
|||||||
|
|
||||||
public class DeductPointsResponse
|
public class DeductPointsResponse
|
||||||
{
|
{
|
||||||
public long AccountId { get; set; }
|
public PointsAccountId AccountId { get; set; } = PointsAccountId.New();
|
||||||
public long MemberId { get; set; }
|
public long MemberId { get; set; }
|
||||||
public int DeductedPoints { get; set; }
|
public int DeductedPoints { get; set; }
|
||||||
public int TotalPoints { get; set; }
|
public int TotalPoints { get; set; }
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
using MediatR;
|
|
||||||
|
|
||||||
namespace Fengling.Member.Application.Events;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 积分变动事件
|
|
||||||
/// </summary>
|
|
||||||
public class PointsChangedEvent : INotification
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 码ID(用于幂等性检查)
|
|
||||||
/// </summary>
|
|
||||||
public string CodeId { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 会员ID
|
|
||||||
/// </summary>
|
|
||||||
public long MemberId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 租户ID
|
|
||||||
/// </summary>
|
|
||||||
public long TenantId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 交易类型
|
|
||||||
/// </summary>
|
|
||||||
public string TransactionType { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 积分数(正数增加,负数扣减)
|
|
||||||
/// </summary>
|
|
||||||
public int Points { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 来源ID
|
|
||||||
/// </summary>
|
|
||||||
public string? SourceId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 备注
|
|
||||||
/// </summary>
|
|
||||||
public string? Remark { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 变动后的总积分
|
|
||||||
/// </summary>
|
|
||||||
public int TotalPoints { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 变动时间
|
|
||||||
/// </summary>
|
|
||||||
public DateTime OccurredAt { get; set; } = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Fengling.Member.Domain.Aggregates.PointsModel;
|
using Fengling.Member.Domain.Aggregates.PointsModel;
|
||||||
|
using Fengling.Member.Domain.Events.Points;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Fengling.Member.Application.Events;
|
namespace Fengling.Member.Application.Events;
|
||||||
@ -23,8 +24,8 @@ public class PointsChangedEventHandler : INotificationHandler<PointsChangedEvent
|
|||||||
public async Task Handle(PointsChangedEvent notification, CancellationToken cancellationToken)
|
public async Task Handle(PointsChangedEvent notification, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"Handling PointsChangedEvent for MemberId={MemberId}, CodeId={CodeId}, Points={Points}",
|
"Handling PointsChangedEvent for MemberId={MemberId}, AccountId={AccountId}, ChangedPoints={ChangedPoints}",
|
||||||
notification.MemberId, notification.CodeId, notification.Points);
|
notification.MemberId, notification.AccountId, notification.ChangedPoints);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -44,17 +45,17 @@ public class PointsChangedEventHandler : INotificationHandler<PointsChangedEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 确定交易类型分类
|
// 确定交易类型分类
|
||||||
var transactionTypeCategory = notification.Points >= 0
|
var transactionTypeCategory = notification.ChangedPoints >= 0
|
||||||
? PointsTransactionType.Earn
|
? PointsTransactionType.Earn
|
||||||
: PointsTransactionType.Deduct;
|
: PointsTransactionType.Deduct;
|
||||||
|
|
||||||
// 创建积分明细记录(使用 factory 方法)
|
// 创建积分明细记录(使用 factory 方法)
|
||||||
// 注意:PointsAccountId 为 0,需要根据业务需求从缓存或数据库获取
|
// 注意:PointsAccountId 需要根据业务需求从缓存或数据库获取
|
||||||
var transaction = PointsTransaction.Create(
|
var transaction = PointsTransaction.Create(
|
||||||
pointsAccountId: 0, // TODO: 需要根据 MemberId 查询或创建 PointsAccount
|
pointsAccountId: notification.AccountId,
|
||||||
memberId: notification.MemberId,
|
memberId: notification.MemberId,
|
||||||
tenantId: notification.TenantId,
|
tenantId: notification.TenantId,
|
||||||
points: notification.Points,
|
points: notification.ChangedPoints,
|
||||||
transactionType: notification.TransactionType,
|
transactionType: notification.TransactionType,
|
||||||
sourceId: notification.SourceId ?? string.Empty,
|
sourceId: notification.SourceId ?? string.Empty,
|
||||||
typeCategory: transactionTypeCategory,
|
typeCategory: transactionTypeCategory,
|
||||||
@ -64,13 +65,13 @@ public class PointsChangedEventHandler : INotificationHandler<PointsChangedEvent
|
|||||||
|
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"PointsChangedEvent processed successfully. MemberId={MemberId}, Points={Points}, TotalPoints={TotalPoints}",
|
"PointsChangedEvent processed successfully. MemberId={MemberId}, Points={Points}, TotalPoints={TotalPoints}",
|
||||||
notification.MemberId, notification.Points, notification.TotalPoints);
|
notification.MemberId, notification.ChangedPoints, notification.NewBalance);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex,
|
_logger.LogError(ex,
|
||||||
"Error handling PointsChangedEvent. MemberId={MemberId}, CodeId={CodeId}",
|
"Error handling PointsChangedEvent. MemberId={MemberId}, AccountId={AccountId}",
|
||||||
notification.MemberId, notification.CodeId);
|
notification.MemberId, notification.AccountId);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,7 +94,7 @@ public class PointsProcessingService : IPointsProcessingService
|
|||||||
|
|
||||||
// 7. 发布领域事件(异步持久化到数据库)
|
// 7. 发布领域事件(异步持久化到数据库)
|
||||||
var domainEvent = new PointsChangedEvent(
|
var domainEvent = new PointsChangedEvent(
|
||||||
0, // AccountId - 缓存中暂无ID,事件消费者处理
|
PointsAccountId.New(), // AccountId - 缓存中暂无ID,事件消费者处理
|
||||||
request.MemberId,
|
request.MemberId,
|
||||||
tenantId,
|
tenantId,
|
||||||
request.IsAddition ? request.Points : -request.Points,
|
request.IsAddition ? request.Points : -request.Points,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ namespace Fengling.Member.Domain.Aggregates.PointsModel;
|
|||||||
|
|
||||||
public class PointsTransaction : Entity<long>
|
public class PointsTransaction : Entity<long>
|
||||||
{
|
{
|
||||||
public long PointsAccountId { get; private set; }
|
public PointsAccountId PointsAccountId { get; private set; } = PointsAccountId.New();
|
||||||
public long MemberId { get; private set; }
|
public long MemberId { get; private set; }
|
||||||
public long TenantId { get; private set; }
|
public long TenantId { get; private set; }
|
||||||
public int Points { get; private set; }
|
public int Points { get; private set; }
|
||||||
@ -23,7 +23,7 @@ public class PointsTransaction : Entity<long>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PointsTransaction Create(
|
public static PointsTransaction Create(
|
||||||
long pointsAccountId,
|
PointsAccountId pointsAccountId,
|
||||||
long memberId,
|
long memberId,
|
||||||
long tenantId,
|
long tenantId,
|
||||||
int points,
|
int points,
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
using Fengling.Member.Domain.Aggregates.PointsModel;
|
||||||
|
|
||||||
namespace Fengling.Member.Domain.Events.Points;
|
namespace Fengling.Member.Domain.Events.Points;
|
||||||
|
|
||||||
public record PointsChangedEvent(
|
public record PointsChangedEvent(
|
||||||
long AccountId,
|
PointsAccountId AccountId,
|
||||||
long MemberId,
|
long MemberId,
|
||||||
long TenantId,
|
long TenantId,
|
||||||
int ChangedPoints,
|
int ChangedPoints,
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public class AddPointsRequest
|
|||||||
|
|
||||||
public class AddPointsResponse
|
public class AddPointsResponse
|
||||||
{
|
{
|
||||||
public long AccountId { get; set; }
|
public PointsAccountId AccountId { get; set; } = PointsAccountId.New();
|
||||||
public long MemberId { get; set; }
|
public long MemberId { get; set; }
|
||||||
public int AddedPoints { get; set; }
|
public int AddedPoints { get; set; }
|
||||||
public int TotalPoints { get; set; }
|
public int TotalPoints { get; set; }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user