feat:添加种子数据

This commit is contained in:
陈淳
2023-04-19 16:35:47 +08:00
parent 654c7d650a
commit 2fd861025a
12 changed files with 2067 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Infrastructure.Ddd.Repositories;
namespace Yi.Framework.Infrastructure.Data.DataSeeds
{
public abstract class AbstractDataSeed<TEntity> : IDataSeed<TEntity>
{
protected readonly IRepository<TEntity> _repository;
public AbstractDataSeed(IRepository<TEntity> repository)
{
_repository = repository;
}
/// <summary>
/// 简单种子数据,重写该方法即可
/// </summary>
/// <returns></returns>
public abstract List<TEntity> GetSeedData();
/// <summary>
/// 复杂数据,重写该方法即可
/// </summary>
/// <returns></returns>
public async virtual Task<bool> DataHandlerAsync()
{
return await _repository.InsertRangeAsync(GetSeedData());
}
/// <summary>
/// 这个用来处理判断是否数据库还存在数据
/// </summary>
/// <returns></returns>
public virtual async Task<bool> IsInvoker()
{
var p = await _repository.IsAnyAsync(x => true);
var p2 = await _repository.CountAsync(x => true);
if (await _repository.CountAsync(u => true) > 0)
{
return false;
}
return true;
}
/// <summary>
/// 完全自定义数据,处理该方法即可
/// </summary>
/// <returns></returns>
public async virtual Task<bool> InvokerAsync()
{
bool res = true;
if (await IsInvoker())
{
return await DataHandlerAsync();
}
return res;
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace Yi.Framework.Infrastructure.Data.DataSeeds
{
public static class DataSeedExtensions
{
public static async Task<IApplicationBuilder> UseDataSeedServer(this IApplicationBuilder builder)
{
if (!App.Configuration.GetSection("EnabledDataSeed").Get<bool>())
{
return builder;
}
var dataSeeds = builder.ApplicationServices.GetServices<IDataSeed>();
var iUnitOfWorkManager = builder.ApplicationServices.GetRequiredService<ISqlSugarClient>();
if (dataSeeds is not null)
{
//using (var uow = iUnitOfWorkManager.CreateContext())
//{
var res = await iUnitOfWorkManager.Ado.UseTranAsync(async () =>
{
foreach (var seed in dataSeeds)
{
await seed.InvokerAsync();
}
});
//var res = uow.Commit();
if (!res.IsSuccess)
{
throw new ApplicationException("种子数据初始化异常");
}
//}
}
return builder.UseMiddleware<DataFilterMiddleware>();
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Infrastructure.Data.DataSeeds
{
public interface IDataSeed
{
Task<bool> InvokerAsync();
}
public interface IDataSeed<TEntity> : IDataSeed
{
}
}

View File

@@ -23,7 +23,6 @@
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Infrastructure\Yi.Framework.Infrastructure.csproj" />
<ProjectReference Include="..\Yi.Framework.Module\Yi.Framework.Module.csproj" />
<ProjectReference Include="..\Yi.Furion.Sqlsugar.Core\Yi.Furion.Sqlsugar.Core.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,132 @@
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Helper;
using Yi.Furion.Core.Rbac.Entities;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
public class DeptDataSeed : AbstractDataSeed<DeptEntity>,ITransient
{
public DeptDataSeed(IRepository<DeptEntity> repository) : base(repository)
{
}
public override List<DeptEntity> GetSeedData()
{
var entities = new List<DeptEntity>();
DeptEntity chengziDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "橙子科技",
DeptCode = "Yi",
OrderNum = 100,
IsDeleted = false,
ParentId = 0,
Leader = "橙子",
Remark = "如名所指"
};
entities.Add(chengziDept);
DeptEntity shenzhenDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "深圳总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(shenzhenDept);
DeptEntity jiangxiDept = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "江西总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(jiangxiDept);
DeptEntity szDept1 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "研发部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept1);
DeptEntity szDept2 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept2);
DeptEntity szDept3 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "测试部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept3);
DeptEntity szDept4 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept4);
DeptEntity szDept5 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "运维部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept5);
DeptEntity jxDept1 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept1);
DeptEntity jxDept2 = new DeptEntity()
{
Id = SnowflakeHelper.NextId,
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept2);
return entities;
}
}
}

View File

@@ -0,0 +1,363 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Module.DictionaryManager.Entities;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
public class DictionaryDataSeed : AbstractDataSeed<DictionaryEntity>
{
public DictionaryDataSeed(IRepository<DictionaryEntity> repository) : base(repository)
{
}
public override List<DictionaryEntity> GetSeedData()
{
List<DictionaryEntity> entities = new List<DictionaryEntity>();
DictionaryEntity dictInfo1 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "男",
DictValue = "0",
DictType = "sys_user_sex",
OrderNum = 100,
Remark = "性别男",
IsDeleted = false,
};
entities.Add(dictInfo1);
DictionaryEntity dictInfo2 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "女",
DictValue = "1",
DictType = "sys_user_sex",
OrderNum = 99,
Remark = "性别女",
IsDeleted = false,
};
entities.Add(dictInfo2);
DictionaryEntity dictInfo3 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "未知",
DictValue = "2",
DictType = "sys_user_sex",
OrderNum = 98,
Remark = "性别未知",
IsDeleted = false,
};
entities.Add(dictInfo3);
DictionaryEntity dictInfo4 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "显示",
DictValue = "true",
DictType = "sys_show_hide",
OrderNum = 100,
Remark = "显示菜单",
IsDeleted = false,
};
entities.Add(dictInfo4);
DictionaryEntity dictInfo5 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "隐藏",
DictValue = "false",
DictType = "sys_show_hide",
OrderNum = 99,
Remark = "隐藏菜单",
IsDeleted = false,
};
entities.Add(dictInfo5);
DictionaryEntity dictInfo6 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "正常",
DictValue = "true",
DictType = "sys_normal_disable",
OrderNum = 100,
Remark = "正常状态",
IsDeleted = false,
};
entities.Add(dictInfo6);
DictionaryEntity dictInfo7 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "停用",
DictValue = "false",
DictType = "sys_normal_disable",
OrderNum = 99,
Remark = "停用状态",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo7);
DictionaryEntity dictInfo8 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "正常",
DictValue = "0",
DictType = "sys_job_status",
OrderNum = 100,
Remark = "正常状态",
IsDeleted = false,
};
entities.Add(dictInfo8);
DictionaryEntity dictInfo9 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "暂停",
DictValue = "1",
DictType = "sys_job_status",
OrderNum = 99,
Remark = "停用状态",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo9);
DictionaryEntity dictInfo10 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "默认",
DictValue = "DEFAULT",
DictType = "sys_job_group",
OrderNum = 100,
Remark = "默认分组",
IsDeleted = false,
};
entities.Add(dictInfo10);
DictionaryEntity dictInfo11 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "系统",
DictValue = "SYSTEM",
DictType = "sys_job_group",
OrderNum = 99,
Remark = "系统分组",
IsDeleted = false,
};
entities.Add(dictInfo11);
DictionaryEntity dictInfo12 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "是",
DictValue = "Y",
DictType = "sys_yes_no",
OrderNum = 100,
Remark = "系统默认是",
IsDeleted = false,
};
entities.Add(dictInfo12);
DictionaryEntity dictInfo13 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "否",
DictValue = "N",
DictType = "sys_yes_no",
OrderNum = 99,
Remark = "系统默认否",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo13);
DictionaryEntity dictInfo14 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "通知",
DictValue = "1",
DictType = "sys_notice_type",
OrderNum = 100,
Remark = "通知",
IsDeleted = false,
};
entities.Add(dictInfo14);
DictionaryEntity dictInfo15 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "公告",
DictValue = "2",
DictType = "sys_notice_type",
OrderNum = 99,
Remark = "公告",
IsDeleted = false,
};
entities.Add(dictInfo15);
DictionaryEntity dictInfo16 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "正常",
DictValue = "0",
DictType = "sys_notice_status",
OrderNum = 100,
Remark = "正常状态",
IsDeleted = false,
};
entities.Add(dictInfo16);
DictionaryEntity dictInfo17 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "关闭",
DictValue = "1",
DictType = "sys_notice_status",
OrderNum = 99,
Remark = "关闭状态",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo17);
DictionaryEntity dictInfo18 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "新增",
DictValue = "1",
DictType = "sys_oper_type",
OrderNum = 100,
Remark = "新增操作",
IsDeleted = false,
};
entities.Add(dictInfo18);
DictionaryEntity dictInfo19 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "修改",
DictValue = "2",
DictType = "sys_oper_type",
OrderNum = 99,
Remark = "修改操作",
IsDeleted = false,
};
entities.Add(dictInfo19);
DictionaryEntity dictInfo22 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "删除",
DictValue = "3",
DictType = "sys_oper_type",
OrderNum = 98,
Remark = "删除操作",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo22);
DictionaryEntity dictInfo23 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "授权",
DictValue = "4",
DictType = "sys_oper_type",
OrderNum = 97,
Remark = "授权操作",
IsDeleted = false,
};
entities.Add(dictInfo23);
DictionaryEntity dictInfo24 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "导出",
DictValue = "5",
DictType = "sys_oper_type",
OrderNum = 96,
Remark = "导出操作",
IsDeleted = false,
};
entities.Add(dictInfo24);
DictionaryEntity dictInfo25 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "导入",
DictValue = "6",
DictType = "sys_oper_type",
OrderNum = 95,
Remark = "导入操作",
IsDeleted = false,
};
entities.Add(dictInfo25);
DictionaryEntity dictInfo26 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "强退",
DictValue = "7",
DictType = "sys_oper_type",
OrderNum = 94,
Remark = "强退操作",
IsDeleted = false,
};
entities.Add(dictInfo26);
DictionaryEntity dictInfo27 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "生成代码",
DictValue = "8",
DictType = "sys_oper_type",
OrderNum = 93,
Remark = "生成代码操作",
IsDeleted = false,
};
entities.Add(dictInfo27);
DictionaryEntity dictInfo28 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "清空数据",
DictValue = "9",
DictType = "sys_oper_type",
OrderNum = 92,
Remark = "清空数据操作",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo28);
DictionaryEntity dictInfo20 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "成功",
DictValue = "false",
DictType = "sys_common_status",
OrderNum = 100,
Remark = "正常状态",
IsDeleted = false,
};
entities.Add(dictInfo20);
DictionaryEntity dictInfo21 = new DictionaryEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictLabel = "失败",
DictValue = "true",
DictType = "sys_common_status",
OrderNum = 99,
Remark = "失败状态",
IsDeleted = false,
ListClass = "danger"
};
entities.Add(dictInfo21);
return entities;
}
}
}

