121 lines
4.0 KiB
C#
121 lines
4.0 KiB
C#
|
|
|
|
|
|
|
|
|
|
|
|
namespace CloudGaming.Api.Admin.ApplicationServices.DevelopmentTools.LowCode.Impl;
|
|
|
|
/// <summary>
|
|
/// 数据库表服务
|
|
/// </summary>
|
|
public class DatabaseTableService : IDatabaseTableService
|
|
{
|
|
private readonly string TableInfoKey = "TableInfo:GenDbTableDto";
|
|
private readonly int CacheTime = 12;
|
|
|
|
private readonly IMemoryCache _memoryCache;
|
|
private readonly IRepository<LowCodeTable> _lowCodeTableRepository;
|
|
private readonly IRepository<LowCodeTableInfo> _lowCodeTableInfoRepository;
|
|
private readonly UserDbContext _userDbContext;
|
|
private readonly GameDbContext _gameDbContext;
|
|
private readonly PhoneDbContext _phoneDbContext;
|
|
private readonly ExtDbContext _extDbContext;
|
|
//private readonly GameDbContext _gameDbContext;
|
|
//private readonly ExtDbContext _extDbContext;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="memoryCache"></param>
|
|
/// <param name="lowCodeTableRepository"></param>
|
|
/// <param name="lowCodeTableInfoRepository"></param>
|
|
/// <param name="userDbContext"></param>
|
|
/// <param name="gameDbContext"></param>
|
|
/// <param name="phoneDbContext"></param>
|
|
/// <param name="extDbContext"></param>
|
|
public DatabaseTableService(
|
|
IMemoryCache memoryCache,
|
|
IRepository<LowCodeTable> lowCodeTableRepository,
|
|
IRepository<LowCodeTableInfo> lowCodeTableInfoRepository,
|
|
UserDbContext userDbContext
|
|
, GameDbContext gameDbContext
|
|
, PhoneDbContext phoneDbContext
|
|
, ExtDbContext extDbContext
|
|
)
|
|
{
|
|
_memoryCache = memoryCache;
|
|
_lowCodeTableRepository = lowCodeTableRepository;
|
|
_lowCodeTableInfoRepository = lowCodeTableInfoRepository;
|
|
_userDbContext = userDbContext;
|
|
_gameDbContext = gameDbContext;
|
|
_phoneDbContext = phoneDbContext;
|
|
_extDbContext = extDbContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有的表 包含表下面的列
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual List<DbTableInfo> GetAllTableInfos()
|
|
{
|
|
var list = _lowCodeTableRepository.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase();
|
|
//var userList = _userDbContext.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase(); ;
|
|
var userList = _userDbContext.GetDbTableInfo();
|
|
var gameList = _gameDbContext.GetDbTableInfo();
|
|
var appList = _phoneDbContext.GetDbTableInfo();
|
|
var extList = _extDbContext.GetDbTableInfo();
|
|
list.AddRange(userList);
|
|
list.AddRange(gameList);
|
|
list.AddRange(appList);
|
|
list.AddRange(extList);
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
/// 获取所有的表 包含表下面的列
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual List<GenDbTableDto> GetAllTables()
|
|
{
|
|
var tables = _lowCodeTableRepository.ToListAll();
|
|
//_userDbContext.UnitOfWork.
|
|
var tableColumns = _lowCodeTableInfoRepository.ToListAll();
|
|
|
|
var result = new List<GenDbTableDto>();
|
|
foreach (var item in tables)
|
|
{
|
|
var table = item.MapTo<LowCodeTable, GenDbTableDto>();
|
|
table.TableInfos = tableColumns.Where(w => w.Low_Code_TableId == item.Id).ToList();
|
|
result.Add(table);
|
|
}
|
|
|
|
_memoryCache.Set(TableInfoKey, result, DateTime.Now.AddHours(CacheTime));
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取表信息根据缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<GenDbTableDto> GetAllTablesByCache() => _memoryCache.Get<List<GenDbTableDto>>(TableInfoKey) ?? GetAllTables();
|
|
|
|
/// <summary>
|
|
/// 清空所有表缓存信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ClearAllTablesByCache()
|
|
{
|
|
_memoryCache.Remove(TableInfoKey);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取数据库名称
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string? GetDatabaseName() => _lowCodeTableRepository.GetContext()?.Database.GetDbConnection().Database;
|
|
|
|
|
|
}
|