From 0e1310324d624a4424d5ea86a6074ecaa1c139bf Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Fri, 28 Mar 2025 09:48:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Document/AuditDocumentService.cs | 119 +++++++++++++++--- .../Document/DTO/AuditDocumentViewModel.cs | 41 +++--- .../Service/Document/_MapConfig.cs | 1 + 3 files changed, 128 insertions(+), 33 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs index 8e5bf4891..eecec8682 100644 --- a/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs +++ b/IRaCIS.Core.Application/Service/Document/AuditDocumentService.cs @@ -17,6 +17,7 @@ using IRaCIS.Core.Infrastructure; using DocumentFormat.OpenXml.Office2010.Excel; using MassTransit; using NPOI.POIFS.Properties; +using Org.BouncyCastle.Crypto; namespace IRaCIS.Core.Application.Service; @@ -46,7 +47,53 @@ public class AuditDocumentService(IRepository _auditDocumentRepos /// /// [HttpPost] - public async Task UpdateAuditDocument(AuditDocumentAddOrEdit inDto) + public async Task UpdateAuditDocument(AuditDocumentUpdateDto inDto) + { + AuditDocumentAddOrEdit addOrEdit = _mapper.Map(inDto); + addOrEdit.IsUpdate = true; + return await AddOrUpdateAuditDocument(addOrEdit); + } + + /// + /// 新增稽查文档 + /// + /// + /// + [HttpPost] + public async Task AddAuditDocument(List inDto) + { + inDto.ForEach(x => x.IsUpdate = false); + await addData(inDto); + + async Task addData(List data) + { + foreach(var item in data) + { + var result= await AddOrUpdateAuditDocument(item); + + item.Children.ForEach(x => { + x.ParentId = result.Id; + x.IsUpdate = false; + + }); + + if (item.Children.Count() > 0) + { + await addData(item.Children); + } + } + } + + return ResponseOutput.Ok(); + } + + + + /// + /// 通用方法 + /// + /// + private async Task AddOrUpdateAuditDocument(AuditDocumentAddOrEdit inDto) { if (inDto.ParentId != null) { @@ -55,11 +102,20 @@ public class AuditDocumentService(IRepository _auditDocumentRepos { if (inDto.AuditDocumentTypeEnum == AuditDocumentType.Folder) { - throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotAddFolder"]); + if (inDto.IsUpdate) + { + throw new BusinessValidationFailedException(_localizer["AuditDocument_CanNotAddFolder"]); + } + else + { + return alikeData; + + } + } else { - var entityData = await _auditDocumentRepository.UpdateFromDTOAsync(inDto, true); + var entityData = await _auditDocumentRepository.InsertOrUpdateAsync(inDto, true); var historicalVersionIds = await _auditDocumentRepository.Where(x => x.MainFileId == alikeData.Id).OrderBy(x => x.Version).Select(x => x.Id).ToListAsync(); @@ -77,23 +133,51 @@ public class AuditDocumentService(IRepository _auditDocumentRepos }); } - return ResponseOutput.Ok(entityData.Id.ToString()); + return entityData; } } } - var entity = await _auditDocumentRepository.UpdateFromDTOAsync(inDto, true); - return ResponseOutput.Ok(entity.Id.ToString()); + var entity = await _auditDocumentRepository.InsertOrUpdateAsync(inDto, true); + return entity; } - ///// - ///// 新增稽查文档 - ///// - ///// - //public async Task InsertAuditDocument() - //{ - - //} + /// + /// 获取面包屑导航 + /// + /// + /// + public async Task> GetBreadcrumbData(GetBreadcrumbDataInDto inDto) + { + List result=new List(); + + await findParent(result, inDto.Id); + async Task findParent(List datas, Guid id) + { + var data= await _auditDocumentRepository.Where(x => x.Id == inDto.Id).FirstNotNullAsync(); + datas.Add(data.Name); + if (data.ParentId != null) + { + await findParent(datas, data.ParentId.Value); + } + + } + + result.Reverse(); + + return result; + + } + + + ///// + ///// 新增稽查文档 + ///// + ///// + //public async Task InsertAuditDocument() + //{ + + //} /// @@ -107,10 +191,9 @@ public class AuditDocumentService(IRepository _auditDocumentRepos var data= await _auditDocumentRepository .Where(x=>x.AuditDocumentTypeEnum!=AuditDocumentType.HistoricalVersion) .WhereIf(inDto.IsAuthorization!=null,x=>x.IsAuthorization==inDto.IsAuthorization).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); - - var root= data - .WhereIf(inDto.Id!= null, x => x.Id == inDto.Id) - .WhereIf(inDto.Id==null,x=>x.ParentId==null).ToList(); + var root= data + .WhereIf(inDto.Ids != null, x => inDto.Ids.Contains(x.Id.Value)) + .WhereIf(inDto.Ids == null,x=>x.ParentId==null).ToList(); foreach (var item in root) { diff --git a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs index b3e71b6b4..d1341dd7a 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/AuditDocumentViewModel.cs @@ -25,7 +25,7 @@ public class DeleteAuditDocumentInDto public class GetAuditDocumentDataInDto { - public Guid? Id { get; set; } + public List? Ids { get; set; } public bool? IsAuthorization { get; set; } } @@ -81,29 +81,40 @@ public class MovieFileOrFolderInDto public Guid ParentId { get; set; } } - -public class AuditDocumentAddOrEdit +public class AuditDocumentUpdateDto { public Guid? Id { get; set; } - + public AuditDocumentType AuditDocumentTypeEnum { get; set; } - + public string FileFormat { get; set; } - + public string FilePath { get; set; } - + public decimal? FileSize { get; set; } - + public bool IsAuthorization { get; set; } - - // public Guid? MainFileId { get; set; } - + + // public Guid? MainFileId { get; set; } + public string Name { get; set; } - + public Guid? ParentId { get; set; } - - //public int? Version { get; set; } - } +} + +public class GetBreadcrumbDataInDto +{ + public Guid Id { get; set; } +} + +public class AuditDocumentAddOrEdit: AuditDocumentUpdateDto +{ + + + public List Children { get; set; }=new List() { }; + + public bool IsUpdate { get; set; } = true; +} public class AuditDocumentQuery:PageInput { diff --git a/IRaCIS.Core.Application/Service/Document/_MapConfig.cs b/IRaCIS.Core.Application/Service/Document/_MapConfig.cs index d146db4aa..2f27b406a 100644 --- a/IRaCIS.Core.Application/Service/Document/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Document/_MapConfig.cs @@ -15,6 +15,7 @@ namespace IRaCIS.Core.Application.Service var userId = Guid.Empty; var isEn_Us = false; CreateMap(); + CreateMap(); CreateMap(); CreateMap().ReverseMap(); CreateMap()