using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Util.Domain; using Util.Domain.Auditing; using Util.Domain.Entities; using Util.Domain.Extending; using Util.Tenants; using Util.Tests.Events; namespace Util.Tests.Models; /// /// 产品 /// [Description( "产品" )] public class Product : AggregateRoot, IDelete, ITenant, IAudited, IExtraProperties { /// /// 初始化产品 /// public Product() : this( Guid.Empty ) { } /// /// 初始化产品 /// /// 产品标识 public Product( Guid id ) : base( id ) { TestProperty2 = new ProductItem(); TestProperty4 = new ProductItem2(); TestProperties = new List(); } /// /// 产品编码 /// [Description( "产品编码" )] [MaxLength( 50 )] public string Code { get; set; } /// /// 产品名称 /// [Description( "产品名称" )] [MaxLength( 500 )] public string Name { get; set; } /// /// 价格 /// [Description( "价格" )] public decimal Price { get; set; } /// /// 价格 /// [Description( "价格" )] public int IntPrice { get; set; } /// /// 价格 /// [Description( "价格" )] public long LongPrice { get; set; } /// /// 价格 /// [Description( "价格" )] public float FloatPrice { get; set; } /// /// 描述 /// [Description( "描述" )] public string Description { get; set; } /// /// 启用 /// [Description( "启用" )] public bool Enabled { get; set; } /// /// 创建时间 /// [Description( "创建时间" )] public DateTime? CreationTime { get; set; } /// /// 创建人 /// [Description( "创建人" )] public Guid? CreatorId { get; set; } /// /// 最后修改时间 /// [Description( "最后修改时间" )] public DateTime? LastModificationTime { get; set; } /// /// 最后修改人 /// [Description( "最后修改人" )] public Guid? LastModifierId { get; set; } /// /// 是否删除 /// [Description( "是否删除" )] public bool IsDeleted { get; set; } /// /// 租户标识 /// [Description( "租户标识" )] public string TenantId { get; set; } /// /// 简单扩展属性 /// [NotMapped] public string TestProperty1 { get => ExtraProperties.GetProperty( nameof( TestProperty1 ) ); set => ExtraProperties.SetProperty( nameof( TestProperty1 ), value ); } private readonly ExtraProperty _property2 = new( nameof( TestProperty2 ) ); /// /// 对象扩展属性 /// [NotMapped] public ProductItem TestProperty2 { get => _property2.GetProperty( ExtraProperties ); set => _property2.SetProperty( ExtraProperties, value ); } /// /// 枚举扩展属性 /// [NotMapped] public ProductEnum? TestProperty3 { get => ExtraProperties.GetProperty( nameof( TestProperty3 ) ); set => ExtraProperties.SetProperty( nameof( TestProperty3 ), value ); } private readonly ExtraProperty _property4 = new( nameof( TestProperty4 ) ); /// /// 不可变对象扩展属性 /// [NotMapped] public ProductItem2 TestProperty4 { get => _property4.GetProperty( ExtraProperties ); set => _property4.SetProperty( ExtraProperties, value ); } private readonly ExtraProperty> _properties = new( nameof( TestProperties ) ); /// /// 对象集合扩展属性 /// [NotMapped] public List TestProperties { get => _properties.GetProperty( ExtraProperties ); set => _properties.SetProperty( ExtraProperties, value ); } private readonly ExtraProperty _property5 = new( nameof( TestProperty5 ) ); /// /// 不可变对象扩展属性 /// [NotMapped] public ApplicationExtend TestProperty5 { get => _property5.GetProperty( ExtraProperties ); set => _property5.SetProperty( ExtraProperties, value ); } /// /// 日期扩展属性 /// [NotMapped] public DateTime TestProperty6 { get => ExtraProperties.GetProperty( nameof( TestProperty6 ) ); set => ExtraProperties.SetProperty( nameof( TestProperty6 ), value ); } private readonly ExtraProperty> _property7 = new( nameof( TaskRecordList ) ); /// /// 执行记录 /// [NotMapped] public List TaskRecordList { get => _property7.GetProperty( ExtraProperties ); set => _property7.SetProperty( ExtraProperties, value ); } /// /// 添加变更列表 /// protected override void AddChanges( Product other ) { AddChange( t => t.Code, other.Code ); AddChange( t => t.Name, other.Name ); AddChange( t => t.Price, other.Price ); AddChange( t => t.Description, other.Description ); AddChange( t => t.Enabled, other.Enabled ); AddChange( t => t.CreationTime, other.CreationTime ); AddChange( t => t.CreatorId, other.CreatorId ); AddChange( t => t.LastModificationTime, other.LastModificationTime ); AddChange( t => t.LastModifierId, other.LastModifierId ); } /// /// 测试领域事件方法1 - 添加1个本地事件 TestEvent2 /// public void TestDomainEvent1() { AddDomainEvent( new TestEvent2 { Id = Id, Name = "a" } ); } /// /// 测试领域事件方法2 - 添加1个集成事件 TestEvent3 /// public void TestDomainEvent2() { AddDomainEvent( new TestEvent3( Id, "a" ) ); } /// /// 获取扩展属性Json /// public string GetExtraPropertiesJson() { return Util.Helpers.Json.ToJson( ExtraProperties ); } }