From 1ad40156ec25db1b9d90c3f94819434e20d52b00 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周五, 16 5月 2025 13:12:45 +0800
Subject: [PATCH] 222

---
 PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs |  146 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 95 insertions(+), 51 deletions(-)

diff --git a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs
index da7e88a..3091f2b 100644
--- a/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs
+++ b/PipeLineLems/server/src/CMS.Plugin.PipeLineLems.EntityFrameworkCore/Repositories/EfCoreCallMaterialOrderRepository.cs
@@ -3,8 +3,8 @@
 using CmsQueryExtensions.Extension; 
 using Microsoft.EntityFrameworkCore; 
 using System.Linq.Dynamic.Core; 
-using System.Linq.Expressions;
-using Volo.Abp;
+using System.Linq.Expressions; 
+using Volo.Abp; 
 using Volo.Abp.Domain.Repositories.EntityFrameworkCore; 
 using Volo.Abp.EntityFrameworkCore; 
  
@@ -38,17 +38,8 @@
             .Where(x => !x.IsDeleted) 
             .OrderByDescending(x=>x.CreationTime)  
             .FirstOrDefaultAsync(t => t.DataIdentifier == name, GetCancellationToken(cancellationToken)); 
-    }
-
-    public virtual async Task<CallMaterialOrder> FindByWmsTaskNoAsync(string wmsTaskNo, CancellationToken cancellationToken = default)
-    {
-        return await (await GetDbSetAsync())
-            .IncludeDetails()
-            .Where(x => !x.IsDeleted)
-            .OrderByDescending(x => x.CreationTime)
-            .FirstOrDefaultAsync(t => t.WmsTaskNo == wmsTaskNo, GetCancellationToken(cancellationToken));
-    }
-
+    } 
+ 
     /// <summary> 
     /// 楠岃瘉鍚嶇О鏄惁瀛樺湪鍙枡鍗曡〃 
     /// </summary> 
@@ -119,24 +110,77 @@
     { 
         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(CallMaterialOrder), id); 
+        } 
+ 
+        // 2. 鑾峰彇 DbContext 骞舵墽琛屽垹闄� 
+        var dbContext = await GetDbContextAsync(); 
+ 
+        // 鐩存帴鎵ц SQL 鍒犻櫎 
+        var sql = $"DELETE FROM scms_callmaterialorders 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_callmaterialorders 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<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));
-    }
-
+    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> 
@@ -145,30 +189,30 @@
     /// <param name="cancellationToken"></param> 
     /// <returns></returns> 
     /// <exception cref="UserFriendlyException"></exception> 
-    public async Task<CallMaterialOrder> GetSingleByFilterAsync(Expression<Func<CallMaterialOrder, 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<CallMaterialOrder> GetSingleByFilterAsync(Expression<Func<CallMaterialOrder, 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