Parcourir la source

😎代码优化

zuohuaijun il y a 1 an
Parent
commit
abc3ac8988

+ 1 - 1
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -38,7 +38,7 @@
     <PackageReference Include="SqlSugarCore" Version="5.1.4.166" />
     <PackageReference Include="SSH.NET" Version="2024.1.0" />
     <PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.4" />
-    <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1062" />
+    <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1064" />
     <PackageReference Include="UAParser" Version="3.1.47" />
     <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
   </ItemGroup>

+ 5 - 5
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs

@@ -1,8 +1,8 @@
-// Admin.NET 鬘ケ逶ョ逧�沿譚�€∝膚譬�€∽ク灘茜蜥悟�莉也嶌蜈ウ譚�茜蝮�女逶ク蠎疲ウ募セ区ウ戊ァ�噪菫晄侃縲ゆスソ逕ィ譛ャ鬘ケ逶ョ蠎秘�螳育嶌蜈ウ豕募セ区ウ戊ァ�柱隶ク蜿ッ隸∫噪隕∵アゅ€
+// Admin.NET 鬘ケ逶ョ逧�沿譚�€∝膚譬�€∽ク灘茜蜥悟�莉也嶌蜈ウ譚�茜蝮�女逶ク蠎疲ウ募セ区ウ戊ァ�噪菫晄侃縲ゆスソ逕ィ譛ャ鬘ケ逶ョ蠎秘�螳育嶌蜈ウ豕募セ区ウ戊ァ�柱隶ク蜿ッ隸∫噪隕∵アゅ€?
 //
-// 譛ャ鬘ケ逶ョ荳サ隕��蠕MIT 隶ク蜿ッ隸∝柱 Apache 隶ク蜿ッ隸�シ育沿譛ャ 2.0�芽ソ幄。悟�蜿大柱菴ソ逕ィ縲りョク蜿ッ隸∽ス堺コ取コ蝉サ」遐∵�第�ケ逶ョ蠖穂クュ逧� LICENSE-MIT 蜥� LICENSE-APACHE 譁�サカ縲�
+// 譛ャ鬘ケ逶ョ荳サ隕��蠕?MIT 隶ク蜿ッ隸∝柱 Apache 隶ク蜿ッ隸�シ育沿譛ャ 2.0�芽ソ幄。悟�蜿大柱菴ソ逕ィ縲りョク蜿ッ隸∽ス堺コ取コ蝉サ」遐∵�第�ケ逶ョ蠖穂クュ逧?LICENSE-MIT 蜥?LICENSE-APACHE 譁�サカ縲?
 //
-// 荳榊セ怜茜逕ィ譛ャ鬘ケ逶ョ莉惹コ句些螳ウ蝗ス螳カ螳牙�縲∵臆荵ア遉セ莨夂ァゥ蠎上€∽セオ迥ッ莉紋ココ蜷域ウ墓揀逶顔ュ画ウ募セ区ウ戊ァ�ヲ∵ュ「逧�エサ蜉ィ�∽ササ菴募渕莠取悽鬘ケ逶ョ莠梧ャ。蠑€蜿題€御コァ逕溽噪荳€蛻�ウ募セ狗コ�郤キ蜥瑚エ」莉サ�梧�莉ャ荳肴価諡�ササ菴戊エ」莉サ�
+// 荳榊セ怜茜逕ィ譛ャ鬘ケ逶ョ莉惹コ句些螳ウ蝗ス螳カ螳牙�縲∵臆荵ア遉セ莨夂ァゥ蠎上€∽セオ迥ッ莉紋ココ蜷域ウ墓揀逶顔ュ画ウ募セ区ウ戊ァ�ヲ∵ュ「逧�エサ蜉ィ�∽ササ菴募渕莠取悽鬘ケ逶ョ莠梧ャ。蠑€蜿題€御コァ逕溽噪荳€蛻�ウ募セ狗コ�郤キ蜥瑚エ」莉サ�梧�莉ャ荳肴価諡�ササ菴戊エ」莉サ�?
 
 namespace Admin.NET.Core;
 
@@ -36,11 +36,11 @@ public class SqlSugarRepository<T> : SimpleClient<T>, ISqlSugarRepository<T> whe
         if (typeof(T).IsDefined(typeof(SysTableAttribute), false))
             return;
 
-        // 闍・譛ェ雍エ莉サ菴戊。ィ迚ケ諤ァ謌門ス灘燕譛ェ逋サ蠖墓�譏ッ鮟倩ョ、遘滓姐Id�悟�霑泌屓鮟倩ョ、蠎楢ソ樊
+        // 闍・譛ェ雍エ莉サ菴戊。ィ迚ケ諤ァ謌門ス灘燕譛ェ逋サ蠖墓�譏ッ鮟倩ョ、遘滓姐Id�悟�霑泌屓鮟倩ョ、蠎楢ソ樊�?
         var tenantId = App.User?.FindFirst(ClaimConst.TenantId)?.Value;
         if (string.IsNullOrWhiteSpace(tenantId) || tenantId == SqlSugarConst.MainConfigId) return;
 
