76 lines
2.9 KiB
C#
76 lines
2.9 KiB
C#
namespace MiaoYu.Repository.LiveForum.Admin.Providers;
|
|
|
|
/// <summary>
|
|
/// LiveForum 数据源提供者
|
|
/// </summary>
|
|
[Component]
|
|
public class LiveForumDataSourceProvider : IDataSourceProvider, IScopedDependency
|
|
{
|
|
private readonly LiveForumAdminDbContext _dbContext;
|
|
|
|
public LiveForumDataSourceProvider(LiveForumAdminDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public DataSourceConfig Config => new DataSourceConfig
|
|
{
|
|
DatabaseKey = DataSourceConstants.LiveForum,
|
|
DisplayName = "直播论坛",
|
|
EntityNamespace = typeof(LiveForumAdminRepositoryStartup).Namespace!,
|
|
ModelPathTemplate = "{RootPath}\\{Namespace}\\Entities\\Apps\\{EntityNamePlural}",
|
|
ServicePathTemplate = "{AppPath}\\ApplicationServices\\Apps\\LiveForum\\{EntityNamePlural}",
|
|
ControllerPathTemplate = "{AppPath}\\Controllers\\Apps\\LiveForum\\{EntityNamePlural}",
|
|
ClientIndexPathTemplate = "{WebPath}\\admin-client\\src\\views\\apps\\liveforum\\{TableNameLower}",
|
|
ClientInfoPathTemplate = "{WebPath}\\admin-client\\src\\views\\apps\\liveforum\\{TableNameLower}",
|
|
ClientServicePathTemplate = "{WebPath}\\admin-client\\src\\services\\apps\\liveforum\\{TableNameLower}",
|
|
MenuPathTemplate = "views/apps/liveforum/{TableNameLower}/Index.vue",
|
|
RouterPathTemplate = "/apps/liveforum/{TableNameLower}",
|
|
TemplatePath = "/wwwroot/code_generation/templatev5/",
|
|
NamingStrategy = EntityNamingStrategy.KeepOriginal,
|
|
Order = 3,
|
|
EnableEntityPrefix = false,
|
|
EntityPrefix = "",
|
|
UsesPluralPath = false
|
|
};
|
|
|
|
public List<CoreDbTableInfo> GetTables()
|
|
{
|
|
var freeSqlTables = _dbContext.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase();
|
|
return ConvertToDbTableInfoList(freeSqlTables);
|
|
}
|
|
|
|
public object GetDbContext() => _dbContext;
|
|
|
|
private List<CoreDbTableInfo> ConvertToDbTableInfoList(List<FreeSql.DatabaseModel.DbTableInfo> freeSqlTables)
|
|
{
|
|
var result = new List<CoreDbTableInfo>();
|
|
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;
|
|
}
|
|
}
|
|
|