From 7ff298c6834275b63b612af49651673689a39660 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期三, 27 十一月 2024 11:33:18 +0800 Subject: [PATCH] 更新 --- WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs index 3a744be..94924fa 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; +using WIDESEAWCS_Core.Attributes; using WIDESEAWCS_Core.Const; using WIDESEAWCS_Core.DB; using WIDESEAWCS_Core.Helper; @@ -87,7 +88,7 @@ string seedData = FileHelper.ReadFile(string.Format(SeedDataFolder, t.Name), Encoding.UTF8); - #region Sys_User + #region AddSeedData if (seedData != "涓嶅瓨鍦ㄧ浉搴旂殑鐩綍") { List<Dictionary<string, object>> dicFile = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(seedData); @@ -106,7 +107,19 @@ for (int i = 0; i < propertyInfos.Count; i++) { PropertyInfo propertyInfo = propertyInfos[i]; - SugarColumn sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); + + SequenceAttribute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttribute>(); + if (sequenceAttirbute != null) + { + int count = dbContext.Db.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt(); + if (count == 0) + { + string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE"; + dbContext.Db.Ado.ExecuteCommand(sql); + } + } + + SugarColumn? sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); if (sugarColumn != null) { if (!sugarColumn.IsIgnore) @@ -117,7 +130,6 @@ } dic.Add(keyValuePairs); } - if (dic.Count > 0) { @@ -141,8 +153,6 @@ } } #endregion - - } else { @@ -154,7 +164,18 @@ for (int i = 0; i < propertyInfos.Count; i++) { PropertyInfo propertyInfo = propertyInfos[i]; - SugarColumn sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); + + SequenceAttribute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttribute>(); + if (sequenceAttirbute != null) + { + int count = dbContext.Db.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt(); + if (count == 0) + { + string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE"; + dbContext.Db.Ado.ExecuteCommand(sql); + } + } + SugarColumn? sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); if (sugarColumn != null) { if (!sugarColumn.IsIgnore) -- Gitblit v1.9.3