View File

@@ -0,0 +1,129 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Module.DictionaryManager.Entities;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
public class DictionaryTypeDataSeed : AbstractDataSeed<DictionaryTypeEntity>, ITransient
{
public DictionaryTypeDataSeed(IRepository<DictionaryTypeEntity> repository) : base(repository)
{
}
public override List<DictionaryTypeEntity> GetSeedData()
{
List<DictionaryTypeEntity> entities = new List<DictionaryTypeEntity>();
DictionaryTypeEntity dict1 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "用户性别",
DictType = "sys_user_sex",
OrderNum = 100,
Remark = "用户性别列表",
IsDeleted = false,
};
entities.Add(dict1);
DictionaryTypeEntity dict2 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "菜单状态",
DictType = "sys_show_hide",
OrderNum = 100,
Remark = "菜单状态列表",
IsDeleted = false,
};
entities.Add(dict2);
DictionaryTypeEntity dict3 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "系统开关",
DictType = "sys_normal_disable",
OrderNum = 100,
Remark = "系统开关列表",
IsDeleted = false,
};
entities.Add(dict3);
DictionaryTypeEntity dict4 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "任务状态",
DictType = "sys_job_status",
OrderNum = 100,
Remark = "任务状态列表",
IsDeleted = false,
};
entities.Add(dict4);
DictionaryTypeEntity dict5 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "任务分组",
DictType = "sys_job_group",
OrderNum = 100,
Remark = "任务分组列表",
IsDeleted = false,
};
entities.Add(dict5);
DictionaryTypeEntity dict6 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "系统是否",
DictType = "sys_yes_no",
OrderNum = 100,
Remark = "系统是否列表",
IsDeleted = false,
};
entities.Add(dict6);
DictionaryTypeEntity dict7 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "通知类型",
DictType = "sys_notice_type",
OrderNum = 100,
Remark = "通知类型列表",
IsDeleted = false,
};
entities.Add(dict7);
DictionaryTypeEntity dict8 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "通知状态",
DictType = "sys_notice_status",
OrderNum = 100,
Remark = "通知状态列表",
IsDeleted = false,
};
entities.Add(dict8);
DictionaryTypeEntity dict9 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "操作类型",
DictType = "sys_oper_type",
OrderNum = 100,
Remark = "操作类型列表",
IsDeleted = false,
};
entities.Add(dict9);
DictionaryTypeEntity dict10 = new DictionaryTypeEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
DictName = "系统状态",
DictType = "sys_common_status",
OrderNum = 100,
Remark = "登录状态列表",
IsDeleted = false,
};
entities.Add(dict10);
return entities;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,63 @@
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Helper;
using Yi.Furion.Core.Rbac.Entities;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
public class PostDataSeed : AbstractDataSeed<PostEntity>, ITransient
{
public PostDataSeed(IRepository<PostEntity> repository) : base(repository)
{
}
public override List<PostEntity> GetSeedData()
{
var entites = new List<PostEntity>();
PostEntity Post1 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "董事长",
PostCode = "ceo",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post1);
PostEntity Post2 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "项目经理",
PostCode = "se",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post2);
PostEntity Post3 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "人力资源",
PostCode = "hr",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post3);
PostEntity Post4 = new PostEntity()
{
Id = SnowflakeHelper.NextId,
PostName = "普通员工",
PostCode = "user",
OrderNum = 100,
IsDeleted = false
};
entites.Add(Post4);
return entites;
}
}
}

