zs
2025-05-13 de4a3a2c1b39c128d4ecd23367db5fcbda957bdd
HIAWms/server/src/CMS.Plugin.HIAWms.EntityFrameworkCore/Repositories/EfCoreWmsMaterialStockRepository.cs
@@ -1,6 +1,9 @@
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;
@@ -88,7 +91,7 @@
        .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?.MaterialModel), u => u.MaterialModel==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)
@@ -123,7 +126,7 @@
        .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,
@@ -134,7 +137,7 @@
           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,
@@ -146,7 +149,7 @@
       .AsQueryable(); // 转换回IQueryable以支持后续操作
        var result = groupedData
        .OrderBy(sorting.IsNullOrEmpty() ? nameof(WmsMaterialStock.Sort) : sorting)
        .OrderBy(x=>x.StockNumber)
        .PageBy(skipCount, maxResultCount)
        .ToList();
@@ -253,9 +256,48 @@
       .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()
    {