From 5a149d626ae8bc3fa4bddbb53f8caf40f51f6da6 Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周三, 04 6月 2025 17:42:13 +0800
Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo

---
 Weben_CMS专用代码生成器/Code/Templete/EntityFrameworkCore/EfCoreRepository模板.txt |  131 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 118 insertions(+), 13 deletions(-)

diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/EntityFrameworkCore/EfCoreRepository\346\250\241\346\235\277.txt" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/EntityFrameworkCore/EfCoreRepository\346\250\241\346\235\277.txt"
index c355d6a..efb086b 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/EntityFrameworkCore/EfCoreRepository\346\250\241\346\235\277.txt"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/EntityFrameworkCore/EfCoreRepository\346\250\241\346\235\277.txt"
@@ -1,9 +1,10 @@
-using CMS.Plugin.$NameSpacePath$.Domain.$EntityName$;
+锘縰sing CMS.Plugin.$NameSpacePath$.Domain.$EntityName$;
 using CMS.Plugin.$NameSpacePath$.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;
 
@@ -11,7 +12,7 @@
 namespace CMS.Plugin.$NameSpacePath$.EntityFrameworkCore.Repositories;
 
 /// <summary>
-/// $ChinaComment$仓储实现
+/// $ChinaComment$浠撳偍瀹炵幇
 /// </summary>
 public class EfCore$EntityName$Repository : EfCoreRepository<ICMSPluginDbContext, $EntityName$, Guid>, I$EntityName$Repository
 {
@@ -25,7 +26,7 @@
     }
 
     /// <summary>
-    /// 按照名称查找$ChinaComment$
+    /// 鎸夌収鍚嶇О鏌ユ壘$ChinaComment$
     /// </summary>
     /// <param name="name"></param>
     /// <param name="cancellationToken"></param>
@@ -35,23 +36,23 @@
         return await (await GetDbSetAsync())
             .IncludeDetails()
             .Where(x => !x.IsDeleted)
-            .OrderBy(t => t.Sort)
-            .FirstOrDefaultAsync(t => t.MaterialCode == name, GetCancellationToken(cancellationToken));
+            .OrderByDescending(x=>x.$OrderBy$) 
+            .FirstOrDefaultAsync(t => t.$ValidateRepeatName$ == name, GetCancellationToken(cancellationToken));
     }
 
     /// <summary>
-    /// 验证名称是否存在$ChinaComment$
+    /// 楠岃瘉鍚嶇О鏄惁瀛樺湪$ChinaComment$
     /// </summary>
-    /// <param name="materialCode"></param>
+    /// <param name="name">鏍¢獙鍊�</param>
     /// <param name="id"></param>
     /// <returns></returns>
-    public async Task<bool> NameExistAsync(string materialCode, Guid? id = null)
+    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.MaterialCode == materialCode);
+        return await (await GetDbSetAsync()).WhereIf(id.HasValue, p => p.Id != id).Where(x => !x.IsDeleted).AnyAsync(x => x.$ValidateRepeatName$ == name);
     }
 
     /// <summary>
-    /// 获取最大排序$ChinaComment$
+    /// 鑾峰彇鏈�澶ф帓搴�$ChinaComment$
     /// </summary>
     /// <returns></returns>
     public async Task<int> GetMaxSortAsync()
@@ -69,7 +70,7 @@
     }
 
     /// <summary>
-    /// 获取分页列表$ChinaComment$
+    /// 鑾峰彇鍒嗛〉鍒楄〃$ChinaComment$
     /// </summary>
     /// <param name="whereConditions"></param>
     /// <param name="sorting"></param>
@@ -84,13 +85,13 @@
             .IncludeDetails(includeDetails)
             .WhereIf(whereConditions != null, whereConditions.data)
             .Where(x => !x.IsDeleted)
-            .OrderBy(sorting.IsNullOrEmpty() ? nameof($EntityName$.Sort) : sorting)
+            .OrderByDescending(x=>x.$OrderBy$)
             .PageBy(skipCount, maxResultCount)
             .ToListAsync(GetCancellationToken(cancellationToken));
     }
 
     /// <summary>
-    /// 获取总数$ChinaComment$
+    /// 鑾峰彇鎬绘暟$ChinaComment$
     /// </summary>
     /// <param name="whereConditions"></param>
     /// <param name="cancellationToken"></param>
@@ -110,4 +111,108 @@
         return (await GetQueryableAsync())
             .Where(x => !x.IsDeleted).IncludeDetails();
     }
+
+    /// <summary>
+    /// 鐗╃悊鍒犻櫎$ChinaComment$
+    /// </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($EntityName$), id);
+        }
+
+        // 2. 鑾峰彇 DbContext 骞舵墽琛屽垹闄�
+        var dbContext = await GetDbContextAsync();
+
+        // 鐩存帴鎵ц SQL 鍒犻櫎
+        var sql = $"DELETE FROM $TableName$ WHERE Id ='{entity.Id.ToString()}'";
+        await dbContext.Database.ExecuteSqlRawAsync(sql, cancellationToken);
+    }
+
+    /// <summary>
+    /// 鎵归噺鐗╃悊鍒犻櫎$ChinaComment$锛堢洿鎺ュ垹闄わ紝涓嶈蒋鍒犻櫎锛�
+    /// </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 $TableName$ WHERE Id IN ({string.Join(",", idsToDelete.Select(id => $"'{id}'"))})";
+        await dbContext.Database.ExecuteSqlRawAsync(sql, cancellationToken);
+    }
+
+    /// <summary>
+    /// 鏍规嵁鏉′欢鑾峰彇$ChinaComment$鍒楄〃
+    /// </summary>
+    /// <param name="whereConditions"></param>
+    /// <param name="cancellationToken"></param>
+    /// <returns></returns>
+    public async Task<List<$EntityName$>> GetListByFilterAsync(Expression<Func<$EntityName$, bool>> whereConditions, CancellationToken cancellationToken = default)
+    {
+        return await (await GetDbSetAsync())
+            .IncludeDetails()
+            .WhereIf(whereConditions != null, whereConditions)
+            .Where(x => !x.IsDeleted)
+            .OrderByDescending(x => x.$OrderBy$)
+            .ToListAsync(GetCancellationToken(cancellationToken));
+    }
+
+    /// <summary>
+    ///  鏍规嵁鏉′欢鑾峰彇鍗曚釜$ChinaComment$
+    /// </summary>
+    /// <param name="whereConditions"></param>
+    /// <param name="isMultipleThrowException">鏄惁鏌ヨ鍑哄鏉″氨鎶ラ敊</param>
+    /// <param name="cancellationToken"></param>
+    /// <returns></returns>
+    /// <exception cref="UserFriendlyException"></exception>
+    public async Task<$EntityName$> GetSingleByFilterAsync(Expression<Func<$EntityName$, 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.$OrderBy$)
+                .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.$OrderBy$)
+                .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
+        }
+    }
 }

--
Gitblit v1.9.3