parent
db0319bfba
commit
79ffa3e29a
|
@ -1,4 +1,5 @@
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
@ -17,16 +18,61 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
{
|
{
|
||||||
public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources);
|
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) ||
|
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("国际化Json文件目录有误");
|
throw new BusinessValidationFailedException("国际化Json文件目录有误");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task BatchAddJsonKeyValueAsync(List<BatchAddInternationalizationDto> 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 usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json);
|
||||||
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
||||||
|
|
|
@ -51,13 +51,16 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
|
|
||||||
public int State { get; set; }
|
public int State { get; set; }
|
||||||
|
|
||||||
public List<BatchAddDto> AddList { get; set; }
|
public List<BatchAddInternationalizationDto> AddList { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class BatchAddDto: InternationalizationSimpleDto
|
public class BatchAddInternationalizationDto
|
||||||
{
|
{
|
||||||
public string Description { get; set; } = string.Empty;
|
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 class InternationalizationSimpleDto
|
||||||
|
|
|
@ -87,6 +87,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
await _internationalizationRepository.SaveChangesAsync();
|
await _internationalizationRepository.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
CreateMap<Internationalization, InternationalizationView>();
|
CreateMap<Internationalization, InternationalizationView>();
|
||||||
CreateMap<Internationalization, InternationalizationAddOrEdit>().ReverseMap();
|
CreateMap<Internationalization, InternationalizationAddOrEdit>().ReverseMap();
|
||||||
|
|
||||||
CreateMap<BatchAddDto, InternationalizationAddOrEdit>();
|
CreateMap<BatchAddInternationalizationDto, InternationalizationAddOrEdit>();
|
||||||
|
|
||||||
|
|
||||||
CreateMap<PublishLog, PublishLogView>();
|
CreateMap<PublishLog, PublishLogView>();
|
||||||
|
|
Loading…
Reference in New Issue