Administrator
3 years ago
4 changed files with 256 additions and 0 deletions
@ -0,0 +1,48 @@ |
|||
|
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.Entities; |
|||
using Win.Sfs.SettleAccount.Entities.WMS; |
|||
using WY.NewJit.Extends.PaiGe.WMS; |
|||
|
|||
|
|||
namespace Win.Sfs.SettleAccount.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName("UnInterface")] |
|||
public class UnInterfaceDbContext : AbpDbContext<UnInterfaceDbContext> |
|||
{ |
|||
#region DbSet
|
|||
|
|||
|
|||
#endregion
|
|||
|
|||
/* Add DbSet properties for your Aggregate Roots / Entities here. |
|||
* Also map them inside NewJitDbContextModelCreatingExtensions.ConfigureNewJit |
|||
*/ |
|||
|
|||
public UnInterfaceDbContext(DbContextOptions<UnInterfaceDbContext> options) |
|||
: base(options) |
|||
{ |
|||
this.Database.SetCommandTimeout(System.TimeSpan.FromMinutes(30)); |
|||
} |
|||
|
|||
|
|||
|
|||
protected override void OnModelCreating(ModelBuilder builder) |
|||
{ |
|||
base.OnModelCreating(builder); |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,163 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.Common; |
|||
using System.Data.SqlClient; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Storage; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
|||
using Win.Sfs.Shared; |
|||
using Win.Sfs.Shared.DomainBase; |
|||
using Win.Sfs.Shared.Filter; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Repository |
|||
{ |
|||
public class UnInterfaceEfCoreRepository<TEntity> : |
|||
EfCoreRepository<UnInterfaceDbContext,TEntity>, |
|||
ITransientDependency |
|||
where TEntity : class,IEntity |
|||
{ |
|||
|
|||
private readonly IDbContextProvider<UnInterfaceDbContext> _dbContextProvider; |
|||
|
|||
|
|||
|
|||
public UnInterfaceEfCoreRepository(IDbContextProvider<UnInterfaceDbContext> dbContextProvider) : |
|||
base(dbContextProvider) |
|||
{ |
|||
|
|||
_dbContextProvider = dbContextProvider; |
|||
|
|||
} |
|||
public UnInterfaceEfCoreRepository() : base(null) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public DbCommand CreateCommand(string commandText, CommandType commandType, params DbParameter[] parameters) |
|||
{ |
|||
var command = DbContext.Database.GetDbConnection().CreateCommand(); |
|||
|
|||
command.CommandText = commandText; |
|||
command.CommandType = commandType; |
|||
command.Transaction = DbContext.Database.CurrentTransaction?.GetDbTransaction(); |
|||
|
|||
foreach (var parameter in parameters) |
|||
{ |
|||
command.Parameters.Add(parameter); |
|||
} |
|||
|
|||
return command; |
|||
} |
|||
|
|||
public async Task EnsureConnectionOpenAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
var connection = DbContext.Database.GetDbConnection(); |
|||
|
|||
if (connection.State != ConnectionState.Open) |
|||
{ |
|||
await connection.OpenAsync(cancellationToken); |
|||
} |
|||
} |
|||
public virtual async Task<List<TEntity>> GetAllAsync( bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = includeDetails ? this.WithDetails() : this.GetQueryable(); |
|||
|
|||
//query = query.Where(p => p.BranchId.Equals(branchId));
|
|||
|
|||
return await query.ToListAsync(cancellationToken: cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync( CancellationToken cancellationToken = default) |
|||
{ |
|||
return await this.GetQueryable() |
|||
//.Where(p => p.BranchId.Equals(branchId))
|
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
} |
|||
|
|||
public virtual async Task<long> GetCountByFilterAsync( List<FilterCondition> filters, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await this.GetQueryable() |
|||
//.Where(p => p.BranchId.Equals(branchId))
|
|||
.WhereIf(filters?.Count != 0, filters.ToLambda<TEntity>()) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<TEntity>> GetListByFilterAsync(List<FilterCondition> filters, |
|||
string sorting = null, |
|||
int maxResultCount = int.MaxValue, int skipCount = 0, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = includeDetails ? this.WithDetails() : this.GetQueryable(); |
|||
// query = query.Where(p => p.BranchId.Equals(branchId));
|
|||
var entities = query.WhereIf(filters?.Count != 0, filters.ToLambda<TEntity>()); |
|||
//2021-07-02 设置sorting首字母大小,因设置了驼峰规则,不匹配“ var memberProp = typeof(T).GetProperty(propertyName);”反射
|
|||
if(!string.IsNullOrEmpty(sorting)) |
|||
{ |
|||
sorting = sorting.Substring(0, 1).ToUpper() + sorting.Substring(1); |
|||
} |
|||
entities = GetSortingQueryable(entities, sorting); |
|||
return await entities.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
|
|||
} |
|||
|
|||
protected static IQueryable<TEntity> GetSortingQueryable(IQueryable<TEntity> entities, string sorting) |
|||
{ |
|||
if (string.IsNullOrEmpty(sorting)) |
|||
{ |
|||
entities = entities.OrderByDescending("Id"); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
|
|||
|
|||
|
|||
var sortParams = sorting?.Split(' '); |
|||
var sortName = sortParams[0]; |
|||
|
|||
|
|||
Type t = typeof(TEntity); |
|||
var _first = t.GetProperties().Where(p => p.Name.ToUpper() == sortName.ToUpper()).FirstOrDefault(); |
|||
if (_first != null) |
|||
{ |
|||
sortName = _first.Name; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
bool isDesc; |
|||
if (sortParams.Length > 1) |
|||
{ |
|||
var sortDirection = sortParams[1]; |
|||
isDesc = sortDirection.ToUpper().Contains("DESC") ? true : false; |
|||
} |
|||
else |
|||
{ |
|||
isDesc = true; |
|||
} |
|||
|
|||
entities = isDesc ? entities.OrderByDescending(sortName) : entities.OrderBy(sortName); |
|||
} |
|||
|
|||
return entities; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Repository |
|||
{ |
|||
public class WmsOutputInterfaceDapperRepoisitory |
|||
{ |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue