using YY.Admin.Core.Services;
using YY.Admin.Core.Sync;
namespace YY.Admin.Infrastructure.Sync;
///
/// 将桌面用户 CRUD 写入 Outbox,通过 /sys/sync/batch 反同步到 Jeecg 后端。
/// 断网时自动持久化,联网后续传。
///
public sealed class UserSyncOutbox : IUserSyncOutbox
{
private readonly OutboxProcessor _outboxProcessor;
public UserSyncOutbox(OutboxProcessor outboxProcessor)
{
_outboxProcessor = outboxProcessor;
}
public Task EnqueueCreateAsync(
string userId, string account, string? realName, int? sex, DateTime? birthday, string? phone, string? email, int status, string? updateBy,
CancellationToken cancellationToken = default)
{
return _outboxProcessor.EnqueueAsync(
SysUserSyncOutbox.AggregateType,
userId,
SysUserSyncOutbox.EventCreate,
new { userId, account, realName, sex, birthday, phone, email, status, updateBy },
cancellationToken);
}
public Task EnqueueUpdateAsync(
string userId, string account, string? realName, int? sex, DateTime? birthday, string? phone, string? email, int status, string? updateBy,
CancellationToken cancellationToken = default)
{
return _outboxProcessor.EnqueueAsync(
SysUserSyncOutbox.AggregateType,
userId,
SysUserSyncOutbox.EventUpdate,
new { userId, account, realName, sex, birthday, phone, email, status, updateBy },
cancellationToken);
}
public Task EnqueueToggleStatusAsync(
string userId, int status, string? updateBy,
CancellationToken cancellationToken = default)
{
return _outboxProcessor.EnqueueAsync(
SysUserSyncOutbox.AggregateType,
userId,
SysUserSyncOutbox.EventToggleStatus,
new { userId, status, updateBy },
cancellationToken);
}
public Task EnqueueDeleteAsync(string userId, CancellationToken cancellationToken = default)
{
return _outboxProcessor.EnqueueAsync(
SysUserSyncOutbox.AggregateType,
userId,
SysUserSyncOutbox.EventDelete,
new { userId },
cancellationToken);
}
public Task EnqueueBatchDeleteAsync(IReadOnlyList userIds, CancellationToken cancellationToken = default)
{
return _outboxProcessor.EnqueueAsync(
SysUserSyncOutbox.AggregateType,
string.Join(",", userIds),
SysUserSyncOutbox.EventBatchDelete,
new { userIds },
cancellationToken);
}
}