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..33c862f7c 100644 --- a/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs +++ b/IRaCIS.Core.Application/Helper/InternationalizationHelper.cs @@ -1,5 +1,8 @@ -锘縰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; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -13,32 +16,164 @@ 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) + private static void VerifyFolder() { - - 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))) + 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 }); // 娣诲姞鎴栨洿鏂版寚瀹氱殑閿煎 - jsonObject[key] = value; + + 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 }) + { + var json = await File.ReadAllTextAsync(filePath); + + JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); + + // 娣诲姞鎴栨洿鏂版寚瀹氱殑閿煎 + + 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()); } } + + 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) + { + if (!File.Exists(filePath)) + { + throw new BusinessValidationFailedException("鍥介檯鍖朖son鏂囦欢涓嶅瓨鍦"); + } + + 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 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/DTO/InternationalizationViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs index c4f2f3fc9..16ed714b1 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/InternationalizationViewModel.cs @@ -38,13 +38,37 @@ 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; 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 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 + { + 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/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/InternationalizationService.cs b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs index ebbcc3f58..d6168906a 100644 --- a/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs +++ b/IRaCIS.Core.Application/Service/Common/InternationalizationService.cs @@ -8,6 +8,9 @@ using IRaCIS.Core.Domain.Models; 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 { /// @@ -24,27 +27,70 @@ 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; } + [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) { @@ -56,7 +102,13 @@ namespace IRaCIS.Core.Application.Service IsVerify = true }; - var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true,verifyExp1); + 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()); diff --git a/IRaCIS.Core.Application/Service/Common/_MapConfig.cs b/IRaCIS.Core.Application/Service/Common/_MapConfig.cs index 523e15044..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)) @@ -57,6 +61,9 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap().ReverseMap(); + CreateMap(); + + CreateMap(); CreateMap().ReverseMap(); 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) {