| | |
| | | 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; |
| | | } |
| | |
| | | { |
| | | 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> |
| | |
| | | { |
| | | object? obj = Activator.CreateInstance(htyType); |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateTypeEnum)); |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | } |
| | | _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | if (obj != null) |
| | | _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | } |
| | | } |
| | | return DeleteData(entity); |
| | |
| | | { |
| | | object? obj2 = Activator.CreateInstance(htyType); |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateTypeEnum)); |
| | | 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(); |
| | |
| | | list.Add(obj); |
| | | } |
| | | } |
| | | _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | if (list.Count > 0) |
| | | _db.InsertableByObject(list).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | |
| | | } |
| | | } |