184 lines
7.2 KiB
C#
184 lines
7.2 KiB
C#
namespace CloudGaming.Api.Admin.ApplicationServices.DevelopmentTools.LowCode.Impl;
|
|
|
|
/// <summary>
|
|
/// 服务 Low_Code_Table_InfoService
|
|
/// </summary>
|
|
public class LowCodeTableInfoService(
|
|
IServiceProvider serviceProvider,
|
|
IDatabaseTableService databaseTableService,
|
|
IRepository<LowCodeTable> lowCodeTableRepository)
|
|
: ApplicationService<LowCodeTableInfo, Guid, LowCodeTableInfo, LowCodeTableInfo>(serviceProvider)
|
|
{
|
|
/// <summary>
|
|
/// 获取列表数据
|
|
/// </summary>
|
|
/// <param name="pagingSearchInput"></param>
|
|
/// <returns></returns>
|
|
public override async Task<PagingView> FindListAsync(PagingSearchInput<LowCodeTableInfo> pagingSearchInput)
|
|
{
|
|
var query = Repository.SelectNoTracking
|
|
.WhereIf(pagingSearchInput.Search.Low_Code_TableId != Guid.Empty,
|
|
w => w.Low_Code_TableId == pagingSearchInput.Search.Low_Code_TableId)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.ColumnName),
|
|
w => w.ColumnName.Contains(pagingSearchInput.Search.ColumnName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search.Describe),
|
|
w => w.Describe.Contains(pagingSearchInput.Search.Describe))
|
|
.OrderBy(w => w.Position)
|
|
.ThenByDescending(w => w.CreationTime)
|
|
.Select(w => new
|
|
{
|
|
w.Id,
|
|
w.IsPrimary,
|
|
w.IsIdentity,
|
|
w.IsNullable,
|
|
w.Position,
|
|
w.ColumnName,
|
|
w.Describe,
|
|
w.DatabaseColumnType,
|
|
w.CsType,
|
|
w.CsField,
|
|
w.DisplayName,
|
|
w.Low_Code_TableId,
|
|
w.LastModificationTime,
|
|
w.CreationTime,
|
|
IsTableColumnShow = w.IsTableColumnShow ?? true,
|
|
w.IsTableSelect,
|
|
w.IsImageId,
|
|
OrderById = w.OrderById,
|
|
w.Width
|
|
})
|
|
;
|
|
|
|
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 Task DeleteListAsync(List<Guid> ids)
|
|
{
|
|
databaseTableService.ClearAllTablesByCache();
|
|
return Repository.DeleteByIdsAsync(ids);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据表名同步列数据
|
|
/// </summary>
|
|
/// <param name="tableId"></param>
|
|
/// <param name="isTableSync">是否来自表格同步</param>
|
|
/// <returns></returns>
|
|
public async Task SynchronizationColumnByTableIdAsync(Guid tableId, bool isTableSync = false)
|
|
{
|
|
var allTables = databaseTableService.GetAllTableInfos();
|
|
var table = await lowCodeTableRepository.FindAsync(w => w.Id == tableId);
|
|
var tableInfo = allTables.Find(w => w.Name == table.TableName);
|
|
|
|
//查询出当前表所有的字段
|
|
var tableColumns = await Repository.ToListAsync(w => w.Low_Code_TableId == table.Id);
|
|
|
|
//操作集合
|
|
var list = new List<LowCodeTableInfo>();
|
|
|
|
if (isTableSync)
|
|
{
|
|
if (tableColumns != null && tableColumns.Count == 0)
|
|
{
|
|
foreach (var item in tableInfo.Columns)
|
|
{
|
|
// if (tableColumns.Any(w => w.ColumnName == item.Name)) continue;
|
|
|
|
var model = new LowCodeTableInfo();
|
|
model.IsPrimary = item.IsPrimary;
|
|
model.IsIdentity = item.IsIdentity;
|
|
model.IsNullable = item.IsNullable;
|
|
model.Position = item.Position;
|
|
model.Low_Code_TableId = table.Id;
|
|
model.ColumnName = item.Name;
|
|
model.DatabaseColumnType = item.DbTypeTextFull;
|
|
model.CsType = item.CsType.Name;
|
|
model.CsField = item.Name;
|
|
model.MaxLength = item.MaxLength;
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.Comment))
|
|
{
|
|
model.Describe = item.Comment;
|
|
model.DisplayName = item.Comment;
|
|
}
|
|
var oldColumns = tableColumns.FirstOrDefault(w => w.ColumnName == item.Name);
|
|
if (oldColumns != null)
|
|
{
|
|
model.OrderById = oldColumns.OrderById;
|
|
model.Describe = oldColumns.Describe;
|
|
model.IsImageId = oldColumns.IsImageId;
|
|
model.IsTableColumnShow = oldColumns.IsTableColumnShow;
|
|
model.IsTableSelect = oldColumns.IsTableSelect;
|
|
model.Width = oldColumns.Width;
|
|
};
|
|
list.Add(model);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
await Repository.DeleteAsync(w => w.Low_Code_TableId == table.Id);
|
|
|
|
foreach (var item in tableInfo.Columns)
|
|
{
|
|
// if (tableColumns.Any(w => w.ColumnName == item.Name)) continue;
|
|
|
|
var model = new LowCodeTableInfo();
|
|
model.IsPrimary = item.IsPrimary;
|
|
model.IsIdentity = item.IsIdentity;
|
|
model.IsNullable = item.IsNullable;
|
|
model.Position = item.Position;
|
|
model.Low_Code_TableId = table.Id;
|
|
model.ColumnName = item.Name;
|
|
model.DatabaseColumnType = item.DbTypeTextFull;
|
|
model.CsType = item.CsType.Name;
|
|
model.CsField = item.Name;
|
|
model.MaxLength = item.MaxLength;
|
|
if (!string.IsNullOrWhiteSpace(item.Comment))
|
|
{
|
|
model.Describe = item.Comment;
|
|
model.DisplayName = item.Comment;
|
|
}
|
|
var oldColumns = tableColumns.FirstOrDefault(w => w.ColumnName == item.Name);
|
|
if (oldColumns != null)
|
|
{
|
|
model.OrderById = oldColumns.OrderById;
|
|
model.Describe = oldColumns.Describe;
|
|
model.IsImageId = oldColumns.IsImageId;
|
|
model.IsTableColumnShow = oldColumns.IsTableColumnShow;
|
|
model.IsTableSelect = oldColumns.IsTableSelect;
|
|
model.Width = oldColumns.Width;
|
|
};
|
|
list.Add(model);
|
|
}
|
|
}
|
|
|
|
await Repository.InsertRangeAsync(list);
|
|
|
|
databaseTableService.ClearAllTablesByCache();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变更数据
|
|
/// </summary>
|
|
/// <param name="lowCodeTableInfos"></param>
|
|
/// <returns></returns>
|
|
public Task ChangeAsync(List<LowCodeTableInfo> lowCodeTableInfos)
|
|
{
|
|
databaseTableService.ClearAllTablesByCache();
|
|
return Repository.UpdateRangeAsync(lowCodeTableInfos);
|
|
}
|
|
} |