From 0dcd74388f2fdb1e9d05cdeb8c620e51f2e5d494 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 28 Jun 2023 16:04:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E5=88=B7=E6=96=B0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/Program.cs | 60 ++++---------- .../Helper/InternationalizationHelper.cs | 82 +++++++++++++++++-- .../IRaCIS.Core.Application.xml | 7 ++ .../DTO/InternationalizationViewModel.cs | 9 +- .../Common/InternationalizationService.cs | 35 ++++++-- IRaCIS.Core.Application/TestService.cs | 2 +- 6 files changed, 133 insertions(+), 62 deletions(-) diff --git a/IRaCIS.Core.API/Program.cs b/IRaCIS.Core.API/Program.cs index 24f9703c9..b771b7a5f 100644 --- a/IRaCIS.Core.API/Program.cs +++ b/IRaCIS.Core.API/Program.cs @@ -11,6 +11,8 @@ using MassTransit; using MassTransit.NewIdProviders; using System.IO; using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infra.EFCore; +using IRaCIS.Core.Application.Helper; namespace IRaCIS.Core.API { @@ -64,13 +66,11 @@ namespace IRaCIS.Core.API //缓存项目的状态 匿名化数据 await InitCache(host); - WatchJsonFile(Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources, StaticData.En_US_Json) ); - - WatchJsonFile(Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources, StaticData.Zh_CN_Json)); + + - host.Run(); @@ -100,58 +100,28 @@ namespace IRaCIS.Core.API webBuilder.UseStartup(); }).UseSerilog() .UseServiceProviderFactory(new AutofacServiceProviderFactory()); - + private static async Task InitCache(IHost host) { + var _repository = host.Services.GetService(typeof(IRepository)) as IRepository; + + //初始化 国际化数据,并且监测国际化文件变更 + await InternationalizationHelper.InitInternationlizationDataAndWatchJsonFileAsync(_repository); + var _mediator = host.Services.GetService(typeof(IMediator)) as IMediator; await _mediator.Send(new AnonymizeCacheRequest()); await _mediator.Send(new TrialStateCacheRequest()); + + + } - private static void LoadJsonFile(string filePath) - { - - IConfigurationBuilder builder = new ConfigurationBuilder() - .AddJsonFile(filePath); - - IConfigurationRoot enConfiguration = builder.Build(); - - - - foreach (IConfigurationSection section in enConfiguration.GetChildren()) - { - if (filePath.Contains(StaticData.En_US_Json) ) - { - StaticData.En_US_Dic[section.Key] = section.Value; - - } - else - { - StaticData.Zh_CN_Dic[section.Key] = section.Value; - } - } - - - - - - - } - public static void WatchJsonFile(string filePath) - { - LoadJsonFile(filePath); - - - FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath)); - watcher.Changed += (sender, e) => LoadJsonFile(filePath); - watcher.EnableRaisingEvents = true; - - } - + + } } diff --git a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs index e1feefcea..ddf14b32d 100644 --- a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs +++ b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs @@ -1,5 +1,7 @@ 锘縰sing IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -13,20 +15,21 @@ namespace IRaCIS.Core.Application.Helper { public static class InternationalizationHelper { + public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources); - public static async void AddOrUpdateJsonKeyValueAsync(string key, string value) + public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value) { - var jsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources); - if (!Directory.Exists(jsonFileFolder) || - Directory.GetFiles(jsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) + + if (!Directory.Exists(JsonFileFolder) || + Directory.GetFiles(JsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) { throw new BusinessValidationFailedException("鍥介檯鍖朖son鏂囦欢鐩綍鏈夎"); } - // - foreach (var filePath in Directory.GetFiles(jsonFileFolder).Where(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) + //灏嗚鐩綍涓嬬殑鍥介檯鍖栨枃浠跺叏閮ㄤ慨鏀 + foreach (var filePath in Directory.GetFiles(JsonFileFolder).Where(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) { var json = await File.ReadAllTextAsync(filePath); @@ -40,5 +43,72 @@ namespace IRaCIS.Core.Application.Helper } } + + public static async Task InitInternationlizationDataAndWatchJsonFileAsync(IRepository _repository) + { + //鏌ヨ鏁版嵁搴撶殑鏁版嵁 + var toJsonList = await _repository.Where(t => t.InternationalizationType == 1).Select(t => new + { + t.Code, + t.Value, + t.ValueCN + }).ToListAsync(); + + //缁勭粐鎴恓son 鏂囦欢 + + var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json); + var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json); + + + + + //鏈湴闈欐佹枃浠跺浗闄呭寲闇瑕 + foreach (var tojsonItem in toJsonList) + { + StaticData.En_US_Dic[tojsonItem.Code] = tojsonItem.Value; + StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN; + } + + File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic)); + File.WriteAllText(cnJsonPath, JsonConvert.SerializeObject(StaticData.Zh_CN_Dic)); + + + //鐩戞祴Json鏂囦欢鍙樻洿 瀹炴椂鍒锋柊鏁版嵁 + + WatchJsonFile(usJsonPath); + WatchJsonFile(cnJsonPath); + + } + + public static void WatchJsonFile(string filePath) + { + + FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath)); + watcher.Changed += (sender, e) => LoadJsonFile(filePath); + watcher.EnableRaisingEvents = true; + + } + + + private static void LoadJsonFile(string filePath) + { + + IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile(filePath); + + IConfigurationRoot enConfiguration = builder.Build(); + + foreach (IConfigurationSection section in enConfiguration.GetChildren()) + { + if (filePath.Contains(StaticData.En_US_Json)) + { + StaticData.En_US_Dic[section.Key] = section.Value; + + } + else + { + StaticData.Zh_CN_Dic[section.Key] = section.Value; + } + } + } } } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index e9b41531c..9b20bf2e4 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -2494,6 +2494,13 @@ 涓村簥绛旀 + + + 鑷姩娣诲姞CRC涓村簥鏁版嵁 + + + + 鑾峰彇CRC鍙楄瘯鑰呬复搴婃暟鎹 diff --git a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs index c4f2f3fc9..5f2e25a59 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs @@ -38,7 +38,7 @@ namespace IRaCIS.Core.Application.ViewModel public Guid? Id { get; set; } public int State { get; set; } public string Description { get; set; } = string.Empty; - public string Code { get; set; } + public string Code { get; set; } = string.Empty; public string Value { get; set; } = string.Empty; public string ValueCN { get; set; } = string.Empty; @@ -46,6 +46,13 @@ namespace IRaCIS.Core.Application.ViewModel } + public class InternationalizationSimpleDto + { + public string Code { get; set; } = string.Empty; + public string Value { get; set; } = string.Empty; + public string ValueCN { get; set; } = string.Empty; + } + } diff --git a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index ebbcc3f58..0fa7d246c 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -8,6 +8,8 @@ using IRaCIS.Core.Domain.Models; using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; +using Microsoft.AspNetCore.Authorization; + namespace IRaCIS.Core.Application.Service { /// @@ -24,22 +26,37 @@ namespace IRaCIS.Core.Application.Service _internationalizationRepository = internationalizationRepository; } + + [AllowAnonymous] + + public async Task> GetFrontInternationalizationList() + { + + var list = await _internationalizationRepository.Where(t => t.InternationalizationType == 0).Select(t => new InternationalizationSimpleDto() + { + Code = t.Code, + Value = t.Value, + ValueCN = t.ValueCN + }).ToListAsync(); + + return list; + } + [HttpPost] public async Task> GetInternationalizationList(InternationalizationQuery inQuery) { - var internationalizationQueryable =_internationalizationRepository - .WhereIf(inQuery.Description!=null,t=>t.Description.Contains(inQuery.Description)) + var internationalizationQueryable = _internationalizationRepository + .WhereIf(inQuery.Description != null, t => t.Description.Contains(inQuery.Description)) .WhereIf(inQuery.Code != null, t => t.Code.Contains(inQuery.Code)) - .WhereIf(inQuery.State != null, t => t.State==inQuery.State) - .WhereIf(inQuery.InternationalizationType != null, t => t.InternationalizationType == inQuery.InternationalizationType) - + .WhereIf(inQuery.State != null, t => t.State == inQuery.State) + .WhereIf(inQuery.InternationalizationType != null, t => t.InternationalizationType == inQuery.InternationalizationType) .WhereIf(inQuery.Value != null, t => t.Value.Contains(inQuery.Value)) - .WhereIf(inQuery.ValueCN != null, t => t.ValueCN.Contains(inQuery.ValueCN)) - .ProjectTo(_mapper.ConfigurationProvider); + .WhereIf(inQuery.ValueCN != null, t => t.ValueCN.Contains(inQuery.ValueCN)) + .ProjectTo(_mapper.ConfigurationProvider); var pageList = await internationalizationQueryable - .ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? "Id" : inQuery.SortField, + .ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(InternationalizationView.State) : inQuery.SortField, inQuery.Asc); return pageList; @@ -56,7 +73,7 @@ namespace IRaCIS.Core.Application.Service IsVerify = true }; - var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true,verifyExp1); + var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true, verifyExp1); return ResponseOutput.Ok(entity.Id.ToString()); diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 78b43a002..0bdd15b12 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -53,7 +53,7 @@ namespace IRaCIS.Application.Services { - var rows = await MiniExcel.QueryAsync(@"C:\Users\Administrator\Desktop\Export\NetCore.xlsx"); + var rows = await MiniExcel.QueryAsync(@"C:\Users\Administrator\Desktop\Export\vue.xlsx"); foreach (var row in rows) { From 4f5b7be7b888c6ee96462385566bed8d748b2e92 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 28 Jun 2023 16:22:28 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=A7=A6=E5=8F=91=E6=9B=B4?= =?UTF-8?q?=E6=96=B0json=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/InternationalizationHelper.cs | 31 +++++++++++++++---- .../Common/InternationalizationService.cs | 7 +++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs index ddf14b32d..e12cb271b 100644 --- a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs +++ b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs @@ -17,7 +17,7 @@ namespace IRaCIS.Core.Application.Helper { public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources); - public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value) + public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN) { @@ -28,15 +28,32 @@ namespace IRaCIS.Core.Application.Helper throw new BusinessValidationFailedException("鍥介檯鍖朖son鏂囦欢鐩綍鏈夎"); } - //灏嗚鐩綍涓嬬殑鍥介檯鍖栨枃浠跺叏閮ㄤ慨鏀 - foreach (var filePath in Directory.GetFiles(JsonFileFolder).Where(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) + var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json); + var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json); + + + //鏇存柊json 鏂囦欢 鍚屾椂鏇存柊鍐呭瓨缂撳瓨鐨勬暟鎹 + foreach (var filePath in new string[] { usJsonPath, cnJsonPath }) { var json = await File.ReadAllTextAsync(filePath); JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); // 娣诲姞鎴栨洿鏂版寚瀹氱殑閿煎 - jsonObject[key] = value; + + if (filePath.Contains(StaticData.En_US_Json)) + { + jsonObject[key] = value; + + StaticData.En_US_Dic[key] = value; + } + else + { + jsonObject[key] = valueCN; + + StaticData.Zh_CN_Dic[key] = valueCN; + } + await File.WriteAllTextAsync(filePath, jsonObject.ToString()); @@ -60,8 +77,6 @@ namespace IRaCIS.Core.Application.Helper var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json); - - //鏈湴闈欐佹枃浠跺浗闄呭寲闇瑕 foreach (var tojsonItem in toJsonList) { @@ -82,6 +97,10 @@ namespace IRaCIS.Core.Application.Helper public static void WatchJsonFile(string filePath) { + if (!File.Exists(filePath)) + { + throw new BusinessValidationFailedException("鍥介檯鍖朖son鏂囦欢涓嶅瓨鍦"); + } FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath)); watcher.Changed += (sender, e) => LoadJsonFile(filePath); diff --git a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index 0fa7d246c..a076d8bd6 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using Microsoft.AspNetCore.Authorization; +using IRaCIS.Core.Application.Helper; namespace IRaCIS.Core.Application.Service { @@ -75,6 +76,12 @@ namespace IRaCIS.Core.Application.Service var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true, verifyExp1); + if (addOrEditInternationalization.InternationalizationType == 1) + { + await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, entity.Value, entity.ValueCN); + + } + return ResponseOutput.Ok(entity.Id.ToString()); } From 747ad313e67a2ff77cffc82ecba1a603dab77867 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 28 Jun 2023 17:29:03 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/InternationalizationViewModel.cs | 9 +++++++ .../Common/InternationalizationService.cs | 26 +++++++++++++++++++ .../Service/Common/_MapConfig.cs | 3 +++ 3 files changed, 38 insertions(+) diff --git a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs index 5f2e25a59..371c9a7d4 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs @@ -45,6 +45,15 @@ namespace IRaCIS.Core.Application.ViewModel public int InternationalizationType { get; set; } } + public class BatchAddInternationalization + { + public int InternationalizationType { get; set; } + + public int State { get; set; } + + public List AddList { get; set; } + } + public class InternationalizationSimpleDto { diff --git a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index a076d8bd6..1c7497836 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -63,6 +63,32 @@ namespace IRaCIS.Core.Application.Service return pageList; } + [HttpPost] + public async Task BatchAddInternationalization(BatchAddInternationalization batchAdd) + { + foreach (var item in batchAdd.AddList) + { + + var mapItem = _mapper.Map(item); + + mapItem.InternationalizationType = batchAdd.InternationalizationType; + mapItem.State = batchAdd.State; + + var verifyExp1 = new EntityVerifyExp() + { + VerifyExp = t => t.Code == mapItem.Code && t.InternationalizationType == mapItem.InternationalizationType, + + VerifyMsg = $"璇ョ被鍨嬪凡鏈墈item.Code}鍚嶇О鐨勫浗闄呭寲鏍囪瘑", + IsVerify = true + }; + + var entity = await _internationalizationRepository.InsertOrUpdateAsync(mapItem, false, verifyExp1); + } + + await _internationalizationRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + } public async Task AddOrUpdateInternationalization(InternationalizationAddOrEdit addOrEditInternationalization) { diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index 523e15044..7a4af27fd 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -57,6 +57,9 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap().ReverseMap(); + CreateMap(); + + CreateMap(); CreateMap().ReverseMap(); From db0319bfba255b5de26e8245a144a97213c92cf8 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 28 Jun 2023 17:34:07 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/DTO/InternationalizationViewModel.cs | 7 ++++++- IRaCIS.Core.Application/Service/Common/_MapConfig.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs index 371c9a7d4..a0eec5d13 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs @@ -51,10 +51,15 @@ namespace IRaCIS.Core.Application.ViewModel public int State { get; set; } - public List AddList { get; set; } + public List AddList { get; set; } } + public class BatchAddDto: InternationalizationSimpleDto + { + public string Description { get; set; } = string.Empty; + } + public class InternationalizationSimpleDto { public string Code { get; set; } = string.Empty; diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index 7a4af27fd..fe157b9a3 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -57,7 +57,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap().ReverseMap(); - CreateMap(); + CreateMap(); CreateMap(); From 79ffa3e29addba7ad0c382c1e881a5c9b21183b3 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 28 Jun 2023 17:59:25 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=E6=89=B9=E9=87=8F=E6=8F=90=E4=BA=A4=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=20=E6=9B=B4=E6=96=B0json=20=E4=BB=A5=E5=8F=8A=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/InternationalizationHelper.cs | 60 ++++++++++++++++--- .../DTO/InternationalizationViewModel.cs | 7 ++- .../Common/InternationalizationService.cs | 2 + .../Service/Common/_MapConfig.cs | 2 +- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs index e12cb271b..33c862f7c 100644 --- a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs +++ b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs @@ -1,4 +1,5 @@ -锘縰sing IRaCIS.Core.Domain.Share; +锘縰sing IRaCIS.Core.Application.ViewModel; +using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; @@ -17,21 +18,66 @@ namespace IRaCIS.Core.Application.Helper { public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources); - public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN) + private static void VerifyFolder() { - - - if (!Directory.Exists(JsonFileFolder) || - Directory.GetFiles(JsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) + Directory.GetFiles(JsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase))) { throw new BusinessValidationFailedException("鍥介檯鍖朖son鏂囦欢鐩綍鏈夎"); } + } + + public static async Task BatchAddJsonKeyValueAsync(List batchAddDtos) + { + VerifyFolder(); var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json); var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json); - + + //鏇存柊json 鏂囦欢 鍚屾椂鏇存柊鍐呭瓨缂撳瓨鐨勬暟鎹 + foreach (var filePath in new string[] { usJsonPath, cnJsonPath }) + { + var json = await File.ReadAllTextAsync(filePath); + + JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); + + // 娣诲姞鎴栨洿鏂版寚瀹氱殑閿煎 + + if (filePath.Contains(StaticData.En_US_Json)) + { + foreach (var item in batchAddDtos) + { + jsonObject[item.Code] = item.Value; + + StaticData.En_US_Dic[item.Code] = item.Value; + } + } + else + { + foreach (var item in batchAddDtos) + { + jsonObject[item.Code] = item.Value; + + StaticData.Zh_CN_Dic[item.Code] = item.Value; + } + } + + + await File.WriteAllTextAsync(filePath, jsonObject.ToString()); + + } + } + + public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN) + { + + VerifyFolder(); + + var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json); + var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json); + + //鏇存柊json 鏂囦欢 鍚屾椂鏇存柊鍐呭瓨缂撳瓨鐨勬暟鎹 foreach (var filePath in new string[] { usJsonPath, cnJsonPath }) { diff --git a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs index a0eec5d13..16ed714b1 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs @@ -51,13 +51,16 @@ namespace IRaCIS.Core.Application.ViewModel public int State { get; set; } - public List AddList { get; set; } + public List AddList { get; set; } } - public class BatchAddDto: InternationalizationSimpleDto + public class BatchAddInternationalizationDto { public string Description { get; set; } = string.Empty; + public string Code { get; set; } = string.Empty; + public string Value { get; set; } = string.Empty; + public string ValueCN { get; set; } = string.Empty; } public class InternationalizationSimpleDto diff --git a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index 1c7497836..d6168906a 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -87,6 +87,8 @@ namespace IRaCIS.Core.Application.Service await _internationalizationRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); } diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index fe157b9a3..850a6d541 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -57,7 +57,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap().ReverseMap(); - CreateMap(); + CreateMap(); CreateMap(); From 398a804b4174dd89bb491a07b38804cca30ac72f Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 29 Jun 2023 10:49:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRaCIS.Core.Application.xml | 7 ++++ .../Service/Common/DTO/DictionaryModel.cs | 33 +++++++++++++++++++ .../Service/Common/DictionaryService.cs | 33 +++++++++++++++++++ .../Service/Common/_MapConfig.cs | 4 +++ 4 files changed, 77 insertions(+) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 9b20bf2e4..349f351ff 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -10936,6 +10936,13 @@ + + + 娣诲姞瀛楀吀 鐨勫悓鏃 涓璧锋坊鍔犲瓙椤 --New + + + + New 鏌ヨ鏉′欢 diff --git a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs index 8604f20dd..0ff1c4cf8 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs @@ -165,7 +165,40 @@ namespace IRaCIS.Application.Contracts + public class AddBasicDicAndChild + { + [NotDefault] + public Guid ConfigTypeId { get; set; } + public bool IsEnable { get; set; } + + public string Code { get; set; } = String.Empty; + + public int ShowOrder { get; set; } + public string Description { get; set; } = String.Empty; + + public DicDataTypeEnum DataTypeEnum { get; set; } + + + public List ChildList { get; set; } = new List(); + } + + + public class AddBasicDicChild + { + public string Code { get; set; } = String.Empty; + public string Value { get; set; } = String.Empty; + + public string ValueCN { get; set; } = String.Empty; + + public string ChildGroup { get; set; } = String.Empty; + + public int ShowOrder { get; set; } + + public string Description { get; set; } = String.Empty; + + public bool IsEnable { get; set; } = true; + } diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index f02173ae2..cc5bf300d 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -88,6 +88,39 @@ namespace IRaCIS.Application.Services return ResponseOutput.Ok(entity.Id.ToString()); } + + /// + /// 娣诲姞瀛楀吀 鐨勫悓鏃 涓璧锋坊鍔犲瓙椤 --New + /// + /// + /// + [HttpPost] + public async Task AddBasicDicAndChild(AddBasicDicAndChild addBasicDicAndChild) + { + var verifyExp1 = new EntityVerifyExp() + { + VerifyExp = t => t.Code == addBasicDicAndChild.Code && t.ParentId == null, + VerifyMsg = $"宸叉湁{addBasicDicAndChild.Code}鍚嶇О鐨勫瓧鍏", + IsVerify = true + }; + + + var entity = await _dicRepository.InsertFromDTOAsync(addBasicDicAndChild, false, verifyExp1); + + var childList = _mapper.Map>(addBasicDicAndChild.ChildList); + + foreach (var item in childList) + { + item.DataTypeEnum = addBasicDicAndChild.DataTypeEnum; + item.ParentId = entity.Id; + } + + await _dicRepository.AddRangeAsync(childList); + + await _dicRepository.SaveChangesAsync(); + return ResponseOutput.Ok(entity.Id.ToString()); + } + /// /// New 鏌ヨ鏉′欢 /// diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index 850a6d541..4077d674a 100644 --- a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs @@ -39,6 +39,10 @@ namespace IRaCIS.Core.Application.Service CreateMap().ReverseMap(); + + CreateMap().ForMember(o => o.ChildList, t => t.Ignore()); + CreateMap(); + CreateMap() .ForMember(o => o.ParentChildCodeEnum, t => t.MapFrom(u => u.Parent.ChildCodeEnum)) .ForMember(o => o.Value, t => t.MapFrom(u => u.MappedValue))