using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using ClassNotify.Shared.Models;
namespace ClassNotify.Server.Domain.Entities;
///
/// 学校/机构租户实体
///
public class Tenant
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "t_beijing_no4"
public string Name { get; set; } = string.Empty; // e.g. "北京四中"
public string TenantType { get; set; } = "School"; // "School" (普通学校) or "Personal" (独立/免校个人教师空间)
public bool IsActive { get; set; } = true;
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public ICollection Classrooms { get; set; } = new List();
public ICollection Users { get; set; } = new List();
public ICollection Devices { get; set; } = new List();
public ICollection ActivationCodes { get; set; } = new List();
public ICollection Notifications { get; set; } = new List();
}
///
/// 教师/管理员用户实体
///
public class User
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "usr_1001"
public string TenantId { get; set; } = string.Empty;
public string Username { get; set; } = string.Empty;
public string PasswordHash { get; set; } = string.Empty;
public string FullName { get; set; } = string.Empty;
[NotMapped]
public string DisplayName => FullName;
public string Role { get; set; } = "Teacher"; // Teacher, SchoolAdmin, SuperAdmin
public bool IsLocked { get; set; } = false;
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? LastLoginAt { get; set; }
public int TokenVersion { get; set; } = 1;
public string? RecoveryEmail { get; set; }
public bool EmailVerified { get; set; } = false;
public string? RecoveryKeyHash { get; set; }
public DateTimeOffset? RecoveryKeyCreatedAtUtc { get; set; }
public bool MustChangePassword { get; set; } = false;
public DateTimeOffset? TemporaryPasswordExpiresAtUtc { get; set; }
public string? Mobile { get; set; }
public DateTimeOffset? TrialEndsAt { get; set; }
public DateTimeOffset? VipExpiresAt { get; set; }
public bool IsVipActive(DateTimeOffset now) => VipExpiresAt.HasValue && VipExpiresAt.Value > now;
public bool IsTrialActive(DateTimeOffset now) => TrialEndsAt.HasValue && TrialEndsAt.Value > now;
public Tenant? Tenant { get; set; }
}
///
/// 班级实体
///
public class Classroom
{
public string Id { get; set; } = string.Empty; // e.g. "cls_801"
public string TenantId { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty; // e.g. "八年级(1)班"
public string? Grade { get; set; }
public string? RoomNumber { get; set; }
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public Tenant? Tenant { get; set; }
public ICollection Devices { get; set; } = new List();
}
///
/// 教室硬件多媒体设备实体
///
public class Device
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "dev_52f0"
public string TenantId { get; set; } = string.Empty;
public string ClassroomId { get; set; } = string.Empty;
public string DeviceTokenHash { get; set; } = string.Empty;
public string? RawDeviceToken { get; set; } // Kept only for legacy migration
public string? InstallationId { get; set; } // Unique installation instance identifier
public string? HardwareComponentsHash { get; set; } // Deterministic hardware fingerprint (MachineGuid + BIOS + Board)
public string? Hostname { get; set; }
public string? DisplayLabel { get; set; } // Per-device custom remark/label for SuperAdmin
public bool IsActive { get; set; } = true;
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? BindingStartedAtUtc { get; set; }
public DateTimeOffset? LastHeartbeatAt { get; set; }
public string? LastHeartbeatCorrelationId { get; set; }
public string? ServiceVersion { get; set; }
public string? ClientVersion { get; set; }
public int? ProtocolVersion { get; set; }
public string? OsVersion { get; set; }
public string? Architecture { get; set; }
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public bool? ClientProcessAvailable { get; set; }
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public bool IsOnline => LastHeartbeatAt.HasValue && (DateTimeOffset.UtcNow - LastHeartbeatAt.Value).TotalSeconds <= 120;
// License Management Fields (P3)
public DateTimeOffset? LicensedUntil { get; set; }
public string LicenseTier { get; set; } = "Trial";
public bool TrialUsed { get; set; } = true;
public Tenant? Tenant { get; set; }
public Classroom? Classroom { get; set; }
public ICollection Receipts { get; set; } = new List();
}
///
/// 设备加密凭据恢复记录 (仅用于 InstallationId 幂等恢复,不直接在业务代码暴露明文)
///
public class DeviceCredentialRecord
{
[Key]
public string DeviceId { get; set; } = string.Empty;
public string InstallationId { get; set; } = string.Empty;
public string DeviceTokenHash { get; set; } = string.Empty;
public string EncryptedRecoverableToken { get; set; } = string.Empty;
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? RotatedAt { get; set; }
}
///
/// 一次性设备激活码实体
///
public class ActivationCode
{
[Key]
public string Code { get; set; } = string.Empty; // e.g. "H8K4-29DP"
public string? Id { get; set; } // Opaque unique identifier for UI and Reveal API, e.g. "act_..."
public string TenantId { get; set; } = string.Empty;
public string ClassroomId { get; set; } = string.Empty;
public DateTimeOffset ExpiresAt { get; set; } = DateTimeOffset.UtcNow.AddDays(7);
public bool IsUsed { get; set; }
public DateTimeOffset? UsedAt { get; set; }
public string? UsedByDeviceId { get; set; }
public string? InstallationId { get; set; } // Bound to first installation instance
// License Duration Configuration (P3)
public int? LicenseDurationDays { get; set; } = 7;
public string LicenseTier { get; set; } = "Trial";
// Batch Notes / Tag (Commercial Pilot)
public string? Notes { get; set; }
// Teacher Direct Assignment & Dual-Distribution (Turn 50)
public string? TargetClassNameAtIssue { get; set; } // Historical snapshot of class name at issue time (e.g. "81班")
public string? AssignedTeacherId { get; set; } // Direct assignment to Teacher User.Id
public string? AssignedTeacherName { get; set; } // Teacher username or display name
public string DistributionMethod { get; set; } = "External"; // "External" (微信/纸质) or "TeacherAccount" (账号直派)
public DateTimeOffset? AssignedAt { get; set; }
public string? AssignedByUserId { get; set; }
public DateTimeOffset? SecretExposedAtUtc { get; set; }
public string Status { get; set; } = "Issued"; // Draft, Issued, Redeemed, Expired, Revoked
public DateTimeOffset? RevokedAtUtc { get; set; }
public string? RevokedReason { get; set; }
public string Purpose { get; set; } = "ProvisionAndLicense"; // ProvisionAndLicense, PersonalProvisionAndLicense, RenewLicenseOnly, Reprovision
public bool IsSignupTrial { get; set; } = false; // Turn 62: Exactly one signup trial code per Personal Tenant
public DateTimeOffset? RedeemBeforeUtc { get; set; } // Turn 62: Redemption deadline (30 days from issuance)
public Tenant? Tenant { get; set; }
}
///
/// 激活码教师指派与流转历史记录 (Immutable Audit Trail)
///
public class ActivationCodeAssignment
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "asg_xxx"
public string TenantId { get; set; } = string.Empty;
public string ActivationCodeId { get; set; } = string.Empty;
public string CodeMasked { get; set; } = string.Empty;
public string TeacherUserId { get; set; } = string.Empty;
public string TeacherName { get; set; } = string.Empty;
public string AssignedByUserId { get; set; } = string.Empty;
public DateTimeOffset AssignedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? UnassignedAtUtc { get; set; }
public string? Reason { get; set; }
}
///
/// 设备授权与续费审计流水实体 (P3 License Lifecycle)
///
public class DeviceLicenseRecord
{
[Key]
public string Id { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public string? InstallationId { get; set; }
public string ClassroomId { get; set; } = string.Empty;
public string Action { get; set; } = "ACTIVATE"; // ACTIVATE, RENEW, EXTEND, REVOKE
public string LicenseTier { get; set; } = "Trial";
public int? GrantedDays { get; set; }
public DateTimeOffset? PreviousLicensedUntil { get; set; }
public DateTimeOffset? NewLicensedUntil { get; set; }
public string? SourceActivationCode { get; set; }
public string? OperatorUsername { get; set; }
public string? Reason { get; set; }
public string? ClientRequestId { get; set; }
public bool IsTest { get; set; } = false; // Isolate synthetic test records from production KPIs
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}
///
/// 教师/系统下发通知主表 (不存储单一设备 ACK 状态)
///
public class Notification
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "msg_1789944446934_0471"
public string TenantId { get; set; } = string.Empty;
public string ClassroomId { get; set; } = string.Empty;
public string? SenderUserId { get; set; }
public string SenderName { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public string Title { get; set; } = "🔔 老师呼叫";
public string Priority { get; set; } = "Normal";
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? ExpiresAt { get; set; }
public bool Voice { get; set; } = true;
public bool Shake { get; set; } = true;
public int DurationSeconds { get; set; } = 15;
public bool IsCancelled { get; set; } = false;
public DateTimeOffset? CancelledAt { get; set; }
public string? CancelledBy { get; set; }
public string? BroadcastId { get; set; }
public string CorrelationId { get; set; } = string.Empty;
public Tenant? Tenant { get; set; }
public ICollection Receipts { get; set; } = new List();
}
///
/// 设备通知回执明细表 (按设备独立记录状态与时间线,防止单点覆盖)
///
public class NotificationReceipt
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "rcpt_..."
public string NotificationId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
///
/// 回执阶段状态: Sent, DeviceReceived, Displayed, Acknowledged, Failed, Timeout
///
public string Status { get; set; } = "Sent";
public DateTimeOffset? DeviceReceivedAt { get; set; }
public DateTimeOffset? DisplayedAt { get; set; }
public DateTimeOffset? AcknowledgedAt { get; set; }
public DateTimeOffset? FailedAt { get; set; }
public string? FailureReason { get; set; }
///
/// 视觉回执状态: None, Available, Expired
///
public string VisualReceiptState { get; set; } = "None";
public string? VisualReceiptPath { get; set; }
public DateTimeOffset? VisualReceiptCapturedAt { get; set; }
public DateTimeOffset? VisualReceiptExpiresAt { get; set; }
public long? VisualReceiptSizeBytes { get; set; }
public string? VisualReceiptSha256 { get; set; }
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
public Notification? Notification { get; set; }
public Device? Device { get; set; }
}
///
/// JSON 数据一次性迁移记录标记
///
public class MigrationMarker
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "JsonMigration_v1"
public DateTimeOffset MigratedAt { get; set; } = DateTimeOffset.UtcNow;
public string? Details { get; set; }
}
///
/// 教室终端受控远程运维命令实体
/// 全链路统一 CommandId (cmd_xxxxx),从创建到最终上报不可篡改
///
public class DeviceCommand
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "cmd_..."
[Required]
public string TenantId { get; set; } = string.Empty;
[Required]
public string DeviceId { get; set; } = string.Empty;
[Required]
public string CommandType { get; set; } = string.Empty; // "SelfCheck", "RestartClient", "Reconnect", "RefreshConfig"
public string? Parameters { get; set; }
[Required]
public string CreatedBy { get; set; } = string.Empty;
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset ExpiresAt { get; set; }
public DateTimeOffset? StartedAt { get; set; }
public DateTimeOffset? CompletedAt { get; set; }
[Required]
public string Status { get; set; } = "Pending"; // "Pending", "Dispatched", "Succeeded", "Failed", "TimedOut", "Expired"
public int? ResultCode { get; set; }
public long? DurationMs { get; set; }
public string? ResultMessage { get; set; }
public Tenant? Tenant { get; set; }
public Device? Device { get; set; }
}
///
/// 全局唯一远程命令超期与超时状态终态化规则
/// 彻底消除各查询路径与后台 Worker 之间的状态竞态
///
public static class DeviceCommandNormalizer
{
public static bool NormalizeExpiredOrTimedOut(DeviceCommand cmd, DateTimeOffset now)
{
if (ClassNotify.Shared.Models.DeviceCommandStatuses.IsTerminal(cmd.Status))
{
return false;
}
if (cmd.Status == ClassNotify.Shared.Models.DeviceCommandStatuses.Pending)
{
if (cmd.ExpiresAt <= now)
{
cmd.Status = ClassNotify.Shared.Models.DeviceCommandStatuses.Expired;
cmd.CompletedAt = now;
cmd.ResultCode = -2;
cmd.ResultMessage = "Command pending expired before dispatch or device reconnect.";
return true;
}
}
else if (cmd.Status == ClassNotify.Shared.Models.DeviceCommandStatuses.Dispatched)
{
var dispatchedAt = cmd.StartedAt ?? cmd.CreatedAt;
if (cmd.ExpiresAt <= now)
{
cmd.Status = ClassNotify.Shared.Models.DeviceCommandStatuses.TimedOut;
cmd.CompletedAt = now;
cmd.ResultCode = -4;
cmd.ResultMessage = "Command expired after dispatch without device result.";
return true;
}
else if (now - dispatchedAt >= TimeSpan.FromMinutes(2))
{
cmd.Status = ClassNotify.Shared.Models.DeviceCommandStatuses.TimedOut;
cmd.CompletedAt = now;
cmd.ResultCode = -4;
cmd.ResultMessage = "Command timed out (device did not report execution result within 2 minutes).";
return true;
}
}
return false;
}
}
///
/// 管理员操作审计事件实体
///
public class AdminAuditEvent
{
[Key]
public string Id { get; set; } = string.Empty;
public DateTimeOffset OccurredAt { get; set; } = DateTimeOffset.UtcNow;
public string ActorUsername { get; set; } = string.Empty;
public string ActorRole { get; set; } = string.Empty;
public string Action { get; set; } = string.Empty;
public string TargetType { get; set; } = string.Empty;
public string TargetId { get; set; } = string.Empty;
public string? Details { get; set; }
public string? IpAddress { get; set; }
}
///
/// 终端批量自检批次实体 (P2.5 RC1-2)
/// 严格不绑定单一 TenantId,支持 SuperAdmin 跨校集中运维
/// 状态统计由关联的 DeviceSelfCheckRun 动态聚合计算,防止字段状态漂移
///
public class DeviceSelfCheckBatch
{
[Key]
public string Id { get; set; } = string.Empty;
public string CorrelationId { get; set; } = string.Empty;
public string ClientRequestId { get; set; } = string.Empty;
public string CreatedByUserId { get; set; } = string.Empty;
public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset DeadlineAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public int TargetDeviceCount { get; set; }
public string Status { get; set; } = "Running";
public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}
///
/// 设备远程诊断/自检运行记录
///
public class DeviceSelfCheckRun
{
[Key]
public string Id { get; set; } = string.Empty; // e.g. "sc_1790268406949_0471"
public string? BatchId { get; set; }
public string TenantId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public string CorrelationId { get; set; } = string.Empty;
public string Status { get; set; } = "Pending"; // Pending, Completed, Failed, Timeout (Legacy mirror)
public string RunState { get; set; } = ClassNotify.Shared.Models.SelfCheckRunStates.PendingDispatch; // PendingDispatch, Dispatched, Completed, Unreachable, TimedOut
public string? OverallStatus { get; set; } // Healthy, Warning, Failed
public int DispatchAttemptCount { get; set; }
public DateTimeOffset RequestedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? DispatchedAtUtc { get; set; }
public DateTimeOffset DeadlineAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public string? ResultJson { get; set; }
public string RequestedByUserId { get; set; } = string.Empty;
public Tenant? Tenant { get; set; }
public Device? Device { get; set; }
public DeviceSelfCheckBatch? Batch { get; set; }
}
///
/// 设备技术诊断包实体 (P2.5 RC1-3 Support Bundle)
///
public sealed class DeviceSupportBundle
{
[Key]
public string Id { get; set; } = string.Empty;
public string ClientRequestId { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public string CorrelationId { get; set; } = string.Empty;
public string RequestedByUserId { get; set; } = string.Empty;
public string Status { get; set; } = ClassNotify.Shared.Models.SupportBundleStatuses.PendingDispatch;
public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset UpdatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset DeadlineAtUtc { get; set; }
public DateTimeOffset? DispatchedAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public DateTimeOffset? ExpiresAtUtc { get; set; }
public int DispatchAttemptCount { get; set; }
public DateTimeOffset? LastDispatchAttemptAtUtc { get; set; }
public DateTimeOffset? NextDispatchAttemptAtUtc { get; set; }
public string? StoragePath { get; set; }
public long? SizeBytes { get; set; }
public string? Sha256 { get; set; }
public string? ErrorCode { get; set; }
public Tenant? Tenant { get; set; }
public Device? Device { get; set; }
}
///
/// 客户端在线升级发布包实体 (P2.5 RC1-4)
///
public sealed class UpdateRelease
{
public string Id { get; set; } = "";
public string Version { get; set; } = "";
public string Architecture { get; set; } = "win-x64";
public string PackageRelativePath { get; set; } = "";
public long PackageSizeBytes { get; set; }
public string PackageSha256 { get; set; } = "";
public string ManifestSignature { get; set; } = "";
public DateTimeOffset CreatedAtUtc { get; set; }
public bool IsEnabled { get; set; }
}
///
/// 设备升级任务执行记录实体 (P2.5 RC1-4)
///
public sealed class DeviceUpdateRun
{
public string Id { get; set; } = "";
public string TenantId { get; set; } = "";
public string DeviceId { get; set; } = "";
public string ReleaseId { get; set; } = "";
public string CorrelationId { get; set; } = "";
public string RequestedByUserId { get; set; } = "";
public string? ClientRequestId { get; set; }
public string FromVersion { get; set; } = "";
public string TargetVersion { get; set; } = "";
public string Status { get; set; } = ""; // UpdateStatuses
public DateTimeOffset CreatedAtUtc { get; set; }
public DateTimeOffset DeadlineAtUtc { get; set; }
public DateTimeOffset? DispatchedAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public int DispatchAttemptCount { get; set; }
public DateTimeOffset? LastDispatchAttemptAtUtc { get; set; }
public DateTimeOffset? NextDispatchAttemptAtUtc { get; set; }
public string? ErrorCode { get; set; }
public string? ErrorMessage { get; set; }
public string? BatchId { get; set; }
public bool IsCanary { get; set; }
public string DispatchGate { get; set; } = UpdateDispatchGates.Released; // Released, Held
public Tenant? Tenant { get; set; }
public Device? Device { get; set; }
public UpdateRelease? Release { get; set; }
public DeviceUpdateBatch? Batch { get; set; }
}
///
/// 小规模灰度升级批次实体 (P2.5 RC1-4 Phase 3)
/// 严格限制 1~5 台设备,同一学校,单 Canary,人工确认门禁
///
public sealed class DeviceUpdateBatch
{
public string Id { get; set; } = "";
public string TenantId { get; set; } = "";
public string ReleaseId { get; set; } = "";
public string CanaryDeviceId { get; set; } = "";
public string RequestedByUserId { get; set; } = "";
public string? ClientRequestId { get; set; }
public string Status { get; set; } = UpdateBatchStatuses.CanaryRunning;
public int TargetDeviceCount { get; set; }
public DateTimeOffset CreatedAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public DateTimeOffset? StoppedAtUtc { get; set; }
public Tenant? Tenant { get; set; }
public UpdateRelease? Release { get; set; }
public List Runs { get; set; } = new();
}
///
/// 设备首次试用防作弊台账 (Server-Authoritative Device Trial Eligibility)
///
public sealed class DeviceTrialLedger
{
[Key]
public string Id { get; set; } = ""; // e.g. "dtl_..."
public string DeviceTrialKey { get; set; } = ""; // Server HMAC-SHA256 of hardware components
public int FingerprintVersion { get; set; } = 1;
public DateTimeOffset FirstTrialStartedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset TrialEndsAtUtc { get; set; }
public string OriginalDeviceId { get; set; } = "";
public string OriginalTenantId { get; set; } = "";
public string? OriginalUserId { get; set; }
public string Status { get; set; } = "Active"; // Active, Expired
public string? SourceActivationCodeId { get; set; } // Reference to immutable ActivationCode.Id (never persist bearer code)
public int BlockedAttemptCount { get; set; } = 0;
public DateTimeOffset? LastBlockedAtUtc { get; set; }
public string OverrideState { get; set; } = "None"; // None, Granted, Consumed, Revoked, Expired
public int OverrideRemainingUses { get; set; } = 0;
public DateTimeOffset? OverrideExpiresAtUtc { get; set; }
public string? OverrideReason { get; set; }
public string? OverriddenByUserId { get; set; }
public string? OverrideGrantedByUserId { get; set; }
public DateTimeOffset? OverrideGrantedAtUtc { get; set; }
public DateTimeOffset? OverrideConsumedAtUtc { get; set; }
public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? UpdatedAtUtc { get; set; }
}
///
/// 密码重置一次性凭证记录 (15分钟有效,单次使用)
///
public sealed class PasswordResetToken
{
[Key]
public string Id { get; set; } = ""; // e.g. "prt_..."
public string UserId { get; set; } = "";
public string TokenHash { get; set; } = "";
public string TokenType { get; set; } = "EmailLink"; // EmailLink, AdminTicket
public DateTimeOffset ExpiresAtUtc { get; set; }
public bool IsUsed { get; set; } = false;
public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? UsedAtUtc { get; set; }
public string? IssuedByUserId { get; set; }
}
///
/// 教师个人历史回执免打扰/已移除记录 (Per-user Notification History Dismissal)
/// 仅用于在当前教师历史列表中隐藏该通知,不删除底层 Notification、Receipt、VisualReceipt 与审计证据
///
public sealed class NotificationHistoryDismissal
{
[Key]
public string Id { get; set; } = Guid.NewGuid().ToString("N");
public string TenantId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
public string NotificationId { get; set; } = string.Empty;
public DateTimeOffset DismissedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public Notification? Notification { get; set; }
}
///
/// 教师-大屏多对多解耦绑定关系实体
///
public sealed class TeacherDeviceBinding
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
public string TeacherId { get; set; } = string.Empty;
public Guid DeviceId { get; set; }
public string? ClassAlias { get; set; }
public bool IsActive { get; set; } = true;
public DateTimeOffset BoundAt { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? ReleasedAt { get; set; }
}
///
/// 商业化订单实体 (高熵订单号、服务端绝对定价与时长)
///
public sealed class Order
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
public string TeacherId { get; set; } = string.Empty;
[Required]
[MaxLength(64)]
public string OrderNo { get; set; } = string.Empty;
public int AmountFen { get; set; }
public int DurationDays { get; set; } = 365;
[Required]
[MaxLength(32)]
public string Channel { get; set; } = "WeChatPay"; // "WeChatPay" | "Alipay"
[Required]
[MaxLength(32)]
public string Status { get; set; } = "Pending"; // "Pending" | "Paid" | "Closed" | "Failed"
public string? CodeUrl { get; set; }
public string? PrepayId { get; set; }
public string? FailureReason { get; set; }
public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset? PaidAtUtc { get; set; }
public DateTimeOffset ExpiredAtUtc { get; set; }
}
///
/// 商业化卡密实体 (零明文,仅持久化 SHA-256 CodeHash)
///
public sealed class SubscriptionVoucher
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
[MaxLength(64)]
public string CodeHash { get; set; } = string.Empty; // SHA-256
public int DurationDays { get; set; } = 365;
public bool IsUsed { get; set; } = false;
public string? UsedByTeacherId { get; set; }
public DateTimeOffset? UsedAt { get; set; }
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}