消防培训系统服务器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.9 KiB

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
{
/// <summary>
/// 类型映射。
/// </summary>
public static class EntityMapper
{
public static void Initialize()
{
TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true);
TypeAdapterConfig<CoursewareInfo, Courseware>
.ForType()
.Ignore(dest => dest.Id,
dest => dest.UserId,
dest => dest.ModifiedTime,
dest => dest.BuildingTypes,
dest => dest.Referenced);
TypeAdapterConfig<Courseware, CoursewareInfo>
.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<OrganizationInfo, Organization>
.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<Organization, OrganizationInfo>
.ForType()
.Map(dest => dest.Position,
src => new Vector3(src.X ?? 0, src.Y ?? 0, src.Z ?? 0));
TypeAdapterConfig<OrganizationInfo, TemplateOrganization>
.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<TemplateOrganization, OrganizationInfo>
.ForType()
.Map(dest => dest.Position,
src => new Vector3(src.X ?? 0, src.Y ?? 0, src.Z ?? 0));
TypeAdapterConfig<DisasterInfo, Disaster>
.ForType()
.Ignore(dest => dest.Id,
dest => dest.UserId,
dest => dest.CreationTime,
dest => dest.BuildingTypes);
TypeAdapterConfig<Disaster, DisasterInfo>
.ForType()
.Ignore(dest => dest.BuildingTypes)
.Map(dest => dest.CreationTime,
src => src.CreationTime.ToLocalTime())
.Map(dest => dest.RealName,
src => src.User.RealName);
}
}
}