| | |
| | | using System; |
| | | using System.Linq.Dynamic.Core; |
| | | using CMS.Plugin.HIAWms.Domain.WmsAreas; |
| | | using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions; |
| | | using DatabaseSchemaReader.Filters; |
| | | using MathNet.Numerics; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
| | | using Volo.Abp.EntityFrameworkCore; |
| | |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | /// <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) |
| | | public async Task<List<WmsArea>> GetListAsync(WmsArea? area, 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)) |
| | | .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) |
| | | .OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsArea.Sort) : sorting) |
| | | .PageBy(skipCount, maxResultCount) |
| | | .ToListAsync(GetCancellationToken(cancellationToken)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取库区列表 |
| | | /// </summary> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<List<WmsArea>> GetListForSelectAsync(CancellationToken cancellationToken = default) |
| | | { |
| | | return await (await GetDbSetAsync()) |
| | | .ToListAsync(GetCancellationToken(cancellationToken)); |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<long> GetCountAsync(string filter = null, Specification<WmsArea> specification = null, CancellationToken cancellationToken = default) |
| | | 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(); |
| | | } |
| | | } |