namespace MiaoYu.Repository.Admin.Providers; /// /// Admin 数据源提供者 /// [Component] public class AdminDataSourceProvider : IDataSourceProvider, IScopedDependency { private readonly IRepository _repository; public AdminDataSourceProvider(IRepository repository) { _repository = repository; } public DataSourceConfig Config => new DataSourceConfig { DatabaseKey = DataSourceConstants.Admin, DisplayName = "后台管理系统", EntityNamespace = typeof(AdminRepositoryStartup).Namespace!, ServiceNamespace = "MiaoYu.Api.Admin.ApplicationServices.Apps", ControllerNamespace = "MiaoYu.Api.Admin.Controllers.Apps", ClientServiceNamespace = "", ModelPathTemplate = "{RootPath}\\{Namespace}\\Entities\\Apps\\{EntityNamePlural}", ServicePathTemplate = "{AppPath}\\ApplicationServices\\Apps\\{EntityNamePlural}", ControllerPathTemplate = "{AppPath}\\Controllers\\Apps\\{EntityNamePlural}", ClientIndexPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\{TableNameLower}s", ClientInfoPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\{TableNameLower}s", ClientServicePathTemplate = "{RootPath}\\admin-client\\src\\services\\apps\\{TableNameLower}s", MenuPathTemplate = "views/apps/{TableNameLower}s/Index.vue", RouterPathTemplate = "/apps/{TableNameLower}s", TemplatePath = "/wwwroot/code_generation/template/", NamingStrategy = EntityNamingStrategy.ToPascalCase, Order = 1, EnableEntityPrefix = false, EntityPrefix = "", UsesPluralPath = true }; public List GetTables() { var freeSqlTables = _repository.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase(); return ConvertToDbTableInfoList(freeSqlTables); } public object GetDbContext() => _repository.GetContext()!; private List ConvertToDbTableInfoList(List freeSqlTables) { var result = new List(); foreach (var table in freeSqlTables) { var dbTableInfo = new CoreDbTableInfo { DataBase = Config.DatabaseKey, Schema = table.Schema, Name = table.Name, Type = table.Type.ToString(), Comment = table.Comment, Columns = table.Columns?.Select(c => new CoreDbColumnInfo { Name = c.Name, Comment = c.Comment, IsPrimary = c.IsPrimary, IsIdentity = c.IsIdentity, IsNullable = c.IsNullable, Position = c.Position, DbType = c.DbTypeTextFull, CsType = c.CsType?.Name, MaxLength = c.MaxLength }).ToList() }; result.Add(dbTableInfo); } return result; } }