From 1095e07f87819a6b65ec6a4376fe84fa6e83d4da Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 29 Sep 2025 10:09:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=88=E6=9D=83=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Document/AuditDocumentService.cs | 123 +++++++++++------- 1 file changed, 78 insertions(+), 45 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs index 6dff69420..2ed2fdb03 100644 --- a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs @@ -53,7 +53,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos var isAdminOrQA = _userInfo.UserTypeEnumInt == (int)UserTypeEnum.Admin || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.QA; - var auditRecordQueryable = _auditRecordRepository.Where(t => t.BeginTime < dateTimeNow && t.EndTime > dateTimeNow) + var auditRecordQueryable = _auditRecordRepository.Where(t => t.BeginTime < dateTimeNow && t.EndTime > dateTimeNow) //过滤查看用户 .WhereIf(isAdminOrQA == false, t => t.AuditRecordIdentityUserList.Any(t => t.IdentityUserId == _userInfo.IdentityUserId)) .WhereIf(inQuery.BeginAuditTime != null, t => t.AuditTime >= inQuery.BeginAuditTime) @@ -361,16 +361,30 @@ public class AuditDocumentService(IRepository _auditDocumentRepos [HttpPost] public async Task SetIsAuthorization(SetIsAuthorizationInDto inDto) { - //闭包表中找到 设置Id为祖先的所有 后代 包括自己 - var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); + if (inDto.IsAuthorization) + { - //闭包表中找到 设置Id为后代的所有 祖先 包括自己 - var matchIdQuery2 = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.DescendantId)).Select(t => t.AncestorId); + //闭包表中找到 设置Id为祖先的所有 后代 包括自己 + var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); + + //闭包表中找到 设置Id为后代的所有 祖先 包括自己 + var matchIdQuery2 = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.DescendantId)).Select(t => t.AncestorId); - var unionQuery = matchIdQuery.Union(matchIdQuery2); + var unionQuery = matchIdQuery.Union(matchIdQuery2); - await _auditDocumentRepository.BatchUpdateNoTrackingAsync(t => unionQuery.Contains(t.Id), u => new AuditDocument() { IsAuthorization = inDto.IsAuthorization }); + await _auditDocumentRepository.BatchUpdateNoTrackingAsync(t => unionQuery.Contains(t.Id), u => new AuditDocument() { IsAuthorization = inDto.IsAuthorization }); + + } + else + { + //闭包表中找到 设置Id为祖先的所有 后代 包括自己 + var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); + + await _auditDocumentRepository.BatchUpdateNoTrackingAsync(t => matchIdQuery.Contains(t.Id), u => new AuditDocument() { IsAuthorization = inDto.IsAuthorization }); + + + } return ResponseOutput.Ok(); @@ -378,44 +392,6 @@ public class AuditDocumentService(IRepository _auditDocumentRepos - /// - /// 移动文件或者文件夹 到其他文件夹 - /// - /// - [HttpPost] - public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) - { - - //闭包表中找到 设置Id为祖先的所有 后代 包括自己 - var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); - - //无法将当前文件夹移动到当前目录以及子文件夹 - - if (matchIdQuery.Any(t => t == inDto.ParentId)) - { - throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]); - } - - foreach (var id in inDto.Ids) - { - - //移动ParentId - var node = await _auditDocumentRepository.FirstOrDefaultAsync(t => t.Id == id); - - node.ParentId = inDto.ParentId; - await _auditDocumentRepository.SaveChangesAsync(); - - - // 删除原有闭包关系 - await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => t.DescendantId == id || t.AncestorId == id); - - //建立新的闭包关系 - await AddClosureRelationsAsync(node.Id, inDto.ParentId); - - } - - return ResponseOutput.Ok(); - } /// @@ -592,6 +568,63 @@ public class AuditDocumentService(IRepository _auditDocumentRepos #region 闭包维护关系,只处理最底层调用 AddOrUpdateAuditDocument + + + /// + /// 移动文件或者文件夹 到其他文件夹 + /// + /// + [HttpPost] + public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) + { + + //闭包表中找到 设置Id为祖先的所有 后代 包括自己 + var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); + + //无法将当前文件夹移动到当前目录以及子文件夹 + + if (matchIdQuery.Any(t => t == inDto.ParentId)) + { + throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]); + } + + foreach (var id in inDto.Ids) + { + var node = await _auditDocumentRepository.FirstOrDefaultAsync(t => t.Id == id); + + //找到设置父节点的儿子节点 + var existSameName = await _auditDocumentClosureRepository + .Where(t => t.AncestorId == inDto.ParentId && t.Depth == 1) + .Select(t => t.Descendant).AnyAsync(t => t.Name == node.Name && t.AuditDocumentTypeEnum == node.AuditDocumentTypeEnum); + + //不存在同名节点,那么直接移动 + if (!existSameName) + { + //移动ParentId + + + node.ParentId = inDto.ParentId; + + await _auditDocumentRepository.SaveChangesAsync(); + + + // 删除原有闭包关系 + await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => matchIdQuery.Contains(t.DescendantId) || matchIdQuery.Contains(t.AncestorId)); + + + //建立新的节点的闭包关系 + await AddClosureRelationsAsync(node.Id, inDto.ParentId); + + //建立新的节点后的子孙后代闭包关系 不包括自己 + + //var chai _auditDocumentClosureRepository.Where(t => t.AncestorId == id && t.Depth > 0).OrderBy(t => t.Depth).Select(t => t.DescendantId); + + } + } + + return ResponseOutput.Ok(); + } + /// /// 复制文件或者文件夹 ///