diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs index bc50ae332..8e345031a 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs @@ -59,6 +59,65 @@ namespace SqlSugar return await _ExecuteCommandAsync(); } } + + + public List ExecuteReturnSnowflakeIdList() + { + if (this.Context.Ado.Transaction == null) + { + try + { + this.Context.Ado.BeginTran(); + var result = _ExecuteReturnSnowflakeIdList(); + this.Context.Ado.CommitTran(); + return result; + } + catch (Exception ex) + { + this.Context.Ado.RollbackTran(); + throw ex; + } + } + else + { + return _ExecuteReturnSnowflakeIdList(); + } + } + public async Task> ExecuteReturnSnowflakeIdListAsync() + { + if (this.Context.Ado.Transaction == null) + { + try + { + this.Context.Ado.BeginTran(); + var result = await _ExecuteReturnSnowflakeIdListAsync(); + this.Context.Ado.BeginTran(); + return result; + } + catch (Exception ex) + { + this.Context.Ado.RollbackTran(); + throw ex; + } + } + else + { + return await _ExecuteReturnSnowflakeIdListAsync(); + } + } + + + public long ExecuteReturnSnowflakeId() + { + return ExecuteReturnSnowflakeIdList().FirstOrDefault(); + } + public async Task ExecuteReturnSnowflakeIdAsync() + { + var list = await ExecuteReturnSnowflakeIdListAsync(); + return list.FirstOrDefault(); + } + + internal int _ExecuteCommand() { CreateTable(); @@ -101,6 +160,53 @@ namespace SqlSugar } return result; } + + internal List _ExecuteReturnSnowflakeIdList() + { + CreateTable(); + var result = new List(); + var groups = TableNames.GroupBy(it => it.Key).ToList(); + var parent = ((InsertableProvider)Inserable); + var names = parent.InsertBuilder.DbColumnInfoList.GroupBy(it => it.DbColumnName).Select(i => i.Key).ToList(); + foreach (var item in groups) + { + var list = item.Select(it => it.Value as T).ToList(); + var groupInserable = (InsertableProvider)this.Context.Insertable(list); + groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString; + groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc; + groupInserable.diffModel = parent.diffModel; + groupInserable.IsEnableDiffLogEvent = parent.IsEnableDiffLogEvent; + groupInserable.InsertBuilder.IsNoInsertNull = parent.InsertBuilder.IsNoInsertNull; + groupInserable.IsOffIdentity = parent.IsOffIdentity; + var idList= groupInserable.AS(item.Key).InsertColumns(names.ToArray()).ExecuteReturnSnowflakeIdList(); + result.AddRange(idList); + } + return result; + } + internal async Task> _ExecuteReturnSnowflakeIdListAsync() + { + CreateTable(); + var result = new List(); + var groups = TableNames.GroupBy(it => it.Key).ToList(); + var parent = ((InsertableProvider)Inserable); + var names = parent.InsertBuilder.DbColumnInfoList.GroupBy(it => it.DbColumnName).Select(i => i.Key).ToList(); + foreach (var item in groups) + { + var list = item.Select(it => it.Value as T).ToList(); + var groupInserable = (InsertableProvider)this.Context.Insertable(list); + groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString; + groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc; + groupInserable.diffModel = parent.diffModel; + groupInserable.IsEnableDiffLogEvent = parent.IsEnableDiffLogEvent; + groupInserable.InsertBuilder.IsNoInsertNull = parent.InsertBuilder.IsNoInsertNull; + groupInserable.IsOffIdentity = parent.IsOffIdentity; + var idList =await groupInserable.AS(item.Key).InsertColumns(names.ToArray()).ExecuteReturnSnowflakeIdListAsync(); + result.AddRange(idList); + } + return result; + } + + private void CreateTable() { var isLog = this.Context.Ado.IsEnableLogEvent;