View File

@@ -0,0 +1,70 @@
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Helper;
using Yi.Furion.Core.Rbac.Entities;
using Yi.Furion.Core.Rbac.Enums;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
public class RoleDataSeed : AbstractDataSeed<RoleEntity>, ITransient
{
public RoleDataSeed(IRepository<RoleEntity> repository) : base(repository)
{
}
public override List<RoleEntity> GetSeedData()
{
var entities = new List<RoleEntity>();
RoleEntity role1 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "管理员",
RoleCode = "admin",
DataScope = DataScopeEnum.ALL,
OrderNum = 999,
Remark = "管理员",
IsDeleted = false
};
entities.Add(role1);
RoleEntity role2 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "测试角色",
RoleCode = "test",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "测试用的角色",
IsDeleted = false
};
entities.Add(role2);
RoleEntity role3 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "普通用户",
RoleCode = "common",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "正常用户",
IsDeleted = false
};
entities.Add(role3);
RoleEntity role4 = new RoleEntity()
{
Id = SnowflakeHelper.NextId,
RoleName = "游客用户",
RoleCode = "guest",
DataScope = DataScopeEnum.ALL,
OrderNum = 1,
Remark = "可简单浏览",
IsDeleted = false
};
entities.Add(role4);
return entities;
}
}
}