-        // 譬ケ謐ョ遘滓姐Id蛻�困蠎楢ソ樊磁, 荳コ遨コ蛻呵ソ泌屓鮟倩ョ、蠎楢ソ樊磁
+        // 譬ケ謐ョ遘滓姐Id蛻�困蠎楢ソ樊�? 荳コ遨コ蛻呵ソ泌屓鮟倩ョ、蠎楢ソ樊磁
         var sqlSugarScopeProviderTenant = App.GetRequiredService<SysTenantService>().GetTenantDbConnectionScope(long.Parse(tenantId));
         if (sqlSugarScopeProviderTenant == null) return;
         base.Context = sqlSugarScopeProviderTenant;

+ 15 - 13
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -11,6 +11,9 @@ public static class SqlSugarSetup
     // 多租户实例
     public static ITenant ITenant { get; set; }
 
+    // 是否正在处理种子数据
+    private static bool _isHandlingSeedData = false;
+
     /// <summary>
     /// SqlSugar 上下文初始化
     /// </summary>
@@ -165,8 +168,9 @@ public static class SqlSugarSetup
         // 数据审计
         db.Aop.DataExecuting = (oldValue, entityInfo) =>
         {
-            if (CreateingSeedData)
-                return;
+            // 若正在处理种子数据则直接返回
+            if (_isHandlingSeedData) return;
+
             // 新增/插入
             if (entityInfo.OperationType == DataFilterType.InsertByObject)
             {
@@ -251,9 +255,6 @@ public static class SqlSugarSetup
         SqlSugarFilter.SetCustomEntityFilter(db);
     }
 
-    //正在创建种子数据
-    private static bool CreateingSeedData = false;
-
     /// <summary>
     /// 开启库表差异化日志
     /// </summary>
@@ -332,7 +333,8 @@ public static class SqlSugarSetup
         // 初始化种子数据
         if (config.SeedSettings.EnableInitSeed)
         {
-            CreateingSeedData = true;
+            _isHandlingSeedData = true;
+
             Log.Information($"初始化种子数据 {config.DbType} - {config.ConfigId}");
             var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
                 .WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false))
@@ -364,7 +366,7 @@ public static class SqlSugarSetup
                 if (seedData == null) continue;
 
                 var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(entityType);
-                Console.WriteLine($"添加数据 {entityInfo.DbTableName} ({config.ConfigId} - {++count}/{sum},数据量:{seedData.Count()})");
+                Console.WriteLine($"添加数据 {entityInfo.DbTableName} ({config.ConfigId} - {++count}/{sum},数据量:{seedData.Count()})");
 
                 if (entityType.GetCustomAttribute<SplitTableAttribute>(true) != null)
                 {
@@ -381,14 +383,14 @@ public static class SqlSugarSetup
                         // 按主键进行批量增加和更新
                         var storage = dbProvider.StorageableByObject(seedData.ToList()).ToStorage();
 
-                        //要先修改再插入,否则就会更新了最新修改时间字段
+                        // 先修改再插入,否则会更新修改时间字段
                         if (seedType.GetCustomAttribute<IgnoreUpdateSeedAttribute>() == null) // 有忽略更新种子特性时则不更新
                         {
-                            int updateCnt = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(u => u.PropertyName).ToArray()).ExecuteCommand();
-                            Console.WriteLine($"  修改{updateCnt}/{seedData.Count()}条记录");
+                            int updateCount = storage.AsUpdateable.IgnoreColumns(entityInfo.Columns.Where(u => u.PropertyInfo.GetCustomAttribute<IgnoreUpdateSeedColumnAttribute>() != null).Select(u => u.PropertyName).ToArray()).ExecuteCommand();
+                            Console.WriteLine($"  修改 {updateCount}/{seedData.Count()} 条记录");
                         }
-                        int insertCnt = storage.AsInsertable.ExecuteCommand();
-                        Console.WriteLine($"  插入{insertCnt}/{seedData.Count()}条记录");
+                        int insertCount = storage.AsInsertable.ExecuteCommand();
+                        Console.WriteLine($"  插入 {insertCount}/{seedData.Count()} 条记录");
                     }
                     else
                     {
@@ -398,7 +400,7 @@ public static class SqlSugarSetup
                     }
                 }
             }
-            CreateingSeedData = false;
+            _isHandlingSeedData = false;
         }
     }
 

+ 2 - 2
Admin.NET/Admin.NET.Core/Util/ComputerUtil.cs

@@ -147,16 +147,16 @@ public static class ComputerUtil
     /// <returns></returns>
     public static string GetIpFromOnline()
     {
-        var url = "https://www.ip.cn/api/index?ip&type=0";
         try
         {
+            var url = "https://www.ip.cn/api/index?ip&type=0";
             var str = url.GetAsStringAsync().GetAwaiter().GetResult();
             var resp = JSON.Deserialize<IpCnResp>(str);
             return resp.Ip + " " + resp.Address;
         }
         catch
         {
-            return "";
+            return "unknow";
         }
     }