yz_server/Server/Services/DataMigration/MigrationAutoMapperProfile.cs

101 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Common.Models.Enums;
using Common.Models.SubTables;
using Common.Models.UnqTables;
namespace Server.Services.DataMigration
{
/// <summary>
/// 数据迁移配置,实体映射
/// </summary>
public class MigrationAutoMapperProfile : Profile
{
public MigrationAutoMapperProfile()
{
var tbMap = CreateMap<dynamic, TbOrder>();
tbMap.Ignore(s => s.IsChange);
tbMap.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
var lianmengMap = CreateMap<dynamic, Lianmeng>();
lianmengMap.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
lianmengMap.AfterMap((src, dest) =>
{
if (dest.Nickname == null)
{
dest.Nickname = "";
}
if (dest.Username == null)
{
dest.Username = "";
}
});
var robotMap = CreateMap<dynamic, Robot>();
robotMap.Ignore(s => s.IsOnlineRobot);
robotMap.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
robotMap.AfterMap((src, dest) =>
{
if (dest.Nickname == null)
{
dest.Nickname = "";
}
if (dest.LoginAddress == null)
{
dest.LoginAddress = "";
}
if (dest.LoginVersion == null)
{
dest.LoginVersion = "";
}
});
CreateMap<dynamic, DyOrder>()
.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
CreateMap<dynamic, JdOrder>()
.Ignore(s => s.IsChange)
.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
CreateMap<dynamic, PddOrder>()
.Ignore(s => s.IsChange)
.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
CreateMap<dynamic, SnOrder>()
.Ignore(s => s.IsChange)
.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
CreateMap<dynamic, WphOrder>()
.Ignore(s => s.IsChange)
.ForAllOtherMembers(s =>
{
s.MapFromDynamic(s.DestinationMember.Name);
});
}
}
}