From 847e7a89974cb6f5bcfbf7fc8fbe84f085502af6 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周日, 11 5月 2025 15:41:44 +0800 Subject: [PATCH] 222 --- PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs | 163 ++++++++++++++++++++++++++++++------------------------ 1 files changed, 90 insertions(+), 73 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 cf8294f..caade5e 100644 --- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs +++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs @@ -1,73 +1,90 @@ -using CMS.Plugin.PipeLineLems.Domain.WorkPlan; -using CMS.Plugin.PipeLineLems.EntityFrameworkCore.Extensions; -using CmsQueryExtensions.Extension; -using Microsoft.EntityFrameworkCore; -using System.Linq.Dynamic.Core; -using System.Linq.Expressions; -using Volo.Abp.Domain.Repositories.EntityFrameworkCore; -using Volo.Abp.EntityFrameworkCore; - - -namespace CMS.Plugin.PipeLineLems.EntityFrameworkCore.Repositories; - +using CMS.Plugin.PipeLineLems.Domain.WorkPlan; +using CMS.Plugin.PipeLineLems.EntityFrameworkCore.Extensions; +using CmsQueryExtensions.Extension; +using Microsoft.EntityFrameworkCore; +using System.Linq.Dynamic.Core; +using System.Linq.Expressions; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + + +namespace CMS.Plugin.PipeLineLems.EntityFrameworkCore.Repositories; + /// <summary> /// 浣滀笟璁″垝琛ㄤ粨鍌ㄥ疄鐜� /// </summary> -public class EfCoreWorkPlanRepository : EfCoreRepository<ICMSPluginDbContext, WorkPlan, Guid>, IWorkPlanRepository -{ +public class EfCoreWorkPlanRepository : EfCoreRepository<ICMSPluginDbContext, WorkPlan, Guid>, IWorkPlanRepository +{ /// <summary> /// Initializes a new instance of the <see cref="EfCoreWorkPlanRepository"/> class. /// </summary> /// <param name="dbContextProvider">The database context provider.</param> - public EfCoreWorkPlanRepository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider) - : base(dbContextProvider) - { - } - + public EfCoreWorkPlanRepository(IDbContextProvider<ICMSPluginDbContext> dbContextProvider) + : base(dbContextProvider) + { + } + /// <summary> /// 鎸夌収鍚嶇О鏌ユ壘浣滀笟璁″垝琛� /// </summary> /// <param name="name"></param> /// <param name="cancellationToken"></param> /// <returns></returns> - public virtual async Task<WorkPlan> FindByNameAsync(string name, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails() - .Where(x => !x.IsDeleted) - .OrderByDescending(x=>x.CreationTime) - .FirstOrDefaultAsync(t => t.TaskCode == name, GetCancellationToken(cancellationToken)); - } - + public virtual async Task<WorkPlan> FindByNameAsync(string name, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails() + .Where(x => !x.IsDeleted) + .OrderByDescending(x => x.CreationTime) + .FirstOrDefaultAsync(t => t.TaskCode == name, GetCancellationToken(cancellationToken)); + } + + + /// <summary> + /// 鎸夌収 鍘熸枡鏍囪 鏌ユ壘浣滀笟璁″垝琛� + /// </summary> + /// <param name="name"></param> + /// <param name="cancellationToken"></param> + /// <returns></returns> + public virtual async Task<List<WorkPlan>> FindByDataIdentifierAsync(string dataIdentifier, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails() + .Where(x => !x.IsDeleted) + .Where(t => t.DataIdentifier == dataIdentifier) + .OrderByDescending(x => x.CreationTime) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + /// <summary> /// 楠岃瘉鍚嶇О鏄惁瀛樺湪浣滀笟璁″垝琛� /// </summary> /// <param name="name">鏍¢獙鍊�</param> /// <param name="id"></param> /// <returns></returns> - public async Task<bool> NameExistAsync(string name, Guid? id = null) - { - return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.TaskCode == name); - } - + public async Task<bool> NameExistAsync(string name, Guid? id = null) + { + return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.TaskCode == name); + } + /// <summary> /// 鑾峰彇鏈�澶ф帓搴忎綔涓氳鍒掕〃 /// </summary> /// <returns></returns> - public async Task<int> GetMaxSortAsync() - { - var hasAny = await (await GetQueryableAsync()) - .Where(x => !x.IsDeleted).AnyAsync(); - if (!hasAny) - { - return 1; - } - - var sort = await (await GetQueryableAsync()) - .Where(x => !x.IsDeleted).MaxAsync(x => x.Sort); - return sort + 1; - } - + public async Task<int> GetMaxSortAsync() + { + var hasAny = await (await GetQueryableAsync()) + .Where(x => !x.IsDeleted).AnyAsync(); + if (!hasAny) + { + return 1; + } + + var sort = await (await GetQueryableAsync()) + .Where(x => !x.IsDeleted).MaxAsync(x => x.Sort); + return sort + 1; + } + /// <summary> /// 鑾峰彇鍒嗛〉鍒楄〃浣滀笟璁″垝琛� /// </summary> @@ -78,36 +95,36 @@ /// <param name="includeDetails"></param> /// <param name="cancellationToken"></param> /// <returns></returns> - public async Task<List<WorkPlan>> GetListAsync(FunReturnResultModel<Expression<Func<WorkPlan, 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) - .OrderByDescending(x=>x.CreationTime) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } - + public async Task<List<WorkPlan>> GetListAsync(FunReturnResultModel<Expression<Func<WorkPlan, 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) + .OrderByDescending(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> GetCountAsync(FunReturnResultModel<Expression<Func<WorkPlan, bool>>> whereConditions, CancellationToken cancellationToken = default) - { - return await (await GetQueryableAsync()) - .WhereIf(whereConditions != null, whereConditions.data) - .Where(x => !x.IsDeleted) - .CountAsync(cancellationToken: GetCancellationToken(cancellationToken)); - } - - + public async Task<long> GetCountAsync(FunReturnResultModel<Expression<Func<WorkPlan, 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<WorkPlan>> WithDetailsAsync() - { - return (await GetQueryableAsync()) - .Where(x => !x.IsDeleted).IncludeDetails(); - } -} + public override async Task<IQueryable<WorkPlan>> WithDetailsAsync() + { + return (await GetQueryableAsync()) + .Where(x => !x.IsDeleted).IncludeDetails(); + } +} -- Gitblit v1.9.3