189 lines
6.6 KiB
C#
189 lines
6.6 KiB
C#
using CloudGaming.Repository.Admin.Entities.LowCode;
|
|
|
|
namespace CloudGaming.Api.Admin.ApplicationServices.DevelopmentTools.LowCode.Impl;
|
|
|
|
/// <summary>
|
|
/// 服务 Low_Code_TableService
|
|
/// </summary>
|
|
public class LowCodeTableService(
|
|
IServiceProvider serviceProvider,
|
|
LowCodeTableInfoService lowCodeTableInfoService,
|
|
IRepository<LowCodeTableInfo> lowCodeTableInfoRepository,
|
|
IDatabaseTableService databaseTableService,
|
|
ICodeGenerationService codeGenerationService)
|
|
: ApplicationService<LowCodeTable, Guid, LowCodeTable, LowCodeTable>(serviceProvider)
|
|
{
|
|
/// <summary>
|
|
/// 获取列表数据
|
|
/// </summary>
|
|
/// <param name="pagingSearchInput"></param>
|
|
/// <returns></returns>
|
|
public override async Task<PagingView> FindListAsync(PagingSearchInput<LowCodeTable> pagingSearchInput)
|
|
{
|
|
var query = Repository.SelectNoTracking
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.TableName),
|
|
w => w.TableName.Contains(pagingSearchInput.Search.TableName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.EntityName),
|
|
w => w.EntityName.Contains(pagingSearchInput.Search.EntityName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.DataBase),
|
|
w => w.DataBase.Contains(pagingSearchInput.Search.DataBase))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.DisplayName),
|
|
w => w.DisplayName.Contains(pagingSearchInput.Search.DisplayName))
|
|
.OrderByDescending(w => w.CreationTime)
|
|
.ThenByDescending(w => w.LastModificationTime)
|
|
.Select(w => new
|
|
{
|
|
w.Id,
|
|
w.TableName,
|
|
w.DisplayName,
|
|
w.EntityName,
|
|
w.Remark,
|
|
w.LastModificationTime,
|
|
w.CreationTime,
|
|
})
|
|
;
|
|
|
|
//获取一下数据用于缓存
|
|
databaseTableService.GetAllTables();
|
|
|
|
var result = await Repository.AsPagingViewAsync(query, pagingSearchInput);
|
|
//覆盖值
|
|
result
|
|
.FormatValue(query, w => w.CreationTime, (oldValue) => oldValue.ToString("yyyy-MM-dd"))
|
|
.FormatValue(query, w => w.LastModificationTime, (oldValue) => oldValue?.ToString("yyyy-MM-dd"))
|
|
;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id数组删除
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
public override async Task DeleteListAsync(List<Guid> ids)
|
|
{
|
|
databaseTableService.ClearAllTablesByCache();
|
|
//删除子表
|
|
//await this._lowCodeTableInfoRepository.DeleteBulkAsync(w => ids.Contains(w.Low_Code_TableId));
|
|
await lowCodeTableInfoRepository.DeleteAsync(w => ids.Contains(w.Low_Code_TableId));
|
|
//删除主表
|
|
await Repository.DeleteByIdsAsync(ids);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询表单数据
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public override async Task<Dictionary<string, object?>> FindFormAsync(Guid id)
|
|
{
|
|
var res = new Dictionary<string, object?>();
|
|
var form = (await Repository.FindByIdAsync(id)).NullSafe();
|
|
|
|
codeGenerationService.FillPathByLowCodeTable(form);
|
|
|
|
res[nameof(id)] = id == Guid.Empty ? "" : id;
|
|
res[nameof(form)] = form;
|
|
res["menu"] = $"views/Apps/{form.DataBase}/{form.TableName}s/Index.vue";
|
|
res["router"] = $"/apps/{form.DataBase.ToLower()}/{form.TableName.ToLower()}s";
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步表
|
|
/// </summary>
|
|
public async Task SynchronizationAsync()
|
|
{
|
|
var allTables = databaseTableService.GetAllTableInfos();
|
|
var oldAllTables = await Repository.ToListAllAsync();
|
|
|
|
#region 同步表
|
|
|
|
var insertList = new List<LowCodeTable>();
|
|
var updateList = new List<LowCodeTable>();
|
|
var ids = new List<Guid>();
|
|
foreach (var item in allTables)
|
|
{
|
|
var table = oldAllTables.Find(w => w.TableName == item.Name);
|
|
var id = Guid.NewGuid();
|
|
if (table == null)
|
|
{
|
|
var lowCodeTable = new LowCodeTable
|
|
{
|
|
Id = id,
|
|
DisplayName = item.Comment,
|
|
TableName = item.Name,
|
|
EntityName = item.Name.ToLineConvertHump(),
|
|
Schema = item.Schema,
|
|
DataBase = "Admin"
|
|
};
|
|
if (AppConfigExtend.IsAppDataBase(item.Schema))
|
|
{
|
|
lowCodeTable.EntityName = item.Name;
|
|
lowCodeTable.DataBase = item.Schema;
|
|
}
|
|
insertList.Add(lowCodeTable);
|
|
}
|
|
else
|
|
{
|
|
id = table.Id;
|
|
if (AppConfigExtend.IsAppDataBase(item.Schema))
|
|
{
|
|
table.EntityName = item.Name;
|
|
table.DataBase = item.Schema;
|
|
}
|
|
else
|
|
{
|
|
table.DataBase = "Admin";
|
|
}
|
|
table.Schema = item.Schema;
|
|
updateList.Add(table);
|
|
}
|
|
|
|
ids.Add(id);
|
|
}
|
|
|
|
if (insertList.Count > 0)
|
|
{
|
|
await Repository.InsertRangeAsync(insertList);
|
|
}
|
|
|
|
if (updateList.Count > 0)
|
|
{
|
|
await Repository.UpdateRangeAsync(updateList);
|
|
}
|
|
|
|
foreach (var item in ids)
|
|
{
|
|
await lowCodeTableInfoService.SynchronizationColumnByTableIdAsync(item, true);
|
|
}
|
|
|
|
databaseTableService.ClearAllTablesByCache();
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变更数据
|
|
/// </summary>
|
|
/// <param name="lowCodeTables"></param>
|
|
/// <returns></returns>
|
|
public async Task ChangeAsync(List<LowCodeTable> lowCodeTables)
|
|
{
|
|
databaseTableService.ClearAllTablesByCache();
|
|
var oldLowCodeTables =
|
|
await Repository.ToListAsync(w => lowCodeTables.Select(w => w.Id).Contains(w.Id));
|
|
var updateList = new List<LowCodeTable>();
|
|
foreach (var item in lowCodeTables)
|
|
{
|
|
var lowCodeTable = oldLowCodeTables.Find(w => w.Id == item.Id);
|
|
lowCodeTable.DisplayName = item.DisplayName;
|
|
lowCodeTable.EntityName = item.EntityName;
|
|
lowCodeTable.Remark = item.Remark;
|
|
updateList.Add(lowCodeTable);
|
|
}
|
|
|
|
await Repository.UpdateRangeAsync(updateList);
|
|
}
|
|
} |