From f4078b75fe80f03e58af3217bf642d0de118d1c9 Mon Sep 17 00:00:00 2001 From: liuying <1427574514@qq.com> Date: 周四, 09 5月 2024 13:01:19 +0800 Subject: [PATCH] 流程图 --- iWare_RawMaterialWarehouse_Wms/Admin.NET.EntityFramework.Core/DbContexts/MultiTenantDbContext.cs | 62 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/iWare_RawMaterialWarehouse_Wms/Admin.NET.EntityFramework.Core/DbContexts/MultiTenantDbContext.cs b/iWare_RawMaterialWarehouse_Wms/Admin.NET.EntityFramework.Core/DbContexts/MultiTenantDbContext.cs new file mode 100644 index 0000000..a2bfa6f --- /dev/null +++ b/iWare_RawMaterialWarehouse_Wms/Admin.NET.EntityFramework.Core/DbContexts/MultiTenantDbContext.cs @@ -0,0 +1,62 @@ +using Admin.NET.Core; +using Furion; +using Furion.DatabaseAccessor; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Yitter.IdGenerator; + +namespace Admin.NET.EntityFramework.Core +{ + [AppDbContext("MultiTenantConnection", DbProvider.Sqlite)] + public class MultiTenantDbContext : AppDbContext<MultiTenantDbContext, MultiTenantDbContextLocator> + { + public MultiTenantDbContext(DbContextOptions<MultiTenantDbContext> options) : base(options) + { + } + + protected override void SavingChangesEvent(DbContextEventData eventData, InterceptionResult<int> result) + { + // 鑾峰彇鎵�鏈夊凡鏇存敼鐨勫疄浣� + var entities = eventData.Context.ChangeTracker.Entries() + .Where(u => u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added) + .ToList(); + + // 鍒ゆ柇鏄惁鏄紨绀虹幆澧� + //var demoEnvFlag = App.GetService<ISysConfigService>().GetDemoEnvFlag().GetAwaiter().GetResult(); + //if (demoEnvFlag) + //{ + // var sysUser = entities.Find(u => u.Entity.GetType() == typeof(SysUser)); + // if (sysUser == null || string.IsNullOrEmpty((sysUser.Entity as SysUser).LastLoginTime.ToString())) // 鎺掗櫎鐧诲綍 + // throw Oops.Oh(ErrorCode.D1200); + //} + + // 褰撳墠鎿嶄綔鐢ㄦ埛淇℃伅 + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + var userName = App.User.FindFirst(ClaimConst.CLAINM_ACCOUNT)?.Value; + + foreach (var entity in entities) + { + if (entity.Entity.GetType().IsSubclassOf(typeof(DEntityBase<long, MultiTenantDbContextLocator>))) + { + var obj = entity.Entity as DEntityBase<long, MultiTenantDbContextLocator>; + if (entity.State == EntityState.Added) + { + obj.Id = YitIdHelper.NextId(); + obj.CreatedTime = DateTimeOffset.Now; + if (!string.IsNullOrEmpty(userId)) + { + obj.CreatedUserId = long.Parse(userId); + obj.CreatedUserName = userName; + } + } + else if (entity.State == EntityState.Modified) + { + obj.UpdatedTime = DateTimeOffset.Now; + obj.UpdatedUserId = long.Parse(userId); + obj.UpdatedUserName = userName; + } + } + } + } + } +} \ No newline at end of file -- Gitblit v1.9.3