HuanMengAdmin/admin-server/MiaoYu.Repository.ChatAI.Admin/Providers/MiaoYuChatDataSourceProvider.cs
zpc 9183ee09c0 Revert "基础项目"
This reverts commit 5bef68f4aa.
2025-11-11 23:15:34 +08:00

79 lines
3.1 KiB
C#

namespace MiaoYu.Repository.ChatAI.Admin.Providers;
/// <summary>
/// MiaoYuChat 数据源提供者
/// </summary>
[Component]
public class MiaoYuChatDataSourceProvider : IDataSourceProvider, IScopedDependency
{
private readonly IRepository<M_Songs> _repository;
public MiaoYuChatDataSourceProvider(IRepository<M_Songs> repository)
{
_repository = repository;
}
public DataSourceConfig Config => new DataSourceConfig
{
DatabaseKey = DataSourceConstants.MiaoYuChat,
DisplayName = "妙语聊天",
EntityNamespace = typeof(ChatAdminRepositoryStartup).Namespace!,
ServiceNamespace = "MiaoYu.Api.Admin.ApplicationServices.Apps",
ControllerNamespace = "MiaoYu.Api.Admin.Controllers.Apps",
ClientServiceNamespace = "",
ModelPathTemplate = "{RootPath}\\{Namespace}\\Entities\\Apps\\{EntityNamePlural}",
ServicePathTemplate = "{AppPath}\\ApplicationServices\\Apps\\ChatAI\\{EntityNamePlural}",
ControllerPathTemplate = "{AppPath}\\Controllers\\Apps\\ChatAI\\{EntityNamePlural}",
ClientIndexPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\chatai\\{TableNameLower}s",
ClientInfoPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\chatai\\{TableNameLower}s",
ClientServicePathTemplate = "{RootPath}\\admin-client\\src\\services\\apps\\chatai\\{TableNameLower}s",
MenuPathTemplate = "views/apps/chatai/{TableNameLower}s/Index.vue",
RouterPathTemplate = "/apps/chatai/{TableNameLower}s",
TemplatePath = "/wwwroot/code_generation/template/",
NamingStrategy = EntityNamingStrategy.ToPascalCase,
Order = 2,
EnableEntityPrefix = false,
EntityPrefix = "",
UsesPluralPath = true
};
public List<CoreDbTableInfo> GetTables()
{
var freeSqlTables = _repository.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase();
return ConvertToDbTableInfoList(freeSqlTables);
}
public object GetDbContext() => _repository.GetContext()!;
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;
}
}