Эх сурвалжийг харах

解决在事件总线中给更新人信息重新赋值NULL的问题

孙志昊 1 сар өмнө
parent
commit
eced30ac7c

+ 7 - 4
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -241,10 +241,6 @@ public static class SqlSugarSetup
             {
                 if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime))
                     entityInfo.SetValue(DateTime.Now);
-                else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserId))
-                    entityInfo.SetValue(App.User?.FindFirst(ClaimConst.UserId)?.Value);
-                else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserName))
-                    entityInfo.SetValue(App.User?.FindFirst(ClaimConst.RealName)?.Value);
                 else if (entityInfo.PropertyName == nameof(EntityBaseDel.DeleteTime))
                 {
                     dynamic entityValue = entityInfo.EntityValue;
@@ -254,6 +250,13 @@ public static class SqlSugarSetup
                         entityInfo.SetValue(DateTime.Now);
                     }
                 }
+                // 若当前用户为空(非web线程时)
+                if (App.User == null) return;
+
+                if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserId))
+                    entityInfo.SetValue(App.User?.FindFirst(ClaimConst.UserId)?.Value);
+                else if (entityInfo.PropertyName == nameof(EntityBase.UpdateUserName))
+                    entityInfo.SetValue(App.User?.FindFirst(ClaimConst.RealName)?.Value);
             }
         };