增加gpt 方法
parent
b835a028ad
commit
f55f498626
|
@ -23,6 +23,7 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,6 +235,60 @@ 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>
|
||||||
|
@ -600,6 +655,17 @@ 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
|
||||||
|
|
||||||
await CopyFileOrFolder(inDto);
|
await CopyFileOrFolder(inDto);
|
||||||
|
|
||||||
await DeleteAuditDocument(new DeleteAuditDocumentInDto()
|
await DeleteAuditDocument(new DeleteAuditDocumentInDto()
|
||||||
|
|
Loading…
Reference in New Issue