From fd666806b58ab0f8276ae538a040a482521c8c48 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周二, 20 5月 2025 18:15:53 +0800 Subject: [PATCH] 高级查询样式整改(其实我发现并没有什么变化啊) --- HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsAreaRepository.cs | 84 +++++++++++++++++++++++++++++++++--------- 1 files changed, 66 insertions(+), 18 deletions(-) diff --git a/HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsAreaRepository.cs b/HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsAreaRepository.cs index 386b78d..ca840a0 100644 --- a/HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsAreaRepository.cs +++ b/HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsAreaRepository.cs @@ -1,6 +1,11 @@ +using System; using System.Linq.Dynamic.Core; +using System.Linq.Expressions; using CMS.Plugin.HIAWms.Domain.WmsAreas; using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions; +using CmsQueryExtensions.Extension; +using DatabaseSchemaReader.Filters; +using MathNet.Numerics; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -21,15 +26,15 @@ } /// <inheritdoc /> - public virtual async Task<WmsArea> FindByNameAsync(string name, CancellationToken cancellationToken = default) + public virtual async Task<WmsArea> FindByNameAsync(string areaNo, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .IncludeDetails() .OrderBy(t => t.Sort) - .FirstOrDefaultAsync(t => t.AreaName == name, GetCancellationToken(cancellationToken)); + .Where(x => !x.IsDeleted) + .FirstOrDefaultAsync(t => t.AreaNo == areaNo, GetCancellationToken(cancellationToken)); } - /// <summary> /// 查看库区是否存在 /// </summary> @@ -38,48 +43,91 @@ /// <returns></returns> public async Task<bool> NameExistAsync(string areaNo, Guid? id = null) { - return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).AnyAsync(x => x.AreaNo == areaNo); + 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()).AnyAsync(); + var hasAny = await (await GetQueryableAsync()) + .Where(x => !x.IsDeleted).AnyAsync(); if (!hasAny) { return 1; } - var sort = await (await GetQueryableAsync()).MaxAsync(x => x.Sort); + 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) + /// <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<WmsArea>> GetListAsync(FunReturnResultModel<Expression<Func<WmsArea, bool>>> whereConditions, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, 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)) - .OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsArea.Sort) : sorting) + .WhereIf(whereConditions != null, whereConditions.data) + .Where(x => !x.IsDeleted) + .OrderByDescending(x => x.CreationTime) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } - /// <inheritdoc /> - public async Task<long> GetCountAsync(string filter = null, Specification<WmsArea> specification = null, CancellationToken cancellationToken = default) + /// <summary> + /// 获取总数仓库信息 + /// </summary> + /// <param name="whereConditions"></param> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<WmsArea, bool>>> whereConditions, CancellationToken cancellationToken = default) { - specification ??= new WmsAreaSpecification(); return await (await GetQueryableAsync()) - .Where(specification.ToExpression()) - .WhereIf(!filter.IsNullOrWhiteSpace(), u => u.AreaNo.Contains(filter)) + .WhereIf(whereConditions != null, whereConditions.data) + .Where(x => !x.IsDeleted) .CountAsync(cancellationToken: GetCancellationToken(cancellationToken)); } + + /// <summary> + /// 获取库区列表 + /// </summary> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public async Task<List<WmsArea>> GetListForSelectAsync(CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(x => !x.IsDeleted) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + /// <inheritdoc /> + //public async Task<long> GetCountAsync(WmsArea? area, 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)) + // .WhereIf(!string.IsNullOrEmpty(area.AreaNo), u => u.AreaNo.Contains(area.AreaNo)) + // .WhereIf(!string.IsNullOrEmpty(area.AreaName), u => u.AreaNo.Contains(area.AreaName)) + // .WhereIf(!string.IsNullOrEmpty(area.StoreCode), u => u.AreaNo == area.StoreCode) + // .WhereIf(area.AreaStatus > 0, u => u.AreaStatus == area.AreaStatus) + // .WhereIf(area.AreaType > 0, u => u.AreaType == area.AreaType) + // .Where(x => !x.IsDeleted) + // .CountAsync(cancellationToken: GetCancellationToken(cancellationToken)); + //} /// <inheritdoc /> public override async Task<IQueryable<WmsArea>> WithDetailsAsync() { - return (await GetQueryableAsync()).IncludeDetails(); + return (await GetQueryableAsync()).Where(x => !x.IsDeleted).IncludeDetails(); } } -- Gitblit v1.9.3