| | |
| | | using System.Linq.Dynamic.Core; |
| | | using System.Linq.Expressions; |
| | | using CMS.Plugin.HIAWms.Domain.WmsMaterialStocks; |
| | | using CMS.Plugin.HIAWms.Domain.WmsTask; |
| | | using CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions; |
| | | using CmsQueryExtensions.Extension; |
| | | using DatabaseSchemaReader.Filters; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using SqlKata; |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<List<WmsMaterialStock>> GetListAsync(WmsMaterialStock? stock, DateTime? startTime = null, DateTime? endTime = null, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, string filter = null, Specification<WmsMaterialStock> specification = null, bool includeDetails = false, CancellationToken cancellationToken = default) |
| | | public async Task<List<WmsMaterialStock>> GetListAsync(FunReturnResultModel<Expression<Func<WmsMaterialStock, bool>>> whereConditions, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, bool includeDetails = false, CancellationToken cancellationToken = default) |
| | | { |
| | | specification ??= new WmsMaterialStockSpecification(); |
| | | var baseQuery = (await GetDbSetAsync()) |
| | | .IncludeDetails(includeDetails) |
| | | .WhereIf(!filter.IsNullOrWhiteSpace(), |
| | | u => u.MaterialNo.Contains(filter) || |
| | | u.MaterialName.Contains(filter) || |
| | | u.MaterialBatch.Contains(filter) || |
| | | u.PlaceNo.Contains(filter) || |
| | | u.AreaName.Contains(filter)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialNo), u => u.MaterialNo.Contains(stock.MaterialNo)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialName), u => u.MaterialName.Contains(stock.MaterialName)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.ContainerNo), u => u.ContainerNo == stock.ContainerNo) |
| | | .WhereIf(stock?.ContainerStatus > 0, u => u.ContainerStatus == stock.ContainerStatus) |
| | | .WhereIf(stock?.ContainerType > 0, u => u.ContainerType == stock.ContainerType) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialBatch), u => u.MaterialBatch == stock.MaterialBatch) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.SupplierCode), u => u.SupplierCode == stock.SupplierCode) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialModel), u => u.MaterialModel.Contains(stock.MaterialModel)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.PlaceNo), u => u.PlaceNo == stock.PlaceNo) |
| | | .WhereIf(stock.PlaceStatus > 0, u => u.PlaceStatus == stock.PlaceStatus) |
| | | .WhereIf(stock?.StorageTypeNo > 0, u => u.StorageTypeNo == stock.StorageTypeNo) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.AreaCode), u => u.AreaCode == stock.AreaCode) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.AreaName), u => u.AreaName.Contains(stock.AreaName)) |
| | | .WhereIf(stock.IsLock > 0, u => u.IsLock == stock.IsLock) |
| | | .WhereIf(startTime.HasValue, u => u.InStockTime >= startTime.Value) |
| | | .WhereIf(endTime.HasValue, u => u.InStockTime <= endTime.Value) |
| | | .IncludeDetails(includeDetails).WhereIf(whereConditions != null, whereConditions.data) |
| | | .Where(u => !u.IsDeleted) |
| | | .AsQueryable(); |
| | | |
| | |
| | | .ToListAsync(GetCancellationToken(cancellationToken)); |
| | | |
| | | var groupedData = materialList |
| | | .GroupBy(x => new { x.MaterialNo, x.PlaceNo, x.ContainerNo}) |
| | | .GroupBy(x => new { x.MaterialNo, x.PlaceNo, x.ContainerNo,x.MaterialModel}) |
| | | .Select(g => new WmsMaterialStock |
| | | { |
| | | MaterialNo = g.Key.MaterialNo, |
| | |
| | | PlaceStatus = g.First().PlaceStatus, |
| | | StorageTypeNo = g.First().StorageTypeNo, |
| | | MaterialBatch = g.First().MaterialBatch, |
| | | MaterialModel = g.First().MaterialModel, |
| | | MaterialModel = g.Key.MaterialModel, |
| | | AreaCode = g.First().AreaCode, |
| | | AreaName = g.First().AreaName, |
| | | CheckStatus = g.First().CheckStatus, |
| | |
| | | .AsQueryable(); // 转换回IQueryable以支持后续操作 |
| | | |
| | | var result = groupedData |
| | | .OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsMaterialStock.Sort) : sorting) |
| | | .OrderBy(x=>x.StockNumber) |
| | | .PageBy(skipCount, maxResultCount) |
| | | .ToList(); |
| | | |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<long> GetCountAsync(WmsMaterialStock? stock, DateTime? startTime = null, DateTime? endTime = null, string filter = null, Specification<WmsMaterialStock> specification = null, CancellationToken cancellationToken = default) |
| | | public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<WmsMaterialStock, bool>>> whereConditions, CancellationToken cancellationToken = default) |
| | | { |
| | | specification ??= new WmsMaterialStockSpecification(); |
| | | var baseQuery = (await GetQueryableAsync()) |
| | | .WhereIf(!filter.IsNullOrWhiteSpace(), |
| | | u => u.MaterialNo.Contains(filter) || |
| | | u.MaterialName.Contains(filter) || |
| | | u.MaterialBatch.Contains(filter) || |
| | | u.PlaceNo.Contains(filter) || |
| | | u.AreaName.Contains(filter)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialNo), u => u.MaterialNo.Contains(stock.MaterialNo)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialName), u => u.MaterialName.Contains(stock.MaterialName)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.ContainerNo), u => u.ContainerNo == stock.ContainerNo) |
| | | .WhereIf(stock?.ContainerStatus > 0, u => u.ContainerStatus == stock.ContainerStatus) |
| | | .WhereIf(stock?.ContainerType > 0, u => u.ContainerType == stock.ContainerType) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialBatch), u => u.MaterialBatch == stock.MaterialBatch) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.SupplierCode), u => u.SupplierCode == stock.SupplierCode) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.MaterialModel), u => u.MaterialModel.Contains(stock.MaterialModel)) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.PlaceNo), u => u.PlaceNo == stock.PlaceNo) |
| | | .WhereIf(stock.PlaceStatus > 0, u => u.PlaceStatus == stock.PlaceStatus) |
| | | .WhereIf(stock?.StorageTypeNo > 0, u => u.StorageTypeNo == stock.StorageTypeNo) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.AreaCode), u => u.AreaCode == stock.AreaCode) |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.AreaName), u => u.AreaName.Contains(stock.AreaName)) |
| | | .WhereIf(stock.IsLock > 0, u => u.IsLock == stock.IsLock) |
| | | .WhereIf(startTime.HasValue, u => u.InStockTime >= startTime.Value) |
| | | .WhereIf(endTime.HasValue, u => u.InStockTime <= endTime.Value) |
| | | .WhereIf(whereConditions != null, whereConditions.data) |
| | | .Where(u => !u.IsDeleted) |
| | | .AsQueryable(); |
| | | |
| | |
| | | .WhereIf(!string.IsNullOrEmpty(stock?.AreaName), u => u.AreaName.Contains(stock.AreaName)) |
| | | .WhereIf(stock.IsLock > 0, u => u.IsLock == stock.IsLock) |
| | | .Where(u => !u.IsDeleted) |
| | | .OrderByDescending(x=>x.InStockTime) |
| | | .ToListAsync(); |
| | | return baseQuery; |
| | | } |
| | | |
| | | /// <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<WmsMaterialStock>> GetStockDetailListAsync(FunReturnResultModel<Expression<Func<WmsMaterialStock, 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(x=>x.PlaceNo) |
| | | .ThenByDescending(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> GetDetailCountAsync(FunReturnResultModel<Expression<Func<WmsMaterialStock, 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<WmsMaterialStock>> WithDetailsAsync() |
| | | { |