diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index d941bdda3..757570608 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -1522,34 +1522,34 @@ 插入闭包表关系 - + 获取文件树形结构 (传Id 根节点就是自己) - + 设置是否授权 - + 复制文件或者文件夹 - + 移动文件或者文件夹 到其他文件夹 - + 删除稽查文档 @@ -1569,21 +1569,6 @@ - - - 获取稽查文档 - - - - - - - - 获取历史版本 - - - - 修改稽查文档 @@ -1612,36 +1597,17 @@ - + - 删除稽查文档 + 获取稽查文档 - + + - + - 获取文件树形结构 (传Id 根节点就是自己) - - - - - - - 移动文件或者文件夹 到其他文件夹 - - - - - - 复制文件或者文件夹 - - - - - - - 设置是否授权 + 获取历史版本 diff --git a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs index 761618443..a769b27ca 100644 --- a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs @@ -22,6 +22,7 @@ using Microsoft.AspNetCore.Http; using IRaCIS.Core.Application.Contracts; using Microsoft.EntityFrameworkCore; using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; +using NPOI.SS.Formula.Functions; namespace IRaCIS.Core.Application.Service; @@ -239,7 +240,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos /// /// [HttpPost] - public async Task> GetAuditDocumentData_New(GetAuditDocumentDataInDto inDto) + public async Task> GetAuditDocumentData(GetAuditDocumentDataInDto inDto) { var defalutSortArray = new string[] { nameof(AuditDocumentData.AuditDocumentTypeEnum), nameof(AuditDocumentData.Name) }; @@ -252,7 +253,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos //匹配节点子查询 var matchedList = await _auditDocumentRepository.Where(x => x.AuditDocumentTypeEnum != AuditDocumentType.HistoricalVersion) .WhereIf(inDto.IsAuthorization != null, x => x.IsAuthorization == inDto.IsAuthorization) - .WhereIf(inDto.AuditRecordId != null, x => x.IsAuthorization == inDto.IsAuthorization) + .WhereIf(inDto.AuditRecordId != null, x => x.IsAuthorization == inDto.IsAuthorization) .WhereIf(inDto.Name.IsNotNullOrEmpty(), n => n.Name.Contains(inDto.Name)) .SelectMany(t => t.AncestorList).Select(t => t.Ancestor)//祖先包含自己 @@ -303,7 +304,11 @@ public class AuditDocumentService(IRepository _auditDocumentRepos parent.Children.Add(node); } - var query = dict.Values.Where(n => n.ParentId == null); + var query = dict.Values + .WhereIf(inDto.SelfId != null, x => inDto.SelfId == x.Id) + .WhereIf(inDto.Id != null, x => inDto.Id == x.ParentId) + .WhereIf(inDto.Id == null && inDto.SelfId == null, x => x.ParentId == null); + PageOutput result = new PageOutput() { @@ -328,7 +333,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos /// /// [HttpPost] - public async Task SetIsAuthorization_New(SetIsAuthorizationInDto inDto) + public async Task SetIsAuthorization(SetIsAuthorizationInDto inDto) { //闭包表中找到 设置Id为祖先的所有 后代 包括自己 var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); @@ -345,42 +350,14 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } - /// - /// 复制文件或者文件夹 - /// - /// - /// - [HttpPost] - public async Task CopyFileOrFolder_New(MovieFileOrFolderInDto inDto) - { - foreach (var id in inDto.Ids) - { - - //当前节点的后代(包括自己) 拷贝的节点以及子节点 - var nodeList = await _auditDocumentClosureRepository.Where(t => t.AncestorId == id).Select(t => t.Descendant).ToListAsync(); - - - foreach (var node in nodeList) - { - //设置新节点Id - node.Id = NewId.NextSequentialGuid(); - - //建立新的闭包关系 - await AddClosureRelationsAsync(node.Id, inDto.ParentId); - } - - } - - return ResponseOutput.Ok(); - } /// /// 移动文件或者文件夹 到其他文件夹 /// /// [HttpPost] - public async Task MovieFileOrFolder_New(MovieFileOrFolderInDto inDto) + public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) { //闭包表中找到 设置Id为祖先的所有 后代 包括自己 var matchIdQuery = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => t.DescendantId); @@ -402,9 +379,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos await _auditDocumentRepository.SaveChangesAsync(); - // 删除原有闭包关系 - await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => t.DescendantId == id || t.AncestorId == id); //建立新的闭包关系 @@ -422,31 +397,61 @@ public class AuditDocumentService(IRepository _auditDocumentRepos /// /// [HttpPost] - public async Task DeleteAuditDocument_New(DeleteAuditDocumentInDto inDto) + [UnitOfWork] + public async Task DeleteAuditDocument(DeleteAuditDocumentInDto inDto) { - //闭包表中找到 设置Id为祖先的所有 后代 包括自己 - var matchList = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => new { t.DescendantId, t.Descendant.MainFileId }); - //删除自己以及后代 - var success = await _auditDocumentRepository.DeleteFromQueryAsync(t => matchList.Select(t => t.DescendantId).Distinct().Contains(t.Id), true); + var isNotOptHistoryFile = _auditDocumentRepository.Where(t => inDto.Ids.Contains(t.Id)).All(t => t.MainFileId == null); - //找到有版本的 - var mainFileIdList = matchList.Where(t => t.MainFileId != null).ToList(); - - foreach (var item in mainFileIdList) + // 删除文件 或者文件夹里所有内容 (能在闭包表中找到) + if (isNotOptHistoryFile) { - var historicalVersionList = await _auditDocumentRepository.Where(x => x.MainFileId == item.MainFileId).OrderBy(x => x.Version).ToListAsync(); + //闭包表中找到 设置Id为祖先的所有 后代 包括自己 + var matchList = _auditDocumentClosureRepository.Where(t => inDto.Ids.Contains(t.AncestorId)).Select(t => new { t.DescendantId, t.Descendant.MainFileId, IsExistOldVersion = t.Descendant.AuditDocumentOldVersionList.Any() }); + + var matchIdList = matchList.Select(t => t.DescendantId).Distinct(); + + //找到有版本的 + var matchIdVersionList = matchList.Where(t => t.IsExistOldVersion).Select(t => t.DescendantId).Distinct(); + + + //删除自己以及后代 (能在闭包表中找到的,肯定不是删除 当前历史版本的操作 和当前历史所有版本的操作,能在闭包包中找到,那么肯定是删除当前文件,和当前文件所有 版本文件) + var success = await _auditDocumentRepository.DeleteFromQueryAsync(t => matchIdList.Contains(t.Id) || matchIdVersionList.Any(c => c == t.MainFileId)); + + + + // 删除原有闭包关系 + await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => matchIdList.Contains(t.DescendantId) || matchIdList.Contains(t.AncestorId)); - var num = 1; - foreach (var historical in historicalVersionList) - { - await _auditDocumentRepository.UpdatePartialFromQueryAsync(historical.Id, x => new AuditDocument() - { - Version = num, - }); - num++; - } } + else + { + //删除历史版本操作 删除当前历史所有版本操作 + + var mainFileIdList = await _auditDocumentRepository.Where(t => inDto.Ids.Contains(t.Id)).Select(t => t.MainFileId).Distinct().ToListAsync(); + + //删除当前选择的历史版本 + await _auditDocumentRepository.BatchDeleteNoTrackingAsync(t => inDto.Ids.Contains(t.Id)); + + + foreach (var item in mainFileIdList) + { + var historicalVersionList = await _auditDocumentRepository.Where(x => x.MainFileId == item).OrderBy(x => x.Version).ToListAsync(); + + var num = 1; + foreach (var historical in historicalVersionList) + { + await _auditDocumentRepository.UpdatePartialFromQueryAsync(historical.Id, x => new AuditDocument() + { + Version = num, + }); + num++; + } + } + + + } + await _auditDocumentRepository.SaveChangesAsync(); return ResponseOutput.Ok(); @@ -558,51 +563,112 @@ public class AuditDocumentService(IRepository _auditDocumentRepos #endregion - #region 增加闭包设计 不用修改地方 + #region 闭包维护关系,只处理最底层调用 AddOrUpdateAuditDocument /// - /// 获取稽查文档 - /// - /// - /// - /// - [HttpPost] - public async Task> GetAuditDocumentList(AuditDocumentQuery inQuery) - { - var auditDocumentQueryable = _auditDocumentRepository - .ProjectTo(_mapper.ConfigurationProvider); - var pageList = await auditDocumentQueryable.ToPagedListAsync(inQuery); - - return pageList; - } - - /// - /// 获取历史版本 + /// 复制文件或者文件夹 /// /// /// [HttpPost] - public async Task> GetHistoricalVersion(GetHistoricalVersionInDto inDto) + public async Task CopyFileOrFolder(MovieFileOrFolderInDto inDto) { - List result = new List(); + #region 不考虑版本的话处理方式 - result = await _auditDocumentRepository.Where(x => x.MainFileId == inDto.Id).ProjectTo(_mapper.ConfigurationProvider).OrderByDescending(x => x.Version).ToListAsync(); - var currentData = await _auditDocumentRepository.Where(x => x.Id == inDto.Id).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); - currentData.IsCurrentVersion = true; + ////1、当前节点的后代(包括自己) 拷贝的节点以及子节点 + //var nodeList = await _auditDocumentClosureRepository.Where(t => t.AncestorId == id).Select(t => t.Descendant).ToListAsync(); - result.Insert(0, currentData); + //// 2. 创建映射表 OldId -> NewId + //var oldToNewId = new Dictionary(); - return result; + //// 3. 复制节点 + + //var newNodeList = nodeList.Clone(); + + //foreach (var node in newNodeList) + //{ + // var newId = NewId.NextSequentialGuid(); + + // //存储旧Id 和新Id 关系 + // oldToNewId[node.Id] = newId; + + // //设置新节点Id + // node.Id = newId; + //} + + + //// 4. 调整 ParentId 指向新 Id + //foreach (var newNode in newNodeList) + //{ + // if (newNode.ParentId.HasValue && oldToNewId.TryGetValue(newNode.ParentId.Value, out var newParentId)) + // { + // newNode.ParentId = newParentId; // 指向新父节点 + // } + // else + // { + // newNode.ParentId = inDto.ParentId; // 顶层节点指向目标父节点 + // } + //} + + //foreach (var node in newNodeList) + //{ + + // await _auditDocumentRepository.AddAsync(node); + + // //建立新的闭包关系 + // await AddClosureRelationsAsync(node.Id, inDto.ParentId); + + //} + + #endregion + + foreach (var item in inDto.Ids) + { + var data = (await GetAuditDocumentData(new GetAuditDocumentDataInDto() + { + SelfId = item, + + PageIndex = 1, + PageSize = 1000 + })).CurrentPageData; + + List auditDocumentAddOrEdits = _mapper.Map>(data); + auditDocumentAddOrEdits.ForEach(x => + { + x.IsUpdate = false; + x.Id = null; + x.ParentId = inDto.ParentId; + }); + + await addData(auditDocumentAddOrEdits); + } + + async Task addData(List data) + { + foreach (var item in data) + { + item.Id = null; + var result = await AddOrUpdateAuditDocument(item); + + item.Children.ForEach(x => + { + x.ParentId = result.Id; + x.IsUpdate = false; + x.Id = null; + }); + + if (item.Children.Count() > 0) + { + await addData(item.Children); + } + } + } + + + return ResponseOutput.Ok(); } - - - #endregion - - #region 闭包维护关系,只处理最底层调用 AddOrUpdateAuditDocument - - /// /// 修改稽查文档 /// @@ -642,10 +708,6 @@ public class AuditDocumentService(IRepository _auditDocumentRepos } - - - - /// /// 新增稽查文档 (批量上传文件时才是数组,文件夹时单个对象) /// @@ -720,6 +782,10 @@ public class AuditDocumentService(IRepository _auditDocumentRepos var historicalVersionIds = await _auditDocumentRepository.Where(x => x.MainFileId == alikeData.Id).OrderBy(x => x.Version).Select(x => x.Id).ToListAsync(); //加上当前的同名文件 一起重新设置版本号 historicalVersionIds.Add(alikeData.Id); + + // 删除原有闭包关系 (重命的文件变成历史版本了) + await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => t.AncestorId == alikeData.Id || t.DescendantId == alikeData.Id); + int num = 1; foreach (var item in historicalVersionIds) @@ -733,10 +799,13 @@ public class AuditDocumentService(IRepository _auditDocumentRepos }); num++; + + await _auditDocumentRepository.SaveChangesAsync(); } - if (inDto.Id == null) + // 针对版本文件是不需要维护闭包表的 + if (inDto.Id == null && entityData.MainFileId == null) { //维护新增闭包关系 await AddClosureRelationsAsync(entityData.Id, entityData.ParentId); @@ -749,7 +818,7 @@ public class AuditDocumentService(IRepository _auditDocumentRepos //同层级没找到同名的文件,那么走正常的新增 和更新 var entity = await _auditDocumentRepository.InsertOrUpdateAsync(inDto, true); - if (inDto.Id == null) + if (inDto.Id == null && entity.MainFileId == null) { //维护新增闭包关系 await AddClosureRelationsAsync(entity.Id, entity.ParentId); @@ -761,331 +830,381 @@ public class AuditDocumentService(IRepository _auditDocumentRepos #endregion + #region 增加闭包设计 不用修改地方 + + /// + /// 获取稽查文档 + /// + /// + /// + /// + [HttpPost] + public async Task> GetAuditDocumentList(AuditDocumentQuery inQuery) + { + var auditDocumentQueryable = _auditDocumentRepository + .ProjectTo(_mapper.ConfigurationProvider); + var pageList = await auditDocumentQueryable.ToPagedListAsync(inQuery); + + return pageList; + } + + /// + /// 获取历史版本 + /// + /// + /// + [HttpPost] + public async Task> GetHistoricalVersion(GetHistoricalVersionInDto inDto) + { + + List result = new List(); + + result = await _auditDocumentRepository.Where(x => x.MainFileId == inDto.Id).ProjectTo(_mapper.ConfigurationProvider).OrderByDescending(x => x.Version).ToListAsync(); + var currentData = await _auditDocumentRepository.Where(x => x.Id == inDto.Id).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); + currentData.IsCurrentVersion = true; + + result.Insert(0, currentData); + + return result; + } + + + + #endregion + + + + #region 闭包后续废弃方法 - /// - /// 删除稽查文档 - /// - /// - /// - [HttpPost] - public async Task DeleteAuditDocument(DeleteAuditDocumentInDto inDto) - { - var data = await _auditDocumentRepository.Select(x => new DeleteAudit() - { - Id = x.Id, - ParentId = x.ParentId, - MainFileId = x.MainFileId - }).ToListAsync(); - - List DeleteId = inDto.Ids; - - finId(inDto.Ids, data); - - void finId(List deletids, List deletes) - { - DeleteId.AddRange(deletids); - - var temp = deletes.Where(x => (x.ParentId != null && deletids.Contains(x.ParentId.Value)) || (x.MainFileId != null && deletids.Contains(x.MainFileId.Value))).Select(x => x.Id).ToList(); - if (temp.Count() > 0) - { - finId(temp, deletes); - } - } + ///// + ///// 删除稽查文档 + ///// + ///// + ///// + //[HttpPost] + //public async Task DeleteAuditDocument(DeleteAuditDocumentInDto inDto) + //{ + // var data = await _auditDocumentRepository.Select(x => new DeleteAudit() + // { + // Id = x.Id, + // ParentId = x.ParentId, + // MainFileId = x.MainFileId + // }).ToListAsync(); - DeleteId = DeleteId.Distinct().ToList(); - var mainFileId = await _auditDocumentRepository.Where(x => DeleteId.Contains(x.Id) && x.MainFileId != null).Select(x => x.MainFileId).Distinct().ToListAsync(); - var success = await _auditDocumentRepository.DeleteFromQueryAsync(t => DeleteId.Distinct().Contains(t.Id), true); + // List DeleteId = inDto.Ids; - foreach (var item in mainFileId) - { - var historicalVersionList = await _auditDocumentRepository.Where(x => x.MainFileId == item).OrderBy(x => x.Version).ToListAsync(); + // finId(inDto.Ids, data); - var num = 1; - foreach (var historical in historicalVersionList) - { - await _auditDocumentRepository.UpdatePartialFromQueryAsync(historical.Id, x => new AuditDocument() - { - Version = num, - }, true); - num++; - } - - - - } - - - return ResponseOutput.Ok(); - - - } - - /// - /// 获取文件树形结构 (传Id 根节点就是自己) - /// - /// - /// - [HttpPost] - public async Task> GetAuditDocumentData(GetAuditDocumentDataInDto inDto) - { - - var defalutSortArray = new string[] { nameof(AuditDocumentData.AuditDocumentTypeEnum), nameof(AuditDocumentData.Name) }; - if (inDto.SortField.IsNotNullOrEmpty()) - { - defalutSortArray = new string[] { nameof(AuditDocumentData.AuditDocumentTypeEnum), inDto.SortField + (inDto.Asc ? " asc" : " desc") }; - inDto.SortField = string.Empty; - } - // 新取出来排序 然后再找子项 - var data = (await _auditDocumentRepository - .Where(x => x.AuditDocumentTypeEnum != AuditDocumentType.HistoricalVersion) - .WhereIf(inDto.IsAuthorization != null, x => x.IsAuthorization == inDto.IsAuthorization) - .ProjectTo(_mapper.ConfigurationProvider).ToPagedListAsync(new PageInput() - { - PageIndex = 1, - PageSize = 999999, - }, defalutSortArray)).CurrentPageData.ToList(); - - - - if (inDto.Name.IsNotNullOrEmpty()) - { - List findIds = new List(); - var findData = data.Where(x => x.Name.Contains(inDto.Name)).Select(x => x.Id.Value).ToList(); - GetParentId(findIds, findData, data); - findIds.AddRange(findData); - - data = data.Where(x => findIds.Distinct().Contains(x.Id.Value)).ToList(); - - } - - - var query = data - .WhereIf(inDto.SelfId != null, x => inDto.SelfId == x.Id) - .WhereIf(inDto.Id != null, x => inDto.Id == x.ParentId) - .WhereIf(inDto.Id == null && inDto.SelfId == null, x => x.ParentId == null); - - - - PageOutput result = new PageOutput() - { - PageIndex = inDto.PageIndex, - PageSize = inDto.PageSize, - TotalCount = query.Count(), - }; - var root = query - .Skip(inDto.PageSize * (inDto.PageIndex - 1)).Take(inDto.PageSize).ToList(); - - var historicalVersionList = await _auditDocumentRepository - .Where(x => x.AuditDocumentTypeEnum == AuditDocumentType.HistoricalVersion).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); - - foreach (var item in root) - { - GetChildren(item, data, historicalVersionList); - - } - result.CurrentPageData = root; - return result; - - } - - private void GetParentId(List parentIds, List ids, List dataList) - { - var parentid = dataList.Where(x => ids.Contains(x.Id.Value) && x.ParentId != null).Select(x => x.ParentId.Value).ToList(); - - if (parentid.Count() > 0) - { - parentIds.AddRange(parentid); - - GetParentId(parentIds, parentid, dataList); - } - - } - - private void GetChildren(AuditDocumentData item, List dataList, List historyList) - { - item.Children = dataList.Where(x => x.ParentId == item.Id).ToList(); - item.HistoricalVersionsCount = historyList.Where(x => x.MainFileId == item.Id).Count(); - foreach (var x in item.Children) - { - GetChildren(x, dataList, historyList); - } - } - /// - /// 移动文件或者文件夹 到其他文件夹 - /// - /// - [HttpPost] - public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) - { - - var data = await _auditDocumentRepository.Select(x => new DeleteAudit() - { - Id = x.Id, - ParentId = x.ParentId, - AuditDocumentTypeEnum = x.AuditDocumentTypeEnum, - MainFileId = x.MainFileId - }).ToListAsync(); - - foreach (var id in inDto.Ids) - { - var file = data.Where(x => x.Id == id).FirstOrDefault(); - if (file.AuditDocumentTypeEnum == AuditDocumentType.Folder) - { - if (finChild(new List { id }, inDto.ParentId, data)) - { - throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]); - } - } - } - - bool finChild(List ids, Guid ChildId, List data) - { - var child = data.Where(x => x.ParentId != null && ids.Contains(x.ParentId.Value)).ToList(); - if (child.Count() == 0) - { - return false; - } - else if (child.Any(x => x.Id == ChildId)) - { - return true; - } - else - { - var newids = child.Select(x => x.Id).ToList(); - - return finChild(newids, ChildId, data); - - } - } - - foreach (var id in inDto.Ids) - { - await _auditDocumentRepository.UpdatePartialFromQueryAsync(id, x => new AuditDocument() - { - ParentId = inDto.ParentId - }); - - await _auditDocumentRepository.SaveChangesAsync(); - } - - return ResponseOutput.Ok(); - } - - /// - /// 复制文件或者文件夹 - /// - /// - /// - [HttpPost] - public async Task CopyFileOrFolder(MovieFileOrFolderInDto inDto) - { - - foreach (var item in inDto.Ids) - { - var data = (await GetAuditDocumentData(new GetAuditDocumentDataInDto() - { - SelfId = item, - - PageIndex = 1, - PageSize = 1000 - })).CurrentPageData; - - List auditDocumentAddOrEdits = _mapper.Map>(data); - auditDocumentAddOrEdits.ForEach(x => - { - x.IsUpdate = false; - x.Id = null; - x.ParentId = inDto.ParentId; - }); - await addData(auditDocumentAddOrEdits); - } - - async Task addData(List data) - { - foreach (var item in data) - { - item.Id = null; - var result = await AddOrUpdateAuditDocument(item); - - item.Children.ForEach(x => - { - x.ParentId = result.Id; - x.IsUpdate = false; - x.Id = null; - }); - - if (item.Children.Count() > 0) - { - await addData(item.Children); - } - } - } - return ResponseOutput.Ok(); - } - - - /// - /// 设置是否授权 - /// - /// - /// - [HttpPost] - public async Task SetIsAuthorization(SetIsAuthorizationInDto inDto) - { - var data = await _auditDocumentRepository.Select(x => new DeleteAudit() - { - Id = x.Id, - ParentId = x.ParentId, - MainFileId = x.MainFileId - }).ToListAsync(); - - List allid = new List(); - findChild(allid, inDto.Ids, data); - if (inDto.IsAuthorization) - { - findParent(allid, inDto.Ids, data); - } - allid = allid.Distinct().ToList(); - await _auditDocumentRepository.UpdatePartialFromQueryAsync(t => allid.Contains(t.Id), x => new AuditDocument() - { - - IsAuthorization = inDto.IsAuthorization - }); - await _auditDocumentRepository.SaveChangesAsync(); - return ResponseOutput.Ok(); - - void findParent(List allId, List current, List data) - { - allId.AddRange(current); - var parent = data.Where(x => current.Contains(x.Id)).Select(x => x.ParentId).Where(x => x != null).Select(x => (Guid)x).ToList(); - - if (parent.Count() > 0) - { - - - findParent(allId, parent, data); - - } - } - - void findChild(List allId, List current, List data) - { - allId.AddRange(current); - - var child = data.Where(x => (x.ParentId != null && current.Contains(x.ParentId.Value)) || (x.MainFileId != null && current.Contains(x.MainFileId.Value))).Select(x => x.Id).ToList(); - if (child.Count() > 0) - { - - - findChild(allId, child, data); - - } - - } - } + // void finId(List deletids, List deletes) + // { + // DeleteId.AddRange(deletids); + + // var temp = deletes.Where(x => (x.ParentId != null && deletids.Contains(x.ParentId.Value)) || (x.MainFileId != null && deletids.Contains(x.MainFileId.Value))).Select(x => x.Id).ToList(); + // if (temp.Count() > 0) + // { + // finId(temp, deletes); + // } + // } + + // DeleteId = DeleteId.Distinct().ToList(); + // var mainFileId = await _auditDocumentRepository.Where(x => DeleteId.Contains(x.Id) && x.MainFileId != null).Select(x => x.MainFileId).Distinct().ToListAsync(); + // var success = await _auditDocumentRepository.DeleteFromQueryAsync(t => DeleteId.Distinct().Contains(t.Id), true); + + // foreach (var item in mainFileId) + // { + // var historicalVersionList = await _auditDocumentRepository.Where(x => x.MainFileId == item).OrderBy(x => x.Version).ToListAsync(); + + // var num = 1; + // foreach (var historical in historicalVersionList) + // { + // await _auditDocumentRepository.UpdatePartialFromQueryAsync(historical.Id, x => new AuditDocument() + // { + // Version = num, + // }, true); + // num++; + // } + + + + // } + + + // return ResponseOutput.Ok(); + + + //} + + + + ///// + ///// 获取文件树形结构 (传Id 根节点就是自己) + ///// + ///// + ///// + //[HttpPost] + //public async Task> GetAuditDocumentData(GetAuditDocumentDataInDto inDto) + //{ + + // var defalutSortArray = new string[] { nameof(AuditDocumentData.AuditDocumentTypeEnum), nameof(AuditDocumentData.Name) }; + // if (inDto.SortField.IsNotNullOrEmpty()) + // { + // defalutSortArray = new string[] { nameof(AuditDocumentData.AuditDocumentTypeEnum), inDto.SortField + (inDto.Asc ? " asc" : " desc") }; + // inDto.SortField = string.Empty; + // } + // // 新取出来排序 然后再找子项 + // var data = (await _auditDocumentRepository + // .Where(x => x.AuditDocumentTypeEnum != AuditDocumentType.HistoricalVersion) + // .WhereIf(inDto.IsAuthorization != null, x => x.IsAuthorization == inDto.IsAuthorization) + // .ProjectTo(_mapper.ConfigurationProvider).ToPagedListAsync(new PageInput() + // { + // PageIndex = 1, + // PageSize = 999999, + // }, defalutSortArray)).CurrentPageData.ToList(); + + + + // if (inDto.Name.IsNotNullOrEmpty()) + // { + // List findIds = new List(); + // var findData = data.Where(x => x.Name.Contains(inDto.Name)).Select(x => x.Id.Value).ToList(); + // GetParentId(findIds, findData, data); + // findIds.AddRange(findData); + + // data = data.Where(x => findIds.Distinct().Contains(x.Id.Value)).ToList(); + + // } + + + // var query = data + // .WhereIf(inDto.SelfId != null, x => inDto.SelfId == x.Id) + // .WhereIf(inDto.Id != null, x => inDto.Id == x.ParentId) + // .WhereIf(inDto.Id == null && inDto.SelfId == null, x => x.ParentId == null); + + + + // PageOutput result = new PageOutput() + // { + // PageIndex = inDto.PageIndex, + // PageSize = inDto.PageSize, + // TotalCount = query.Count(), + // }; + // var root = query + // .Skip(inDto.PageSize * (inDto.PageIndex - 1)).Take(inDto.PageSize).ToList(); + + // var historicalVersionList = await _auditDocumentRepository + // .Where(x => x.AuditDocumentTypeEnum == AuditDocumentType.HistoricalVersion).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + + // foreach (var item in root) + // { + // GetChildren(item, data, historicalVersionList); + + // } + // result.CurrentPageData = root; + // return result; + + //} + + + + + //private void GetParentId(List parentIds, List ids, List dataList) + //{ + // var parentid = dataList.Where(x => ids.Contains(x.Id.Value) && x.ParentId != null).Select(x => x.ParentId.Value).ToList(); + + // if (parentid.Count() > 0) + // { + // parentIds.AddRange(parentid); + + // GetParentId(parentIds, parentid, dataList); + // } + + //} + + //private void GetChildren(AuditDocumentData item, List dataList, List historyList) + //{ + // item.Children = dataList.Where(x => x.ParentId == item.Id).ToList(); + // item.HistoricalVersionsCount = historyList.Where(x => x.MainFileId == item.Id).Count(); + // foreach (var x in item.Children) + // { + // GetChildren(x, dataList, historyList); + // } + //} + ///// + ///// 移动文件或者文件夹 到其他文件夹 + ///// + ///// + //[HttpPost] + //public async Task MovieFileOrFolder(MovieFileOrFolderInDto inDto) + //{ + + // var data = await _auditDocumentRepository.Select(x => new DeleteAudit() + // { + // Id = x.Id, + // ParentId = x.ParentId, + // AuditDocumentTypeEnum = x.AuditDocumentTypeEnum, + // MainFileId = x.MainFileId + // }).ToListAsync(); + + // foreach (var id in inDto.Ids) + // { + // var file = data.Where(x => x.Id == id).FirstOrDefault(); + // if (file.AuditDocumentTypeEnum == AuditDocumentType.Folder) + // { + // if (finChild(new List { id }, inDto.ParentId, data)) + // { + // throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotMove"]); + // } + // } + // } + + // bool finChild(List ids, Guid ChildId, List data) + // { + // var child = data.Where(x => x.ParentId != null && ids.Contains(x.ParentId.Value)).ToList(); + // if (child.Count() == 0) + // { + // return false; + // } + // else if (child.Any(x => x.Id == ChildId)) + // { + // return true; + // } + // else + // { + // var newids = child.Select(x => x.Id).ToList(); + + // return finChild(newids, ChildId, data); + + // } + // } + + // foreach (var id in inDto.Ids) + // { + // await _auditDocumentRepository.UpdatePartialFromQueryAsync(id, x => new AuditDocument() + // { + // ParentId = inDto.ParentId + // }); + + // await _auditDocumentRepository.SaveChangesAsync(); + // } + + // return ResponseOutput.Ok(); + //} + + ///// + ///// 复制文件或者文件夹 + ///// + ///// + ///// + //[HttpPost] + //public async Task CopyFileOrFolder(MovieFileOrFolderInDto inDto) + //{ + + // foreach (var item in inDto.Ids) + // { + // var data = (await GetAuditDocumentData(new GetAuditDocumentDataInDto() + // { + // SelfId = item, + + // PageIndex = 1, + // PageSize = 1000 + // })).CurrentPageData; + + // List auditDocumentAddOrEdits = _mapper.Map>(data); + // auditDocumentAddOrEdits.ForEach(x => + // { + // x.IsUpdate = false; + // x.Id = null; + // x.ParentId = inDto.ParentId; + // }); + // await addData(auditDocumentAddOrEdits); + // } + + // async Task addData(List data) + // { + // foreach (var item in data) + // { + // item.Id = null; + // var result = await AddOrUpdateAuditDocument(item); + + // item.Children.ForEach(x => + // { + // x.ParentId = result.Id; + // x.IsUpdate = false; + // x.Id = null; + // }); + + // if (item.Children.Count() > 0) + // { + // await addData(item.Children); + // } + // } + // } + // return ResponseOutput.Ok(); + //} + + + ///// + ///// 设置是否授权 + ///// + ///// + ///// + //[HttpPost] + //public async Task SetIsAuthorization(SetIsAuthorizationInDto inDto) + //{ + // var data = await _auditDocumentRepository.Select(x => new DeleteAudit() + // { + // Id = x.Id, + // ParentId = x.ParentId, + // MainFileId = x.MainFileId + // }).ToListAsync(); + + // List allid = new List(); + // findChild(allid, inDto.Ids, data); + // if (inDto.IsAuthorization) + // { + // findParent(allid, inDto.Ids, data); + // } + // allid = allid.Distinct().ToList(); + // await _auditDocumentRepository.UpdatePartialFromQueryAsync(t => allid.Contains(t.Id), x => new AuditDocument() + // { + + // IsAuthorization = inDto.IsAuthorization + // }); + // await _auditDocumentRepository.SaveChangesAsync(); + // return ResponseOutput.Ok(); + + // void findParent(List allId, List current, List data) + // { + // allId.AddRange(current); + // var parent = data.Where(x => current.Contains(x.Id)).Select(x => x.ParentId).Where(x => x != null).Select(x => (Guid)x).ToList(); + + // if (parent.Count() > 0) + // { + + + // findParent(allId, parent, data); + + // } + // } + + // void findChild(List allId, List current, List data) + // { + // allId.AddRange(current); + + // var child = data.Where(x => (x.ParentId != null && current.Contains(x.ParentId.Value)) || (x.MainFileId != null && current.Contains(x.MainFileId.Value))).Select(x => x.Id).ToList(); + // if (child.Count() > 0) + // { + + + // findChild(allId, child, data); + + // } + + // } + //} #endregion diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index d711165cd..00f16de45 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -292,6 +292,8 @@ namespace IRaCIS.Application.Contracts public string OrganizationName { get; set; } = string.Empty; public Guid? UserType { get; set; } + public UserTypeEnum? UserTypeEnum { get; set; } + public bool? IsTestUser { get; set; } public bool? IsZhiZhun { get; set; } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 67e4f2e06..09f6c53c8 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -510,7 +510,8 @@ namespace IRaCIS.Core.Application.Service .WhereIf(inQuery.EndLastLoginTime != null, t => t.LastLoginTime <= inQuery.EndLastLoginTime) .WhereIf(inQuery.BeginLastChangePassWordTime != null, t => t.LastChangePassWordTime >= inQuery.BeginLastChangePassWordTime) .WhereIf(inQuery.EndLastChangePassWordTime != null, t => t.LastChangePassWordTime <= inQuery.EndLastChangePassWordTime) - .WhereIf(inQuery.UserType != null, t => t.UserRoleList.Any(t => t.UserTypeId == inQuery.UserType && t.IsUserRoleDisabled==false)) + .WhereIf(inQuery.UserType != null, t => t.UserRoleList.Any(t => t.UserTypeId == inQuery.UserType && t.IsUserRoleDisabled == false)) + .WhereIf(inQuery.UserType != null, t => t.UserRoleList.Any(t => t.UserTypeRole.UserTypeEnum == inQuery.UserTypeEnum && t.IsUserRoleDisabled == false)) .WhereIf(inQuery.UserState != null, t => t.Status == inQuery.UserState) .WhereIf(inQuery.IsTestUser != null, t => t.IsTestUser == inQuery.IsTestUser) .WhereIf(inQuery.IsZhiZhun != null, t => t.IsZhiZhun == inQuery.IsZhiZhun) @@ -863,8 +864,8 @@ namespace IRaCIS.Core.Application.Service .WhereIf(inQuery.OptTypeList != null && inQuery.OptTypeList.Count > 0, t => inQuery.OptTypeList.Contains(t.OptType)) .WhereIf(inQuery.BeginDate != null, t => t.CreateTime >= inQuery.BeginDate) .WhereIf(inQuery.EndDate != null, t => t.CreateTime <= inQuery.EndDate) - .WhereIf(inQuery.IsLoginUncommonly != null , t => t.IsLoginUncommonly== inQuery.IsLoginUncommonly) - + .WhereIf(inQuery.IsLoginUncommonly != null, t => t.IsLoginUncommonly == inQuery.IsLoginUncommonly) + .WhereIf(!string.IsNullOrEmpty(inQuery.LoginUserName), t => t.ActionUserName.Contains(inQuery.LoginUserName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.LoginFaildName), t => t.ActionUserName.Contains(inQuery.LoginFaildName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.IP), t => t.IP.Contains(inQuery.IP!)) @@ -922,7 +923,7 @@ namespace IRaCIS.Core.Application.Service var password = loginDto.Password; var emailConfig = _emailConfig.CurrentValue; - var companyInfo = new SystemEmailSendConfigView() { CompanyName = emailConfig.CompanyName, CompanyNameCN = emailConfig.CompanyNameCN, CompanyShortName = emailConfig.CompanyShortName, CompanyShortNameCN = emailConfig.CompanyShortNameCN,SystemShortName=emailConfig.SystemShortName ,EmailRegexStr=emailConfig.EmailRegexStr}; + var companyInfo = new SystemEmailSendConfigView() { CompanyName = emailConfig.CompanyName, CompanyNameCN = emailConfig.CompanyNameCN, CompanyShortName = emailConfig.CompanyShortName, CompanyShortNameCN = emailConfig.CompanyShortNameCN, SystemShortName = emailConfig.SystemShortName, EmailRegexStr = emailConfig.EmailRegexStr }; int maxFailures = _verifyConfig.CurrentValue.LoginMaxFailCount; @@ -991,7 +992,7 @@ namespace IRaCIS.Core.Application.Service //超过90天没修改密码 - if (loginUser!= null&&_verifyConfig.CurrentValue.IsNeedChangePassWord && loginUser.LastChangePassWordTime != null && DateTime.Now.AddDays(-_verifyConfig.CurrentValue.ChangePassWordDays) > loginUser.LastChangePassWordTime.Value) + if (loginUser != null && _verifyConfig.CurrentValue.IsNeedChangePassWord && loginUser.LastChangePassWordTime != null && DateTime.Now.AddDays(-_verifyConfig.CurrentValue.ChangePassWordDays) > loginUser.LastChangePassWordTime.Value) { loginUser.NeedChangePassWord = true; } @@ -1002,7 +1003,7 @@ namespace IRaCIS.Core.Application.Service UserOptType.LoginLockedAccount }; - var actionUserName= loginUser!= null ? loginUser.UserName : userName; + var actionUserName = loginUser != null ? loginUser.UserName : userName; var lastLoginIPRegion = await _userLogRepository.Where(t => t.ActionUserName == actionUserName && userOptTypes.Contains(t.OptType)) .OrderByDescending(t => t.CreateTime).Select(t => t.IPRegion).FirstOrDefaultAsync(); @@ -1022,7 +1023,7 @@ namespace IRaCIS.Core.Application.Service //异地登录 loginUser.LoginState = 2; - + } } } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 3e25bb06e..7341f824c 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -84,9 +84,11 @@ namespace IRaCIS.Core.Application.Service public async Task RebuildAuditDocumentClosureAsync([FromServices] IRepository _auditDocumentClosureRepository, [FromServices] IRepository _auditDocumentRepository) { + await _auditDocumentClosureRepository.BatchDeleteNoTrackingAsync(t => t.Id != Guid.Empty); - var documents = await _auditDocumentRepository.Where().Select(t => new { t.Id, t.ParentId }).ToListAsync(); + //过滤版本文件,防止污染闭包表 + var documents = await _auditDocumentRepository.Where(t => t.MainFileId == null).Select(t => new { t.Id, t.ParentId }).ToListAsync(); var closures = new List();