From e1dd1dc9ba7135e3d64a65587d6c1be2c3e18c5a Mon Sep 17 00:00:00 2001 From: wangxinhui <wangxinhui@hnkhzn.com> Date: 星期三, 25 六月 2025 11:01:22 +0800 Subject: [PATCH] 提交最新优化代码 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs | 83 ++++++++++++++++++++++------------------- 1 files changed, 45 insertions(+), 38 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" index e974d51..41c5bd7 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/RepositoryBase.cs" @@ -36,38 +36,38 @@ ISqlSugarClient db = _dbBase; //澶氱鎴� - var mta = typeof(TEntity).GetCustomAttribute<MultiTenantAttribute>(); - if (mta is { TenantType: TenantTypeEnum.Db }) - { - //鑾峰彇绉熸埛淇℃伅 绉熸埛淇℃伅鍙互鎻愬墠缂撳瓨涓嬫潵 - if (App.User is { TenantId: > 0 }) - { - dynamic tenant = db.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantId, "=", App.User.TenantId).First(); - if (tenant != null) - { - var iTenant = db.AsTenant(); - if (!iTenant.IsAnyConnection(tenant.TenantId)) - { - string conStr = tenant.ConnectionString; - ConnectionConfig connectionConfig = new ConnectionConfig() - { - ConfigId = tenant.TenantId, - ConnectionString = conStr.DecryptDES(AppSecret.DB), - DbType = (SqlSugar.DbType)tenant.DbType, - IsAutoCloseConnection = true, - AopEvents = new AopEvents() - { - DataExecuting = SqlSugarAop.DataExecuting, + //var mta = typeof(TEntity).GetCustomAttribute<MultiTenantAttribute>(); + //if (mta is { TenantType: TenantTypeEnum.Db }) + //{ + // //鑾峰彇绉熸埛淇℃伅 绉熸埛淇℃伅鍙互鎻愬墠缂撳瓨涓嬫潵 + // if (App.User is { TenantId: > 0 }) + // { + // dynamic tenant = db.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantId, "=", App.User.TenantId).First(); + // if (tenant != null) + // { + // var iTenant = db.AsTenant(); + // if (!iTenant.IsAnyConnection(tenant.TenantId)) + // { + // string conStr = tenant.ConnectionString; + // ConnectionConfig connectionConfig = new ConnectionConfig() + // { + // ConfigId = tenant.TenantId, + // ConnectionString = conStr.DecryptDES(AppSecret.DB), + // DbType = (SqlSugar.DbType)tenant.DbType, + // IsAutoCloseConnection = true, + // AopEvents = new AopEvents() + // { + // DataExecuting = SqlSugarAop.DataExecuting, - } - }; - iTenant.AddConnection(connectionConfig); - } + // } + // }; + // iTenant.AddConnection(connectionConfig); + // } - return iTenant.GetConnection(tenant.TenantId); - } - } - } + // return iTenant.GetConnection(tenant.TenantId); + // } + // } + //} return db; } @@ -122,6 +122,11 @@ { IInsertable<TEntity> insert = _db.Insertable(entity); return insert.ExecuteReturnIdentity(); + } + + public virtual bool AddData<TChild>(TEntity entity, Expression<Func<TEntity, List<TChild>>> expression) where TChild : class, new() + { + return _db.InsertNav(entity).Include(expression).ExecuteCommand(); } /// <summary> @@ -864,7 +869,7 @@ .WhereIF(whereExpression != null, whereExpression).ToListAsync(); } - public bool DeleteAndMoveIntoHty(TEntity entity, OperateType operateType) + public bool DeleteAndMoveIntoHty(TEntity entity, OperateTypeEnum operateType) { Type type = entity.GetType(); Assembly assembly = type.Assembly; @@ -873,8 +878,8 @@ { object? obj = Activator.CreateInstance(htyType); PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); - PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType)); - PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId"); + PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType)); + PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId)); if (obj != null && keyPro != null && operateTypePro != null && sourceIdPro != null) { operateTypePro.SetValue(obj, operateType.ToString()); @@ -903,13 +908,14 @@ } } } - _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); + if (obj != null) + _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); } } return DeleteData(entity); } - public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateType operateType) + public bool DeleteAndMoveIntoHty(List<TEntity> entities, OperateTypeEnum operateType) { Type type = typeof(TEntity); Assembly assembly = type.Assembly; @@ -918,8 +924,8 @@ { object? obj2 = Activator.CreateInstance(htyType); PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); - PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType)); - PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId"); + PropertyInfo? operateTypePro = htyType.GetProperty(nameof(IBaseHistoryEntity.OperateType)); + PropertyInfo? sourceIdPro = htyType.GetProperty(nameof(IBaseHistoryEntity.SourceId)); if (obj2 != null && keyPro != null && operateTypePro != null && sourceIdPro != null) { List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList(); @@ -955,7 +961,8 @@ list.Add(obj); } } - _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand(); + if (list.Count > 0) + _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand(); } } -- Gitblit v1.9.3