Compare commits
No commits in common. "57f7b29cc782e97c17b0cf571ac17c6091375858" and "955fe25d30e2d0b4f4082aca0a6b031cbf8cefdf" have entirely different histories.
57f7b29cc7
...
955fe25d30
|
|
@ -23,7 +23,6 @@ using IRaCIS.Core.Application.Contracts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
|
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
using EFCore.BulkExtensions;
|
|
||||||
namespace IRaCIS.Core.Application.Service;
|
namespace IRaCIS.Core.Application.Service;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -235,60 +234,6 @@ public class AuditDocumentService(IRepository<AuditDocument> _auditDocumentRepos
|
||||||
|
|
||||||
#region 闭包修改
|
#region 闭包修改
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// GPT 移动子树代码--适合一次提交事务
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="subtreeRootId"></param>
|
|
||||||
/// <param name="newParentId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task MoveSubtreeAsync(Guid subtreeRootId, Guid? newParentId)
|
|
||||||
{
|
|
||||||
|
|
||||||
// 1. 子树所有闭包关系(后代包含自身)
|
|
||||||
var subtreeClosures = await _auditDocumentClosureRepository
|
|
||||||
.Where(c => c.AncestorId == subtreeRootId)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var descendantIdsQuery = _auditDocumentClosureRepository
|
|
||||||
.Where(c => c.AncestorId == subtreeRootId).Select(c => c.DescendantId);
|
|
||||||
|
|
||||||
// 2. 删除原有祖先关系,保留自反关系和子树内部关系
|
|
||||||
await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(c =>
|
|
||||||
descendantIdsQuery.Contains(c.DescendantId) &&
|
|
||||||
c.AncestorId != c.DescendantId && // 保留自反关系
|
|
||||||
!descendantIdsQuery.Contains(c.AncestorId) // 保留子树内部关系
|
|
||||||
);
|
|
||||||
|
|
||||||
// 3. 查新父节点祖先
|
|
||||||
var newParentClosures = newParentId.HasValue
|
|
||||||
? await _auditDocumentClosureRepository
|
|
||||||
.Where(c => c.DescendantId == newParentId.Value)
|
|
||||||
.ToListAsync()
|
|
||||||
: new List<AuditDocumentClosure>();
|
|
||||||
|
|
||||||
// 4. 生成新关系
|
|
||||||
var newClosures = new List<AuditDocumentClosure>();
|
|
||||||
|
|
||||||
foreach (var pc in newParentClosures)
|
|
||||||
{
|
|
||||||
foreach (var sc in subtreeClosures)
|
|
||||||
{
|
|
||||||
newClosures.Add(new AuditDocumentClosure
|
|
||||||
{
|
|
||||||
AncestorId = pc.AncestorId,
|
|
||||||
DescendantId = sc.DescendantId,
|
|
||||||
Depth = pc.Depth + sc.Depth + 1 //深度公式:新深度 = 父祖先深度 + 子树原深度 + 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 插入新关系
|
|
||||||
await _auditDocumentClosureRepository.AddRangeAsync(newClosures);
|
|
||||||
await _auditDocumentClosureRepository.SaveChangesAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 插入闭包表关系
|
/// 插入闭包表关系
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -655,17 +600,6 @@ public class AuditDocumentService(IRepository<AuditDocument> _auditDocumentRepos
|
||||||
throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]);
|
throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 不考虑文件名重复 移动子树快速方法
|
|
||||||
//foreach (var item in inDto.Ids)
|
|
||||||
//{
|
|
||||||
// var subtreeRoot = await _auditDocumentRepository.FirstOrDefaultAsync(t => t.Id == item);
|
|
||||||
|
|
||||||
// subtreeRoot.ParentId = inDto.ParentId;
|
|
||||||
|
|
||||||
// await MoveSubtreeAsync(item, inDto.ParentId);
|
|
||||||
//}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
// 不能自动到自己父类这个文件夹
|
// 不能自动到自己父类这个文件夹
|
||||||
if (await _auditDocumentRepository.AnyAsync(x => x.ParentId == inDto.ParentId && inDto.Ids.Contains(x.Id)))
|
if (await _auditDocumentRepository.AnyAsync(x => x.ParentId == inDto.ParentId && inDto.Ids.Contains(x.Id)))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue