|  |  |  | 
|---|
|  |  |  | using WIDESEA_Core.DB; | 
|---|
|  |  |  | using WIDESEA_Core.Const; | 
|---|
|  |  |  | using WIDESEA_Core.AOP; | 
|---|
|  |  |  | using AngleSharp.Dom; | 
|---|
|  |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; | 
|---|
|  |  |  | using SharpCompress.Common; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEA_Core.BaseRepository | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFields) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Take(top).ToList(); | 
|---|
|  |  |  | return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Take(top).IncludesAllFirstLayer().ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public virtual List<TEntity> QueryData(string where, int top, string orderByFields) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).Take(top).ToList(); | 
|---|
|  |  |  | return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).Take(top).IncludesAllFirstLayer().ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | public virtual List<TEntity> QueryData(string where, int pageIndex, int pageSize, string orderByFields) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) | 
|---|
|  |  |  | .WhereIF(!string.IsNullOrEmpty(where), where).ToPageList(pageIndex, pageSize); | 
|---|
|  |  |  | .WhereIF(!string.IsNullOrEmpty(where), where).IncludesAllFirstLayer().ToPageList(pageIndex, pageSize); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | var list = _db.Queryable<TEntity>() | 
|---|
|  |  |  | .OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) | 
|---|
|  |  |  | .WhereIF(whereExpression != null, whereExpression) | 
|---|
|  |  |  | .IncludesAllFirstLayer() | 
|---|
|  |  |  | .ToPageList(pageIndex, pageSize, ref totalCount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new PageGridData<TEntity> { Rows = list, Total = totalCount }; | 
|---|
|  |  |  | 
|---|
|  |  |  | List<TEntity> list = _db.Queryable<TEntity>() | 
|---|
|  |  |  | .OrderBy(orderByModels) | 
|---|
|  |  |  | .WhereIF(whereExpression != null, whereExpression) | 
|---|
|  |  |  | .IncludesAllFirstLayer() | 
|---|
|  |  |  | .ToPageList(pageIndex, pageSize, ref totalCount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new PageGridData<TEntity>(totalCount, list); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int totalCount = 0; | 
|---|
|  |  |  | List<TEntity> list = _db.Queryable<TEntity>() | 
|---|
|  |  |  | .WhereIF(!string.IsNullOrEmpty(where), where).OrderBy(orderByModels).ToPageList(pageIndex, pageSize, ref totalCount); | 
|---|
|  |  |  | .WhereIF(!string.IsNullOrEmpty(where), where).OrderBy(orderByModels).IncludesAllFirstLayer().ToPageList(pageIndex, pageSize, ref totalCount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new PageGridData<TEntity>(totalCount, list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //    Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(){throw new NotImplementedException();} | 
|---|
|  |  |  | //Task<PageModel<TEntity>> QueryPage(PaginationModel pagination){throw new NotImplementedException();} | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task<TEntity> QureyDataByIdAsync(object id) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().In(id).SingleAsync(); | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | IInsertable<TEntity> insert = _db.Insertable(entity); | 
|---|
|  |  |  | return insert.ExecuteReturnIdentityAsync(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 导航插入数据(只支持2级) | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="Entity"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<bool> AddDataNavAsync(TEntity Entity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return await _db.InsertNav(Entity).IncludesAllFirstLayer().ExecuteCommandAsync(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task<int> AddDataAsync(List<TEntity> listEntity) | 
|---|
|  |  |  | 
|---|
|  |  |  | public Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> whereExpression) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).FirstAsync(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task<TEntity> QueryFirstNavAsync(Expression<Func<TEntity, bool>> whereExpression) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).IncludesAllFirstLayer().FirstAsync(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task<TResult> QueryFirstAsync<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression) | 
|---|
|  |  |  | 
|---|
|  |  |  | return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task<bool> UpdateDataNavAsync(TEntity Entity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.UpdateNav(Entity).IncludesAllFirstLayer().ExecuteCommandAsync(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public bool UpdateDataNav(TEntity Entity) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return _db.UpdateNav(Entity).IncludesAllFirstLayer().ExecuteCommand(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //List<TResult> QueryMuch<T, T2, T3, TResult>( | 
|---|
|  |  |  | //    Expression<Func<T, T2, T3, object[]>> joinExpression, | 
|---|
|  |  |  | //    Expression<Func<T, T2, T3, TResult>> selectExpression, | 
|---|
|  |  |  | //    Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(){throw new NotImplementedException();} | 
|---|
|  |  |  | //Task<PageModel<TEntity>> QueryPage(PaginationModel pagination){throw new NotImplementedException();} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|