From 020c5280b34a9eb1f84477d3504b3a75bd228e48 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 22 Jun 2026 15:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=BF=E5=90=8D=E5=8C=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=BF=E6=8D=A2excel=20=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRaCIS.Core.Application.xml | 6 +- .../ImageAndDoc/SystemAnonymizationService.cs | 4 +- IRaCIS.Core.Application/TestService.cs | 121 ++++++++++++++++++ 3 files changed, 127 insertions(+), 4 deletions(-) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 67f9d175b..f465875b6 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -17516,17 +17516,17 @@ - ���� + 质疑 - һ���Ժ˲� + 一致性核查 - ���� + 复制 diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/SystemAnonymizationService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/SystemAnonymizationService.cs index a923cb9e8..1ade0ca55 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/SystemAnonymizationService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/SystemAnonymizationService.cs @@ -4,6 +4,7 @@ // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- +using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using Microsoft.AspNetCore.Mvc; @@ -13,7 +14,7 @@ namespace IRaCIS.Core.Application.Service /// SystemAnonymizationService /// [ApiExplorerSettings(GroupName = "Image")] - public class SystemAnonymizationService(IRepository _systemAnonymizationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, ISystemAnonymizationService + public class SystemAnonymizationService(IRepository _systemAnonymizationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IFusionCache _fusionCache) : BaseService, ISystemAnonymizationService { @@ -37,6 +38,7 @@ namespace IRaCIS.Core.Application.Service var entity = await _systemAnonymizationRepository.InsertOrUpdateAsync(addOrEditSystemAnonymization, true); + await _fusionCache.SetAsync(CacheKeys.SystemAnonymization, CacheHelper.GetSystemAnonymizationListAsync(_systemAnonymizationRepository), TimeSpan.FromDays(7)); return ResponseOutput.Ok(entity.Id.ToString()); diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 470a32ecc..d1c8d8653 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -1,4 +1,5 @@ using Aliyun.OSS; +using ClosedXML.Excel; using FellowOakDicom; using FellowOakDicom.Imaging; using IRaCIS.Application.Contracts; @@ -56,6 +57,126 @@ namespace IRaCIS.Core.Application.Service { public static int IntValue = 100; + static string ReplaceText(string text, Dictionary replaceRules) + { + foreach (var rule in replaceRules) + { + text = text.Replace(rule.Key, rule.Value, StringComparison.OrdinalIgnoreCase); + } + + return text; + } + public async Task ExcelReplaceKeyWord() + { + string folderPath = @"C:\Users\PC\Downloads\SystemData(1)\SystemData\DataTemplate"; + + var replaceRules = new Dictionary + { + ["受试者"] = "试验参与者", + ["Subject"] = "Participant" + }; + + foreach (var file in Directory.GetFiles(folderPath, "*.xlsx", SearchOption.AllDirectories)) + { + Console.WriteLine($"处理文件:{file}"); + + using var workbook = new XLWorkbook(file); + + bool changed = false; + + foreach (var ws in workbook.Worksheets.ToList()) + { + #region Sheet名称 + + var originalName = ws.Name; + + string newSheetName = ReplaceText(originalName, replaceRules); + + if (newSheetName != ws.Name) + { + ws.Name = newSheetName; + changed = true; + + Console.WriteLine($"Sheet重命名:{originalName}->{newSheetName}"); + } + + #endregion + + #region 单元格内容 + + var usedCells = ws.CellsUsed(); + + foreach (var cell in usedCells) + { + if (cell.IsEmpty()) + { + continue; + } + + string value = cell.GetString(); + + if (value.Contains("{{") || (value.Contains("}}"))) + { + continue; + } + + string newValue = ReplaceText(value, replaceRules); + + if (value != newValue) + { + cell.Value = newValue; + changed = true; + + Console.WriteLine($"单元格内容替换:{value}->{newValue}"); + } + } + + #endregion + + #region 公式(可选) + + //foreach (var cell in ws.CellsUsed(c => c.HasFormula)) + //{ + // var formula = cell.FormulaA1; + + // var newFormula = ReplaceText(formula, replaceRules); + + // if (formula != newFormula) + // { + // cell.FormulaA1 = newFormula; + // changed = true; + // } + //} + + #endregion + } + + if (changed) + { + workbook.Save(); + + Console.WriteLine($"已保存:{file}"); + } + + // 文件名替换 + var fileName = Path.GetFileName(file); + var newFileName = ReplaceText(fileName, replaceRules); + + if (fileName != newFileName) + { + var newPath = Path.Combine( + Path.GetDirectoryName(file)!, + newFileName); + + File.Move(file, newPath, true); + + Console.WriteLine($"文件重命名:{fileName} -> {newFileName}"); + } + } + + + return ResponseOutput.Ok(); + } public class ModelVerifyCommand