using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
|
using CMS.Plugin.PipeLineLems.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.PipeLineLems.EntityFrameworkCore.Repositories;
|
|
/// <summary>
|
/// 叫料记录表仓储实现
|
/// </summary>
|
public class EfCoreCallMaterialOrderRecordRepository : EfCoreRepository<ICMSPluginDbContext, CallMaterialOrderRecord, Guid>, ICallMaterialOrderRecordRepository
|
{
|
/// <summary>
|
/// Initializes a new instance of the <see cref="EfCoreCallMaterialOrderRecordRepository"/> class.
|
/// </summary>
|
/// <param name="dbContextProvider">The database context provider.</param>
|
public EfCoreCallMaterialOrderRecordRepository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider)
|
: base(dbContextProvider)
|
{
|
}
|
|
/// <summary>
|
/// 按照名称查找叫料记录表
|
/// </summary>
|
/// <param name="name"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public virtual async Task<CallMaterialOrderRecord> FindByNameAsync(string name, CancellationToken cancellationToken = default)
|
{
|
return await (await GetDbSetAsync())
|
.IncludeDetails()
|
.Where(x => !x.IsDeleted)
|
.OrderByDescending(x=>x.CreationTime)
|
.FirstOrDefaultAsync(t => t.DataIdentifier == name, GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// 验证名称是否存在叫料记录表
|
/// </summary>
|
/// <param name="name">校验值</param>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public async Task<bool> NameExistAsync(string name, Guid? id = null)
|
{
|
return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.DataIdentifier == name);
|
}
|
|
/// <summary>
|
/// 获取最大排序叫料记录表
|
/// </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>
|
/// 获取分页列表叫料记录表
|
/// </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<CallMaterialOrderRecord>> GetListAsync(FunReturnResultModel<Expression<Func<CallMaterialOrderRecord, 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)
|
.OrderByDescending(x=>x.CreationTime)
|
.PageBy(skipCount, maxResultCount)
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
}
|
|
/// <summary>
|
/// 获取总数叫料记录表
|
/// </summary>
|
/// <param name="whereConditions"></param>
|
/// <param name="cancellationToken"></param>
|
/// <returns></returns>
|
public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<CallMaterialOrderRecord, 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<CallMaterialOrderRecord>> WithDetailsAsync()
|
{
|
return (await GetQueryableAsync())
|
.Where(x => !x.IsDeleted).IncludeDetails();
|
}
|
}
|