diff --git a/IRaCIS.Core.API/_PipelineExtensions/LocalizationConfig.cs b/IRaCIS.Core.API/_PipelineExtensions/LocalizationConfig.cs index 45ab1ec1f..d94b96b65 100644 --- a/IRaCIS.Core.API/_PipelineExtensions/LocalizationConfig.cs +++ b/IRaCIS.Core.API/_PipelineExtensions/LocalizationConfig.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Builder; +using IRaCIS.Core.Domain.Share; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Localization; using System.Collections.Generic; using System.Globalization; @@ -12,8 +13,9 @@ namespace IRaCIS.Core.API { var supportedCultures = new List { - new CultureInfo("en-US"), - new CultureInfo("zh-CN") + + new CultureInfo(StaticData.CultureInfo.en_US), + new CultureInfo(StaticData.CultureInfo.zh_CN) }; var options = new RequestLocalizationOptions diff --git a/IRaCIS.Core.Application/Helper/WordTempleteHelper.cs b/IRaCIS.Core.Application/Helper/WordTempleteHelper.cs new file mode 100644 index 000000000..9f605be81 --- /dev/null +++ b/IRaCIS.Core.Application/Helper/WordTempleteHelper.cs @@ -0,0 +1,101 @@ +using IRaCIS.Core.Domain.Share; +using NPOI.XWPF.UserModel; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xceed.Document.NET; +using Xceed.Words.NET; + +namespace IRaCIS.Core.Application.Helper +{ + /// + /// 利用DocX 库 处理word国际化模板 + /// + public static class WordTempleteHelper + { + public static void DocX_GetInternationalTempleteStream(string filePath, Stream memoryStream) + { + + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + using (DocX document = DocX.Load(filePath)) + { + // 查找书签 + var bookmarkEn_Start = document.Bookmarks.FirstOrDefault(b => b.Name == StaticData.CultureInfo.en_US_bookMark); + + if (bookmarkEn_Start != null) + { + // 获取书签的起始位置 + //int bookmarkCNStartPos = bookmarkCn_Start.Paragraph.StartIndex; + + var bookmarkENStartPos = bookmarkEn_Start.Paragraph.StartIndex; + + // 创建一个要删除段落的列表 + List paragraphsToRemove = new List(); + + foreach (var item in document.Paragraphs) + { + //中文模板在前,英文在后,英文模板,就删除英文之前的,中文模板就删除英文之后的 + + if (isEn_US ? item.EndIndex < bookmarkENStartPos : item.StartIndex >= bookmarkENStartPos) + { + paragraphsToRemove.Add(item); + } + } + + foreach (var paragraph in paragraphsToRemove) + { + document.RemoveParagraph(paragraph); + } + + } + + // 保存修改 + document.SaveAs(memoryStream); + } + } + + + public static void Npoi_GetInternationalTempleteStream(string filePath, Stream memoryStream) + { + + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + { + XWPFDocument doc = new XWPFDocument(fs); + + // 查找包含指定书签的段落及其索引 + var bookmarkParagraph = doc.Paragraphs + .FirstOrDefault(p => p.GetCTP().GetBookmarkStartList().Any(b => b.name == StaticData.CultureInfo.en_US_bookMark)); + + if (bookmarkParagraph != null) + { + int bookmarkIndex = doc.Paragraphs.IndexOf(bookmarkParagraph); + + if (isEn_US) + { + // 从书签所在段落开始,删除之前的所有段落 + for (int i = bookmarkIndex - 1; i >= 0; i--) + { + doc.RemoveBodyElement(i); + } + } + else + { + // 删除书签之后的所有段落 + for (int i = doc.Paragraphs.Count - 1; i >= bookmarkIndex; i--) + { + doc.RemoveBodyElement(i); + } + } + } + doc.Write(memoryStream); + } + } + + } +} diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index ab2113cba..ab00314fc 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -42,7 +42,7 @@ - + @@ -50,11 +50,6 @@ - - PreserveNewest - true - PreserveNewest - Always true diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 7f17ce6ef..26bc2e0de 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -117,6 +117,11 @@ 解密后的字符串 + + + 利用DocX 库 处理word国际化模板 + + 分配规则 diff --git a/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs b/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs index f3c6f7f5b..010c2b04e 100644 --- a/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs +++ b/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs @@ -1522,20 +1522,18 @@ namespace IRaCIS.Core.Application.Service.Common //两个都不为null 肯定是不同的裁判 //在完成裁判之后的,和未完成裁判之前的 - if (visitItem.VisitTaskNum < maxNotFinishedJudge.VisitTaskNum && visitItem.VisitTaskNum > maxFinishedJudge.VisitTaskNum) + if (/*visitItem.VisitTaskNum < maxNotFinishedJudge.VisitTaskNum &&*/ visitItem.VisitTaskNum > maxFinishedJudge.VisitTaskNum) { visitItem.IsGenerateJudge = null; } - else if (visitItem.ArmEnum == maxFinishedJudge.JudgeArmEnum && visitItem.VisitTaskNum < maxFinishedJudge.VisitTaskNum) { visitItem.IsGenerateJudge = true; } - - else if (visitItem.ArmEnum == Arm.DoubleReadingArm1) - { - visitItem.IsGenerateJudge = true; - } + //else if (visitItem.ArmEnum == Arm.DoubleReadingArm1) + //{ + // visitItem.IsGenerateJudge = true; + //} } } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index dd7aa1031..104a44f53 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -1,4 +1,5 @@ using Aliyun.OSS; +using DocumentFormat.OpenXml.Wordprocessing; using IP2Region.Net.XDB; using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Contracts; @@ -18,12 +19,14 @@ using Microsoft.Extensions.Options; using MiniExcelLibs; using Minio; using Minio.DataModel.Args; +using NPOI.XWPF.UserModel; using SharpCompress.Common; using Spire.Doc; using System.Linq.Expressions; using System.Reflection.Metadata; using System.Text; using System.Text.RegularExpressions; +using Xceed.Document.NET; using Xceed.Words.NET; @@ -114,7 +117,7 @@ namespace IRaCIS.Application.Services public async Task TestMinIO([FromServices] IOSSService oSSService) { - var str= await oSSService.GetSignedUrl("/01000000-c0a8-0242-1c98-08dc7ebcd37d/Read/01000000-c0a8-0242-1c98-08dc7ebcd37d/Visit/1716872544006_1716872544003.png"); + var str = await oSSService.GetSignedUrl("/01000000-c0a8-0242-1c98-08dc7ebcd37d/Read/01000000-c0a8-0242-1c98-08dc7ebcd37d/Visit/1716872544006_1716872544003.png"); //await oSSService.UploadToOSSAsync("C:\\Users\\Administrator\\Desktop\\TrialSiteUserImportTemplate.xlsx", "myfolder"); @@ -188,11 +191,11 @@ namespace IRaCIS.Application.Services Console.WriteLine("\nOriginal Data: " + dataToEncrypt); // Encrypt the data - var encryptedData = RSAHelper.Encrypt( publicKey, dataToEncrypt); + var encryptedData = RSAHelper.Encrypt(publicKey, dataToEncrypt); Console.WriteLine("\nEncrypted Data: " + encryptedData); // Decrypt the data - string decryptedData = RSAHelper.Decrypt( privateKey, encryptedData); + string decryptedData = RSAHelper.Decrypt(privateKey, encryptedData); Console.WriteLine("\nDecrypted Data: " + decryptedData); @@ -202,38 +205,111 @@ namespace IRaCIS.Application.Services [AllowAnonymous] - public async Task testEmail([FromServices] IWebHostEnvironment env ,string email) + public async Task testDoc([FromServices] IWebHostEnvironment env, string email) { - - //using (DocX document = DocX.Load("C:\\Users\\hang\\Desktop\\")) + #region DocX 测试 + //using (DocX document = DocX.Load("C:\\Users\\hang\\Desktop\\test.docx")) //{ - // // 查找书签对应的段落 - // var bookmark = document.Bookmarks.FirstOrDefault(b => b.Name == bookmarkName); + // // 查找书签 + // var bookmarkCn_Start = document.Bookmarks.FirstOrDefault(b => b.Name == "zh_cn"); + // var bookmarkEn_Start = document.Bookmarks.FirstOrDefault(b => b.Name == "en_us"); - // if (bookmark != null) + // if (bookmarkCn_Start != null && bookmarkEn_Start != null) // { - // // 获取书签所在的段落位置 - // int paragraphIndex = document.Paragraphs.IndexOf(bookmark.Paragraph); + // // 获取书签的起始位置 + // int bookmarkCNStartPos = bookmarkCn_Start.Paragraph.StartIndex; - // // 如果书签所在的段落在文档中 - // if (paragraphIndex >= 0) + // var bookmarkENStartPos = bookmarkEn_Start.Paragraph.StartIndex; + + // // // 创建一个要删除段落的列表 + // List paragraphsToRemove = new List(); + + // foreach (var item in document.Paragraphs) // { - // // 删除书签所在的段落 - // document.RemoveParagraphAt(paragraphIndex); + + // //中文模板在前,英文在后,英文模板,就删除英文之前的,中文模板就删除英文之后的 + // //_userInfo.IsEn_Us? item.EndIndex< bookmarkENStartPos :item.StartIndex>= bookmarkENStartPos + // if (item.StartIndex>= bookmarkENStartPos) + // { + // paragraphsToRemove.Add(item); + + // } + // } + + // foreach (var paragraph in paragraphsToRemove) + // { + // document.RemoveParagraph(paragraph); // } - // // 删除书签(只删除书签标记,不删除内容) - // document.Bookmarks.Remove(bookmark); // } // // 保存修改 - // document.Save(); + // document.SaveAs("C:\\Users\\hang\\Desktop\\test1.docx"); //} + #endregion + + using (FileStream fs = new FileStream("C:\\Users\\hang\\Desktop\\test.docx", FileMode.Open, FileAccess.Read)) + { + XWPFDocument doc = new XWPFDocument(fs); - var hiddenEmail = EmailMaskHelper.MaskEmail(email); + // 查找包含指定书签的段落及其索引 + var bookmarkParagraph = doc.Paragraphs + .FirstOrDefault(p => p.GetCTP().GetBookmarkStartList().Any(b => b.name == "en_us")); - return hiddenEmail; + + if (bookmarkParagraph != null) + { + int bookmarkIndex = doc.Paragraphs.IndexOf(bookmarkParagraph); + + // 删除书签之后的所有段落 + for (int i = doc.Paragraphs.Count - 1; i >= bookmarkIndex; i--) + { + doc.RemoveBodyElement(i); + } + + } + else + { + throw new BusinessValidationFailedException("word 模板没有英文书签"); + } + + // 创建一个要删除段落的列表 + + //XWPFParagraph bookmarkParagraph = null; + + //foreach (var paragraph in doc.Paragraphs) + //{ + + // foreach (var bookmark in paragraph.GetCTP().GetBookmarkStartList()) + // { + // if (bookmark.name == "en_us") + // { + // bookmarkParagraph = paragraph; + // break; + // } + // } + //} + + + + + //// 从书签所在段落开始,删除之前的所有段落 + //for (int i = bookmarkIndex - 1; i >= 0; i--) + //{ + // doc.RemoveBodyElement(i); + //} + + + + using (FileStream outStream = new FileStream("C:\\Users\\hang\\Desktop\\test1.docx", FileMode.Create, FileAccess.Write)) + { + doc.Write(outStream); + } + } + + + return "hiddenEmail"; } diff --git a/IRaCIS.Core.Domain/_Config/_StaticData.cs b/IRaCIS.Core.Domain/_Config/_StaticData.cs index 3b0f84623..117e658fa 100644 --- a/IRaCIS.Core.Domain/_Config/_StaticData.cs +++ b/IRaCIS.Core.Domain/_Config/_StaticData.cs @@ -17,6 +17,14 @@ public static class StaticData public static readonly string Zh_CN_Json = "zh-CN.json"; + public static class CultureInfo + { + public static readonly string zh_CN = "zh-CN"; + public static readonly string en_US = "en-US"; + + public static readonly string en_US_bookMark = "en_us"; + } + /// /// 获取国际化 ///