using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Linq.Expressions; using CMS.Plugin.HIAWms.Domain.WmsAreas; using CMS.Plugin.HIAWms.Domain.WmsMaterials; using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions; using CmsQueryExtensions.Extension; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Specifications; namespace CMS.Plugin.HIAWms.EntityFrameworkCore.Repositories; /// public class EfCoreWmsMaterialRepository : EfCoreRepository, IWmsMaterialRepository { /// /// Initializes a new instance of the class. /// /// The database context provider. public EfCoreWmsMaterialRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } /// public virtual async Task FindByNameAsync(string name, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .IncludeDetails() .Where(x => !x.IsDeleted) .OrderBy(t => t.Sort) .FirstOrDefaultAsync(t => t.MaterialNo == name, GetCancellationToken(cancellationToken)); } /// /// ²éÕÒÐͺŠ/// /// /// /// public virtual async Task FindByModelAsync(string model, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .IncludeDetails() .Where(x => !x.IsDeleted) .OrderBy(t => t.Sort) .FirstOrDefaultAsync(t => t.MaterialModel == model, GetCancellationToken(cancellationToken)); } /// public async Task NameExistAsync(string MaterialNo, Guid? id = null) { return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.MaterialNo == MaterialNo); } /// public async Task 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; } /// /// /// »ñÈ¡·ÖÒ³ÁбíÎïÁÏ»ù´¡ÐÅÏ¢ /// /// /// /// /// /// /// /// public async Task> GetListAsync(FunReturnResultModel>> 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)); } /// /// »ñÈ¡ÎïÁÏ»ù´¡Áбí /// /// /// /// public async Task> GetMaterialListAsync(WmsMaterial? material, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .WhereIf(!string.IsNullOrEmpty(material.MaterialName), u => u.MaterialName.Contains(material.MaterialName)) .WhereIf(!string.IsNullOrEmpty(material.MaterialNo), u => u.MaterialNo.Contains(material.MaterialNo)) .WhereIf(material.MaterialType > 0, u => u.MaterialType == material.MaterialType) .WhereIf(material.PurchaseType > 0, u => u.PurchaseType == material.PurchaseType) .Where(x => !x.IsDeleted) .ToListAsync(GetCancellationToken(cancellationToken)); } /// /// »ñÈ¡×ÜÊýÎïÁÏ»ù´¡ÐÅÏ¢ /// /// /// /// public async Task GetCountAsync(FunReturnResultModel>> whereConditions, CancellationToken cancellationToken = default) { return await (await GetQueryableAsync()) .WhereIf(whereConditions != null, whereConditions.data) .Where(x => !x.IsDeleted) .CountAsync(cancellationToken: GetCancellationToken(cancellationToken)); } /// public override async Task> WithDetailsAsync() { return (await GetQueryableAsync()) .Where(x => !x.IsDeleted).IncludeDetails(); } /// /// »ñÈ¡ÎïÁϱí /// /// /// public async Task> GetListForSelectAsync(CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .Where(x => !x.IsDeleted) .ToListAsync(GetCancellationToken(cancellationToken)); } }