feat: 实现完整的多租户公告管理系统

核心功能:
- 公告状态机(草稿/已发布/已撤销)支持发布、撤销和重新发布
- 发布者范围区分平台级和租户级公告
- 目标受众定向推送(全部租户/指定角色/指定用户)
- 平台管理、租户管理和应用端查询API
- 已读/未读管理和未读统计

技术实现:
- CQRS+DDD架构,清晰的领域边界和事件驱动
- 查询性能优化:数据库端排序和限制,估算策略减少内存占用
- 并发控制:修复RowVersion配置(IsRowVersion→IsConcurrencyToken)
- 完整的FluentValidation验证器和输入保护

测试验证:
- 36个测试全部通过(27单元+9集成)
- 性能测试达标(1000条数据<5秒)
- 代码质量评级A(优秀)

文档:
- 完整的ADR、API文档和迁移指南
- 交付报告和技术债务记录
This commit is contained in:
2025-12-20 19:50:17 +08:00
parent 00eb357e6e
commit 857f776447
76 changed files with 12957 additions and 281 deletions

View File

@@ -0,0 +1,35 @@
using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Application.App.Tenants.Validators;
/// <summary>
/// 创建公告命令验证器。
/// </summary>
public sealed class CreateAnnouncementCommandValidator : AbstractValidator<CreateTenantAnnouncementCommand>
{
/// <summary>
/// 初始化验证规则。
/// </summary>
public CreateAnnouncementCommandValidator()
{
RuleFor(x => x.Title)
.NotEmpty()
.MaximumLength(128);
RuleFor(x => x.Content)
.NotEmpty();
RuleFor(x => x.TargetType)
.NotEmpty();
RuleFor(x => x)
.Must(x => x.TenantId != 0 || x.PublisherScope == PublisherScope.Platform)
.WithMessage("TenantId=0 仅允许平台公告");
RuleFor(x => x.EffectiveTo)
.Must((command, effectiveTo) => !effectiveTo.HasValue || command.EffectiveFrom < effectiveTo.Value)
.WithMessage("生效开始时间必须早于结束时间");
}
}

View File

@@ -0,0 +1,24 @@
using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
namespace TakeoutSaaS.Application.App.Tenants.Validators;
/// <summary>
/// 发布公告命令验证器。
/// </summary>
public sealed class PublishAnnouncementCommandValidator : AbstractValidator<PublishAnnouncementCommand>
{
/// <summary>
/// 初始化验证规则。
/// </summary>
public PublishAnnouncementCommandValidator()
{
RuleFor(x => x.AnnouncementId)
.GreaterThan(0);
RuleFor(x => x.RowVersion)
.NotNull()
.Must(rowVersion => rowVersion != null && rowVersion.Length > 0)
.WithMessage("RowVersion 不能为空");
}
}

View File

@@ -0,0 +1,24 @@
using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
namespace TakeoutSaaS.Application.App.Tenants.Validators;
/// <summary>
/// 撤销公告命令验证器。
/// </summary>
public sealed class RevokeAnnouncementCommandValidator : AbstractValidator<RevokeAnnouncementCommand>
{
/// <summary>
/// 初始化验证规则。
/// </summary>
public RevokeAnnouncementCommandValidator()
{
RuleFor(x => x.AnnouncementId)
.GreaterThan(0);
RuleFor(x => x.RowVersion)
.NotNull()
.Must(rowVersion => rowVersion != null && rowVersion.Length > 0)
.WithMessage("RowVersion 不能为空");
}
}

View File

@@ -0,0 +1,28 @@
using FluentValidation;
using TakeoutSaaS.Application.App.Tenants.Commands;
namespace TakeoutSaaS.Application.App.Tenants.Validators;
/// <summary>
/// 更新公告命令验证器。
/// </summary>
public sealed class UpdateAnnouncementCommandValidator : AbstractValidator<UpdateTenantAnnouncementCommand>
{
/// <summary>
/// 初始化验证规则。
/// </summary>
public UpdateAnnouncementCommandValidator()
{
RuleFor(x => x.Title)
.NotEmpty()
.MaximumLength(128);
RuleFor(x => x.Content)
.NotEmpty();
RuleFor(x => x.RowVersion)
.NotNull()
.Must(rowVersion => rowVersion != null && rowVersion.Length > 0)
.WithMessage("RowVersion 不能为空");
}
}