From 9796651f30deb9eee38c9d846255b293fbba15eb Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周五, 16 5月 2025 09:26:55 +0800
Subject: [PATCH] 333

---
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs |  292 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 164 insertions(+), 128 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 bc81213..47f6228 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreWorkPlanRepository.cs
@@ -1,91 +1,74 @@
-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;
-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; 
+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));
-    }
-
-
-    /// <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));
-    }
-
+    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="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> 
@@ -96,55 +79,108 @@
     /// <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(); 
+    } 
+ 
+    /// <summary> 
+    /// 鐗╃悊鍒犻櫎浣滀笟璁″垝琛� 
+    /// </summary> 
+    /// <param name="id">涓婚敭ID</param> 
+    /// <param name="cancellationToken"></param> 
+    /// <returns></returns> 
+    public virtual async Task DeletePermanentlyAsync(Guid id, CancellationToken cancellationToken = default) 
+    { 
+        var entity = await (await GetDbSetAsync()) 
+            .FirstOrDefaultAsync(x => x.Id == id && !x.IsDeleted, GetCancellationToken(cancellationToken)); 
+ 
+        if (entity == null) 
+        { 
+            throw new Volo.Abp.Domain.Entities.EntityNotFoundException(typeof(WorkPlan), id); 
+        } 
+ 
+        // 2. 鑾峰彇 DbContext 骞舵墽琛屽垹闄� 
+        var dbContext = await GetDbContextAsync(); 
+ 
+        // 鐩存帴鎵ц SQL 鍒犻櫎 
+        var sql = $"DELETE FROM scms_workplans WHERE Id ='{entity.Id.ToString()}'"; 
+        await dbContext.Database.ExecuteSqlRawAsync(sql, cancellationToken); 
+    } 
+ 
+    /// <summary> 
+    /// 鎵归噺鐗╃悊鍒犻櫎浣滀笟璁″垝琛紙鐩存帴鍒犻櫎锛屼笉杞垹闄わ級 
+    /// </summary> 
+    /// <param name="ids">瑕佸垹闄ょ殑涓婚敭ID鍒楄〃</param> 
+    /// <param name="cancellationToken"></param> 
+    /// <returns></returns> 
+    public virtual async Task BatchDeletePermanentlyAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default) 
+    { 
+        // 1. 鏌ヨ绗﹀悎鏉′欢鐨勫疄浣擄紙鏈蒋鍒犻櫎鐨勮褰曪級 
+        var entities = await (await GetDbSetAsync()) 
+            .Where(x => ids.Contains(x.Id) && !x.IsDeleted) 
+            .ToListAsync(GetCancellationToken(cancellationToken)); 
+ 
+        if (!entities.Any()) 
+        { 
+            // 濡傛灉娌℃湁闇�瑕佸垹闄ょ殑璁板綍锛岀洿鎺ヨ繑鍥烇紙閬垮厤涓嶅繀瑕佺殑鏁版嵁搴撴搷浣滐級 
+            return; 
+        } 
+ 
+        // 2. 鑾峰彇 DbContext 骞舵墽琛屾壒閲忓垹闄� 
+        var dbContext = await GetDbContextAsync(); 
+ 
+        var idsToDelete = entities.Select(e => e.Id).ToList(); 
+ 
+        // 鐩存帴鎵ц SQL 鍒犻櫎 
+        var sql = $"DELETE FROM scms_workplans WHERE Id IN ({string.Join(",", idsToDelete.Select(id => $"'{id}'"))})"; 
+        await dbContext.Database.ExecuteSqlRawAsync(sql, cancellationToken); 
+    } 
+ 
     /// <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));
-    }
-
+    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> 
@@ -153,30 +189,30 @@
     /// <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));
-        }
-    }
-}
+    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