using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AX.FireTrainingSys.DTOs; using AX.FireTrainingSys.Models; using Mapster; namespace AX.FireTrainingSys { /// /// 类型映射。 /// public static class EntityMapper { public static void Initialize() { TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true); TypeAdapterConfig .ForType() .Ignore(dest => dest.Id, dest => dest.UserId, dest => dest.ModifiedTime, dest => dest.BuildingTypes, dest => dest.Referenced); TypeAdapterConfig .ForType() .Ignore(dest => dest.BuildingTypes) .Map(dest => dest.ModifiedTime, src => src.ModifiedTime.ToLocalTime()) .Map(dest => dest.Referenced, src => src.Referenced > 0) .Map(dest => dest.Creator, src => src.User.RealName); TypeAdapterConfig .ForType() .Map(dest => dest.X, src => src.Position.X) .Map(dest => dest.Y, src => src.Position.Y) .Map(dest => dest.Z, src => src.Position.Z); TypeAdapterConfig .ForType() .Map(dest => dest.Position, src => new Vector3(src.X ?? 0, src.Y ?? 0, src.Z ?? 0)); TypeAdapterConfig .ForType() .Ignore(dest => dest.Id) .Map(dest => dest.X, src => src.Position.X) .Map(dest => dest.Y, src => src.Position.Y) .Map(dest => dest.Z, src => src.Position.Z); TypeAdapterConfig .ForType() .Map(dest => dest.Position, src => new Vector3(src.X ?? 0, src.Y ?? 0, src.Z ?? 0)); TypeAdapterConfig .ForType() .Ignore(dest => dest.Id, dest => dest.UserId, dest => dest.CreationTime, dest => dest.BuildingTypes); TypeAdapterConfig .ForType() .Ignore(dest => dest.BuildingTypes) .Map(dest => dest.CreationTime, src => src.CreationTime.ToLocalTime()) .Map(dest => dest.RealName, src => src.User.RealName); } } }