using System.Linq.Dynamic.Core;
|
using CMS.Plugin.HIAWms.Domain.WmsAreas;
|
using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions;
|
using Microsoft.EntityFrameworkCore;
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
|
using Volo.Abp.EntityFrameworkCore;
|
using Volo.Abp.Specifications;
|
|
namespace CMS.Plugin.HIAWms.EntityFrameworkCore.Repositories;
|
|
/// <inheritdoc />
|
public class EfCoreWmsAreaRepository : EfCoreRepository<ICMSPluginDbContext, WmsArea, Guid>, IWmsAreaRepository
|
{
|
/// <summary>
|
/// Initializes a new instance of the <see cref="EfCoreWmsAreaRepository"/> class.
|
/// </summary>
|
/// <param name="dbContextProvider">The database context provider.</param>
|
public EfCoreWmsAreaRepository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider)
|
: base(dbContextProvider)
|
{
|
}
|
|
/// <inheritdoc />
|
public virtual async Task<WmsArea> FindByNameAsync(string name, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails()
|
.OrderBy(t => t.Sort)
|
.Where(x=> !x.IsDeleted)
|
.FirstOrDefaultAsync(t => t.AreaName == name, GetCancellationToken(cancellationToken));
|
}
|
|
|
/// <summary>
|
/// ²é¿´¿âÇøÊÇ·ñ´æÔÚ
|
/// </summary>
|
/// <param name="areaNo"></param>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public async Task<bool> NameExistAsync(string areaNo, Guid? id = null)
|
{
|
return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id)
|
.Where(x => !x.IsDeleted).AnyAsync(x => x.AreaNo == areaNo);
|
}
|
|
/// <inheritdoc />
|
public async Task<int> GetMaxSortAsync()
|
{
|
var hasAny = await (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).AnyAsync();
|
if (!hasAny)
|
{
|
return 1;
|
}
|
|
var sort = await (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).MaxAsync(x => x.Sort);
|
return sort + 1;
|
}
|
|
/// <inheritdoc />
|
public async Task<List<WmsArea>> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, string filter = null, Specification<WmsArea> specification = null, bool includeDetails = false, CancellationToken cancellationToken = default)
|
{
|
specification ??= new WmsAreaSpecification();
|
return await (await GetDbSetAsync())
|
.IncludeDetails(includeDetails)
|
.Where(specification.ToExpression())
|
.WhereIf(!filter.IsNullOrWhiteSpace(), u => u.AreaNo.Contains(filter))
|
.Where(x => !x.IsDeleted)
|
.OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsArea.Sort) : sorting)
|
.PageBy(skipCount, maxResultCount)
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
}
|
|
/// <inheritdoc />
|
public async Task<long> GetCountAsync(string filter = null, Specification<WmsArea> specification = null, CancellationToken cancellationToken = default)
|
{
|
specification ??= new WmsAreaSpecification();
|
return await (await GetQueryableAsync())
|
.Where(specification.ToExpression())
|
.WhereIf(!filter.IsNullOrWhiteSpace(), u => u.AreaNo.Contains(filter))
|
.Where(x => !x.IsDeleted)
|
.CountAsync(cancellationToken: GetCancellationToken(cancellationToken));
|
}
|
|
/// <inheritdoc />
|
public override async Task<IQueryable<WmsArea>> WithDetailsAsync()
|
{
|
return (await GetQueryableAsync()).Where(x => !x.IsDeleted).IncludeDetails();
|
}
|
}
|