feat: 添加bbs种子数据

This commit is contained in:
橙子
2023-12-14 21:55:52 +08:00
parent db11e1731b
commit 38b854ed90
11 changed files with 9040 additions and 28 deletions

View File

@@ -70,19 +70,22 @@ namespace Yi.Framework.SqlSugarCore
private void CodeFirst(IServiceProvider service)
{
var moduleContainer = service.GetRequiredService<IModuleContainer>();
var db = service.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient;
var moduleContainer = service.GetRequiredService<IModuleContainer>();
var db = service.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient;
//尝试创建数据库
db.DbMaintenance.CreateDatabase();
List<Type> types = new List<Type>();
foreach (var module in moduleContainer.Modules)
{
types.AddRange(module.Assembly.GetTypes().Where(x => x.GetCustomAttribute<SugarTable>() != null).Where(x => x.GetCustomAttribute<SplitTableAttribute>() is null));
}
if (types.Count > 0)
{
db.CodeFirst.InitTables(types.ToArray());
}
List<Type> types = new List<Type>();
foreach (var module in moduleContainer.Modules)
{
types.AddRange(module.Assembly.GetTypes().Where(x => x.GetCustomAttribute<SugarTable>() != null).Where(x => x.GetCustomAttribute<SplitTableAttribute>() is null));
}
if (types.Count > 0)
{
db.CodeFirst.InitTables(types.ToArray());
}
}
private async Task DataSeedAsync(IServiceProvider service)

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar.DistributedSystem.Snowflake;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Enums;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Bbs.SqlSugarCore.DataSeeds
{
public class BbsMenuDataSeed : IDataSeedContributor, ITransientDependency
{
private IGuidGenerator _guidGenerator;
private ISqlSugarRepository<MenuEntity, Guid> _repository;
public BbsMenuDataSeed(ISqlSugarRepository<MenuEntity,Guid> repository, IGuidGenerator guidGenerator)
{
_repository=repository;
_guidGenerator=guidGenerator;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _repository.IsAnyAsync(x => x.MenuName == "BBS"))
{
await _repository.InsertManyAsync(GetSeedData());
}
}
public List<MenuEntity> GetSeedData()
{
List<MenuEntity> entities = new List<MenuEntity>();
//BBS
MenuEntity bbs = new MenuEntity(_guidGenerator.Create())
{
MenuName = "BBS",
MenuType = MenuTypeEnum.Catalogue,
Router = "/bbs",
IsShow = true,
IsLink = false,
MenuIcon = "monitor",
OrderNum = 91,
IsDeleted = false
};
entities.Add(bbs);
//板块管理
MenuEntity plate = new MenuEntity(_guidGenerator.Create())
{
MenuName = "板块管理",
PermissionCode = "bbs:plate:list",
MenuType = MenuTypeEnum.Menu,
Router = "plate",
IsShow = true,
IsLink = false,
IsCache = true,
Component = "bbs/plate/index",
MenuIcon = "component",
OrderNum = 100,
ParentId = bbs.Id,
IsDeleted = false
};
entities.Add(plate);
//文章管理
MenuEntity article = new MenuEntity(_guidGenerator.Create())
{
MenuName = "文章管理",
PermissionCode = "bbs:article:list",
MenuType = MenuTypeEnum.Menu,
Router = "article",
IsShow = true,
IsLink = false,
IsCache = true,
Component = "bbs/article/index",
MenuIcon = "documentation",
OrderNum = 99,
ParentId = bbs.Id,
IsDeleted = false
};
entities.Add(article);
return entities;
}
}
}

View File

@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<ItemGroup>
<Compile Remove="Events\**" />
<EmbeddedResource Remove="Events\**" />
<None Remove="Events\**" />
</ItemGroup>
<ItemGroup>
@@ -15,8 +20,4 @@
<ProjectReference Include="..\Yi.Framework.Rbac.Domain\Yi.Framework.Rbac.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Events\" />
</ItemGroup>
</Project>

View File

@@ -652,7 +652,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/role/index",
MenuIcon = "peoples",
OrderNum = 100,
OrderNum = 99,
ParentId = system.Id,
IsDeleted = false
};
@@ -720,7 +720,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/menu/index",
MenuIcon = "tree-table",
OrderNum = 100,
OrderNum = 98,
ParentId = system.Id,
IsDeleted = false
};
@@ -787,7 +787,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/dept/index",
MenuIcon = "tree",
OrderNum = 100,
OrderNum = 97,
ParentId = system.Id,
IsDeleted = false
};
@@ -856,7 +856,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/post/index",
MenuIcon = "post",
OrderNum = 100,
OrderNum = 96,
ParentId = system.Id,
IsDeleted = false
};
@@ -923,7 +923,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/dict/index",
MenuIcon = "dict",
OrderNum = 100,
OrderNum = 95,
ParentId = system.Id,
IsDeleted = false
};
@@ -991,7 +991,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/config/index",
MenuIcon = "edit",
OrderNum = 100,
OrderNum = 94,
ParentId = system.Id,
IsDeleted = false
};
@@ -1058,7 +1058,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsShow = true,
IsLink = false,
MenuIcon = "log",
OrderNum = 100,
OrderNum = 93,
ParentId = system.Id,
IsDeleted = false
};

View File

@@ -73,7 +73,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.Repositories
user.Roles = new List<RoleEntity>();
userRoleMenu.User = user.Adapt<UserDto>();
userRoleMenu.Menus = userRoleMenu.Menus.OrderByDescending(x => x.OrderNum).ToHashSet();
return userRoleMenu;
}
}

File diff suppressed because one or more lines are too long