schangxiang@126.com
2025-05-14 874ddf20325b535872488905caa648beaf9ff024
PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.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;
@@ -127,4 +128,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<WorkPlan>> GetListByFilterAsync(Expression<Func<WorkPlan, 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<WorkPlan> GetSingleByFilterAsync(Expression<Func<WorkPlan, 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));
        }
    }
}