zs
2025-05-16 5703aa1072175f4390006f73e43a4236e81ad678
PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs
@@ -4,6 +4,7 @@
using Microsoft.EntityFrameworkCore; 
using System.Linq.Dynamic.Core; 
using System.Linq.Expressions; 
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; 
using Volo.Abp.EntityFrameworkCore; 
 
@@ -119,4 +120,55 @@
        return (await GetQueryableAsync()) 
            .Where(x => !x.IsDeleted).IncludeDetails(); 
    } 
    /// <summary>
    /// 根据条件获取叫料单表列表
    /// </summary>
    /// <param name="whereConditions"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public async Task<List<CallMaterialOrder>> GetListByFilterAsync(Expression<Func<CallMaterialOrder, bool>> whereConditions, CancellationToken cancellationToken = default)
    {
        return await (await GetDbSetAsync())
            .IncludeDetails()
            .WhereIf(whereConditions != null, whereConditions)
            .Where(x => !x.IsDeleted)
            .OrderByDescending(x => x.CreationTime)
            .ToListAsync(GetCancellationToken(cancellationToken));
    }
    /// <summary>
    ///  根据条件获取单个叫料单表
    /// </summary>
    /// <param name="whereConditions"></param>
    /// <param name="isMultipleThrowException">是否查询出多条就报错</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException"></exception>
    public async Task<CallMaterialOrder> GetSingleByFilterAsync(Expression<Func<CallMaterialOrder, bool>> whereConditions, bool is​MultipleThrowException = false, CancellationToken cancellationToken = default)
    {
        if (is​MultipleThrowException)
        {
            var entitys = await (await GetDbSetAsync())
                .IncludeDetails()
                .WhereIf(whereConditions != null, whereConditions)
                .Where(x => !x.IsDeleted)
                .OrderByDescending(x => x.CreationTime)
                .ToListAsync(GetCancellationToken(cancellationToken));
            if (entitys?.Count > 1)
            {
                throw new UserFriendlyException("查询到多条记录");
            }
            return entitys?.FirstOrDefault();
        }
        else
        {
            return await (await GetDbSetAsync())
                .IncludeDetails()
                .WhereIf(whereConditions != null, whereConditions)
                .Where(x => !x.IsDeleted)
                .OrderByDescending(x => x.CreationTime)
                .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
        }
    }