diff --git a/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs b/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs new file mode 100644 index 000000000..2e9932140 --- /dev/null +++ b/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs @@ -0,0 +1,171 @@ + +using IRaCIS.Core.Application.Helper; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using NPOI.OpenXmlFormats.Wordprocessing; +using NPOI.XWPF.UserModel; +using System.Collections; +using System.Reflection; + +namespace IRaCIS.Core.Application.Service; + +public static class NpoiWordHelper +{ + public static async Task TemplateExportWordAsync(string code, object data, IRepository? _commonDocumentRepository, IWebHostEnvironment _hostEnvironment) + { + //var (physicalPath, fileNmae) = await FileStoreHelper.GetCommonDocPhysicalFilePathAsync(_hostEnvironment, _commonDocumentRepository, code); + + var physicalPath = code; + + + using (FileStream stream = File.OpenRead(physicalPath)) + { + XWPFDocument doc = new XWPFDocument(stream); + //遍历段落 + foreach (var para in doc.Paragraphs) + { + ReplaceKey(para, data); + } + //遍历表格 + var tables = doc.Tables; + foreach (var table in tables) + { + //ReplaceTableKey(table, data, "Data"); + } + + foreach (var table in tables) + { + foreach (var row in table.Rows) + { + foreach (var cell in row.GetTableCells()) + { + foreach (var para in cell.Paragraphs) + { + ReplaceKey(para, data); + } + } + } + } + + FileStream out1 = new FileStream("table.docx", FileMode.Create); + doc.Write(out1); + out1.Close(); + return new FileStreamResult(stream, "application/msword") + { + FileDownloadName = $"replaced_{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx" + }; + } + + + + + + + + + + + + + + + } + + private static void ReplaceKey(XWPFParagraph para, object model) + { + string text = para.ParagraphText; + + Type t = model.GetType(); + PropertyInfo[] pi = t.GetProperties(); + foreach (PropertyInfo p in pi) + { + //$$与模板中$$对应,也可以改成其它符号,比如{$name},务必做到唯一 + if (text.Contains("$" + p.Name + "$")) + { + text = text.Replace("$" + p.Name + "$", p.GetValue(model)?.ToString()); + } + } + + //var runs = para.Runs; + //string styleid = para.Style; + //for (int i = 0; i < runs.Count; i++) + //{ + // var run = runs[i]; + // text = run.ToString(); + // Type t = model.GetType(); + // PropertyInfo[] pi = t.GetProperties(); + // foreach (PropertyInfo p in pi) + // { + // //$$与模板中$$对应,也可以改成其它符号,比如{$name},务必做到唯一 + // if (text.Contains("$" + p.Name + "$")) + // { + // text = text.Replace("$" + p.Name + "$", p.GetValue(model)?.ToString()); + // } + // } + // runs[i].SetText(text, 0); + //} + } + + + + + /// + /// 替换表格Key + /// + /// + /// + /// + + private static void ReplaceTableKey(XWPFTable table, IList list, String field) + { + List paras = new List(); + // 获取最后一行数据,最后一行设置值 + Int32 iLastRowIndex = 0; + for (int iIndex = 0; iIndex < table.Rows.Count; iIndex++) + { + if (iIndex == table.Rows.Count - 1) + { + iLastRowIndex = iIndex; + foreach (var cell in table.Rows[iIndex].GetTableCells()) + { + foreach (var para in cell.Paragraphs) + { + paras.Add(para); + } + } + } + } + // 删除最后一行 + table.RemoveRow(iLastRowIndex); + + for (int iIndex = 0; iIndex < list.Count; iIndex++) + { + object data = list[iIndex]; + Type t = data.GetType(); + PropertyInfo[] pi = t.GetProperties(); + // 表增加行 + XWPFTableRow m_row = table.CreateRow(); + CT_Row m_NewRow = new CT_Row(); + String text = String.Empty; + Int32 jIndex = 0; + paras.ForEach(para => + { + text = para.ParagraphText; + foreach (PropertyInfo p in pi) + { + if (text.Contains("$" + field + "." + p.Name + "$")) + { + m_row.GetCell(jIndex).SetText(p.GetValue(data, null).ToString()); + } + } + jIndex++; + }); + m_row = new XWPFTableRow(m_NewRow, table); + table.AddRow(m_row); + + } + } + + + +} \ No newline at end of file diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 7cbaf6507..37ce64f7b 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -64,7 +64,6 @@ - @@ -96,6 +95,7 @@ true + diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 8b3f5abae..3b49e4b91 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -34,6 +34,14 @@ 主要为了 处理项目结束 锁库,不允许操作 + + + 替换表格Key + + + + + 分配规则 @@ -335,6 +343,7 @@ 重阅原任务跟踪处理 只会在同意的时候调用这个 + @@ -348,6 +357,7 @@ 确认重阅与否 1同意 2 拒绝 + diff --git a/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs b/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs index dfbf4d49e..cc974e672 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs @@ -455,6 +455,9 @@ namespace IRaCIS.Application.Contracts public Guid? HospitalId { get; set; } = Guid.Empty; + public string Physician { get; set; } = string.Empty; + public string PhysicianCN { get; set; } = string.Empty; + } #endregion @@ -636,6 +639,9 @@ namespace IRaCIS.Application.Contracts public bool IsVirtual { get; set; } public string BlindName { get; set; } = String.Empty; + + public string BlindNameCN { get; set; } = string.Empty; + } public class ResumeConfirmDTO diff --git a/IRaCIS.Core.Application/Service/Doctor/DTO/TrialExperienceModel.cs b/IRaCIS.Core.Application/Service/Doctor/DTO/TrialExperienceModel.cs index 325cecc01..7fa85d98b 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DTO/TrialExperienceModel.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DTO/TrialExperienceModel.cs @@ -9,6 +9,7 @@ public Guid? PhaseId { get; set; } public string EvaluationContent { get; set; } = String.Empty; + public int VisitReadingCount { get; set; } //public string Term { get; set; } diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 14d319cab..59b392148 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -1,6 +1,9 @@ using BeetleX.BNR; +using IRaCIS.Core.Application.Service; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Distributed; +using System.Text.RegularExpressions; + namespace IRaCIS.Application.Services { @@ -48,18 +51,57 @@ namespace IRaCIS.Application.Services //var needAddVisitList = await _repository.Where(t => t.TrialId == Guid.Empty).DistinctBy(t => t.VisitTaskNum).ToListAsync(); - await _repository.BatchUpdateAsync(t => t.Id==Guid.Empty, u => new VisitTask() { + await _repository.BatchUpdateAsync(t => t.Id == Guid.Empty, u => new VisitTask() + { SuggesteFinishedTime = u.IsUrgent ? DateTime.Now.AddDays(2) : DateTime.Now.AddDays(7), - Code = u.Code+1 + Code = u.Code + 1 }); return _userInfo.LocalIp; } - [HttpPost] - public string Get(TestModel testModel) + + + private static Dictionary _replacePatterns = new Dictionary() + { + { "test", "Atlanta Knight" }, + { "GAME_TIME", "7:30pm" }, + { "GAME_NUMBER", "161" }, + { "DATE", "October 18 2018" }, + }; + + private static string ReplaceFunc(string findStr) { + if (_replacePatterns.ContainsKey(findStr)) + { + return _replacePatterns[findStr]; + } + return findStr; + } + [HttpPost] + public async Task Get(TestModel testModel) + { + + // Load a document. + //using (var document = DocX.Load(Path.Combine(_hostEnvironment.ContentRootPath, "ReplaceText.docx"))) + //{ + // // Check if all the replace patterns are used in the loaded document. + // if (document.FindUniqueByPattern(@"<[\w \=]{4,}>", RegexOptions.IgnoreCase).Count > 0) + // { + // // Do the replacement of all the found tags and with green bold strings. + // //for (int i = 0; i < _replacePatterns.Count; ++i) + // //{ + // // document.ReplaceText("<(.*?)>", TestService.ReplaceFunc, false, RegexOptions.IgnoreCase, new Formatting() { Bold = true, FontColor = System.Drawing.Color.Green }); + // //} + // // Save this document to disk. + + // document.ReplaceText("test", "jfdksajfkljflsdjf", false, RegexOptions.IgnoreCase, new Formatting() { Bold = true, FontColor = System.Drawing.Color.Green }); + // document.SaveAs("ReplacedText.docx"); + // } + + //} + return await NpoiWordHelper.TemplateExportWordAsync(Path.Combine(_hostEnvironment.ContentRootPath, "ReplaceText.docx"), new {test="xiugai",ZZZZ="ModiffyZZZZ"},null,_hostEnvironment); //_cache.SetString("test" , "cacheStr"); @@ -102,7 +144,7 @@ namespace IRaCIS.Application.Services //var d = _dicRepository.UpdateFromDTOAsync(new AddOrEditBasicDic() { Id = Guid.Parse("60d86683-c33b-4349-b672-08da1e91b622"), ParentId = null, ChildGroup = null, Code = null }, true, true).Result; //var a = 123; - var b = _localizer["test{0}", "测试"]; + //var b = _localizer["test{0}", "测试"]; //return _localizer["test{0}", "测试"]; @@ -111,8 +153,8 @@ namespace IRaCIS.Application.Services //var list2 = _repository.Where(t => t.Id == Guid.NewGuid()).Select(t => t.SourceSubjectVisit).ToList(); //var list3 = _repository.Where(t => t.Id == Guid.NewGuid()).SelectMany(t => t.SourceSubjectVisit.VisitTaskList).ToList(); - var list2 = _repository.Where(t => t.Id == Guid.NewGuid()).SelectMany(t => t.SubjectVisitTaskList).ToList(); - return _userInfo.LocalIp; + //var list2 = _repository.Where(t => t.Id == Guid.NewGuid()).SelectMany(t => t.SubjectVisitTaskList).ToList(); + //return _userInfo.LocalIp; } diff --git a/IRaCIS.Core.Domain/Dcotor/Doctor.cs b/IRaCIS.Core.Domain/Dcotor/Doctor.cs index 1494760f5..c03a9b1cd 100644 --- a/IRaCIS.Core.Domain/Dcotor/Doctor.cs +++ b/IRaCIS.Core.Domain/Dcotor/Doctor.cs @@ -74,6 +74,8 @@ namespace IRaCIS.Core.Domain.Models public string DepartmentOther { get; set; } = string.Empty; + public string Physician { get; set; } = string.Empty; + public string PhysicianCN { get; set; } = string.Empty; public Guid? RankId { get; set; } = Guid.Empty; @@ -186,5 +188,10 @@ namespace IRaCIS.Core.Domain.Models public bool IsVirtual { get; set; } public string BlindName { get; set; } + + public string BlindNameCN { get; set; } = string.Empty; + + + public string BlindPublications { get; set; } } } diff --git a/IRaCIS.Core.Domain/Dcotor/TrialExperience.cs b/IRaCIS.Core.Domain/Dcotor/TrialExperience.cs index cba50202a..ad91f58d2 100644 --- a/IRaCIS.Core.Domain/Dcotor/TrialExperience.cs +++ b/IRaCIS.Core.Domain/Dcotor/TrialExperience.cs @@ -30,5 +30,7 @@ namespace IRaCIS.Core.Domain.Models public DateTime CreateTime { get; set; } = DateTime.Now; public Guid UpdateUserId { get; set; } public DateTime UpdateTime { get; set; } + + public int VisitReadingCount { get; set; } } }