using System; using System.IO; using System.Threading.Tasks; using System.Collections.Generic; using Sozsoft.Platform.Entities; using Microsoft.Extensions.Configuration; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; namespace Sozsoft.Platform.Data.Seeds; public class RouteSeedDto { public string Key { get; set; } public string Path { get; set; } public string ComponentPath { get; set; } public string RouteType { get; set; } public string[] Authority { get; set; } } public class MenuSeederDto { public List Routes { get; set; } public List Menus { get; set; } } public class MenuDataSeeder : IDataSeedContributor, ITransientDependency { private readonly IRepository _routeRepository; private readonly IRepository _menuRepository; public MenuDataSeeder( IRepository routeRepository, IRepository menuRepository ) { _routeRepository = routeRepository; _menuRepository = menuRepository; } public async Task SeedAsync(DataSeedContext context) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(Path.Combine("Seeds", "MenusData.json")) .Build(); var items = configuration.Get(); foreach (var item in items.Routes) { var exists = await _routeRepository.AnyAsync(x => x.Key == item.Key); if (!exists) { await _routeRepository.InsertAsync(new Route( item.Key, item.Path, item.ComponentPath, item.RouteType, item.Authority ?? [] )); } } foreach (var item in items.Menus) { var exists = await _menuRepository.AnyAsync(x => x.Code == item.Code); if (!exists) { await _menuRepository.InsertAsync(new Menu { ParentCode = string.IsNullOrWhiteSpace(item.ParentCode) ? null : item.ParentCode, Code = item.Code, DisplayName = item.DisplayName, Order = item.Order, Url = item.Url, Icon = item.Icon, RequiredPermissionName = item.RequiredPermissionName, IsDisabled = item.IsDisabled, ShortName = item.ShortName }); } } } }