From 874ddf20325b535872488905caa648beaf9ff024 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周三, 14 5月 2025 14:07:17 +0800 Subject: [PATCH] 管件提交 --- PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs index caade5e..bc81213 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs +++ b/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鈥婱ultipleThrowException = false, CancellationToken cancellationToken = default) + { + if (is鈥婱ultipleThrowException) + { + 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)); + } + } } -- Gitblit v1.9.3