View File

@@ -0,0 +1,88 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.DataSeeds;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Furion.Core.Rbac.Entities;
using Yi.Furion.Core.Rbac.Enums;
namespace Yi.Furion.Core.Rbac.DataSeeds
{
////支持依赖注入执行
//[AppService(typeof(IDataSeed<UserEntity>))]
////支持启动时执行
//[AppService(typeof(IDataSeed))]
public class UserDataSeed : AbstractDataSeed<UserEntity>,ITransient
{
public UserDataSeed(IRepository<UserEntity> repository) : base(repository)
{
}
public override List<UserEntity> GetSeedData()
{
var entities = new List<UserEntity>();
UserEntity user1 = new UserEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
Name = "大橙子",
UserName = "cc",
Nick = "橙子",
Password = "123456",
Email = "454313500@qq.com",
Phone = 13800000000,
Sex = SexEnum.Male,
Address = "深圳",
Age = 20,
Introduction = "还有谁?",
OrderNum = 999,
Remark = "描述是什么呢?",
State = true
};
user1.BuildPassword();
entities.Add(user1);
UserEntity user2 = new UserEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
Name = "大测试",
UserName = "test",
Nick = "测试",
Password = "123456",
Email = "454313500@qq.com",
Phone = 15900000000,
Sex = SexEnum.Woman,
Address = "深圳",
Age = 18,
Introduction = "还有我!",
OrderNum = 1,
Remark = "我没有描述!",
State = true
};
user2.BuildPassword();
entities.Add(user2);
UserEntity user3 = new UserEntity()
{
Id = SnowFlakeSingle.Instance.NextId(),
Name = "游客",
UserName = "guest",
Nick = "测试",
Password = "123456",
Email = "454313500@qq.com",
Phone = 15900000000,
Sex = SexEnum.Woman,
Address = "深圳",
Age = 18,
Introduction = "临时游客",
OrderNum = 1,
Remark = "懒得创账号",
State = true
};
user3.BuildPassword();
entities.Add(user3);
return entities;
}
}
}

View File

@@ -22,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Infrastructure\Yi.Framework.Infrastructure.csproj" />
<ProjectReference Include="..\Yi.Framework.Module\Yi.Framework.Module.csproj" />
</ItemGroup>