Update Tdengine

This commit is contained in:
sunkaixuan 2025-02-26 16:20:00 +08:00
parent 88eb91b717
commit df8f15aead

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
@ -39,6 +40,31 @@ namespace SqlSugar
return inserObjects.Count();
}
public async Task<int> ExecuteCommandAsync()
{
var provider = (InsertableProvider<T>)thisValue;
var inserObjects = provider.InsertObjs;
var attr = typeof(T).GetCustomAttribute<STableAttribute>();
Check.ExceptionEasy(attr == null || attr?.Tag1 == null, $"", $"{nameof(T)}缺少特性STableAttribute和Tag1");
// 根据所有非空的 Tag 进行分组
var groups = GetGroupInfos(inserObjects, attr);
foreach (var item in groups)
{
var childTableName = getChildTableNamefunc(attr.STableName, item.First());
await this.Context.Utilities.PageEachAsync(item, 500, async pageItems =>
{
var sTableName = provider.SqlBuilder.GetTranslationColumnName(attr.STableName);
var tags = new List<string>();
List<string> tagValues = GetTagValues(pageItems, attr);
var tagString = string.Join(",", tagValues.Where(v => !string.IsNullOrEmpty(v)).Select(v => $"'{v.ToSqlFilter()}'"));
tags.Add(tagString);
await this.Context.Ado.ExecuteCommandAsync($"CREATE TABLE IF NOT EXISTS {childTableName} USING {sTableName} TAGS ({tagString})");
await this.Context.Insertable(pageItems).AS(childTableName).ExecuteCommandAsync();
});
}
return inserObjects.Count();
}
private static List<string> GetTagValues(List<T> pageItems, STableAttribute attr)
{
var tagValues = new List<string>();