using CMS.Plugin.HIAWms.Domain.WmsTask;
|
using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions;
|
using CmsQueryExtensions.Extension;
|
using Microsoft.EntityFrameworkCore;
|
using System.Linq.Dynamic.Core;
|
using System.Linq.Expressions;
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
|
using Volo.Abp.EntityFrameworkCore;
|
|
|
namespace CMS.Plugin.HIAWms.EntityFrameworkCore.Repositories;
|
|
/// <summary>
|
/// Wms任务管理仓储实现
|
/// </summary>
|
public class EfCoreWmsTaskRepository : EfCoreRepository<ICMSPluginDbContext, WmsTask, Guid>, IWmsTaskRepository
|
{
|
/// <summary>
|
/// Initializes a new instance of the <see cref="EfCoreWmsTaskRepository"/> class.
|
/// </summary>
|
/// <param name="dbContextProvider">The database context provider.</param>
|
public EfCoreWmsTaskRepository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider)
|
: base(dbContextProvider)
|
{
|
}
|
|
/// <summary>
|
/// 按照名称查找Wms任务管理
|
/// </summary>
|
/// <param name="taskNo"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public virtual async Task<WmsTask> FindByNameAsync(string taskNo, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails()
|
.Where(x => !x.IsDeleted)
|
.OrderBy(t => t.Sort)
|
.FirstOrDefaultAsync(t => t.TaskNo == taskNo, GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// 验证名称是否存在Wms任务管理
|
/// </summary>
|
/// <param name="taskNo">校验值</param>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public async Task<bool> NameExistAsync(string taskNo, Guid? id = null)
|
{
|
return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.TaskNo == taskNo);
|
}
|
|
/// <summary>
|
/// 获取最大排序Wms任务管理
|
/// </summary>
|
/// <returns></returns>
|
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;
|
}
|
|
/// <summary>
|
/// 获取分页列表Wms任务管理
|
/// </summary>
|
/// <param name="whereConditions"></param>
|
/// <param name="sorting"></param>
|
/// <param name="maxResultCount"></param>
|
/// <param name="skipCount"></param>
|
/// <param name="includeDetails"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<List<WmsTask>> GetListAsync(FunReturnResultModel<Expression<Func<WmsTask, bool>>> whereConditions, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, bool includeDetails = false, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails(includeDetails)
|
.WhereIf(whereConditions != null, whereConditions.data)
|
.Where(x => !x.IsDeleted)
|
.OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsTask.Sort) : sorting)
|
.PageBy(skipCount, maxResultCount)
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// 获取总数Wms任务管理
|
/// </summary>
|
/// <param name="whereConditions"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<WmsTask, bool>>> whereConditions, CancellationToken cancellationToken = default)
|
{
|
return await (await GetQueryableAsync())
|
.WhereIf(whereConditions != null, whereConditions.data)
|
.Where(x => !x.IsDeleted)
|
.CountAsync(cancellationToken: GetCancellationToken(cancellationToken));
|
}
|
|
|
/// <inheritdoc />
|
public override async Task<IQueryable<WmsTask>> WithDetailsAsync()
|
{
|
return (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).IncludeDetails();
|
}
|
}
|