From 41e5f9fd7866aa9c358c5224ebba4dc5a2227f67 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 14 Mar 2024 15:59:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E5=8C=BA=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NewtonsoftJson/JSONTimeZoneConverter.cs | 23 ++++++++++- .../BackGroundJob/IRaCISCHangfireJob.cs | 38 ++++++++++++------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs index cd4e942e8..0968daf29 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/NewtonsoftJson/JSONTimeZoneConverter.cs @@ -50,10 +50,29 @@ namespace IRaCIS.Core.API DateTime dateTime; - if (DateTime.TryParse((string)reader.Value, out dateTime) == false) + if (reader.ValueType == typeof(DateTime) || reader.ValueType == typeof(DateTime?)) { - return null; + DateTime? nullableDateTime = reader.Value as DateTime?; + + + if (nullableDateTime != null && nullableDateTime.HasValue) + { + dateTime = nullableDateTime.Value; + } + else + { + return null; + } } + else + { + if (DateTime.TryParse((string)reader.Value, out dateTime) == false) + { + return null; + } + } + + // 将客户端时间转换为服务器时区的时间 var serverZoneTime = TimeZoneInfo.ConvertTime(dateTime, _clientTimeZone, TimeZoneInfo.Local); diff --git a/IRaCIS.Core.Application/BackGroundJob/IRaCISCHangfireJob.cs b/IRaCIS.Core.Application/BackGroundJob/IRaCISCHangfireJob.cs index 984e30ce5..81da08136 100644 --- a/IRaCIS.Core.Application/BackGroundJob/IRaCISCHangfireJob.cs +++ b/IRaCIS.Core.Application/BackGroundJob/IRaCISCHangfireJob.cs @@ -8,6 +8,7 @@ using IRaCIS.Core.Infrastructure; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using SharpCompress.Common; namespace IRaCIS.Application.Services.BackGroundJob { @@ -24,6 +25,8 @@ namespace IRaCIS.Application.Services.BackGroundJob { public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources); + public static FileSystemWatcher FileSystemWatcher_US { get; set; } + public static FileSystemWatcher FileSystemWatcher_CN { get; set; } private readonly IRepository _trialRepository; private readonly IEasyCachingProvider _provider; private readonly ILogger _logger; @@ -124,32 +127,39 @@ namespace IRaCIS.Application.Services.BackGroundJob //监测Json文件变更 实时刷新数据 - WatchJsonFile(usJsonPath); - WatchJsonFile(cnJsonPath); - } - - public void WatchJsonFile(string filePath) - { - if (!File.Exists(filePath)) + if (!File.Exists(usJsonPath)|| !File.Exists(cnJsonPath)) { throw new BusinessValidationFailedException(StaticData.International("IRaCISCHangfireJob_FileNotFound")); } - var watcher = new FileSystemWatcher + FileSystemWatcher_US = new FileSystemWatcher { - Path = Path.GetDirectoryName(filePath)!, - NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size|NotifyFilters.LastAccess, - Filter = Path.GetFileName(filePath), + Path = Path.GetDirectoryName(usJsonPath)!, + NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size, + Filter = Path.GetFileName(usJsonPath), EnableRaisingEvents = true, - - }; - watcher.Changed += (sender, e) => LoadJsonFile(filePath); + }; + // 添加文件更改事件的处理程序 + FileSystemWatcher_US.Changed += (sender, e) => LoadJsonFile(usJsonPath); + + + FileSystemWatcher_CN = new FileSystemWatcher + { + Path = Path.GetDirectoryName(cnJsonPath)!, + NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size, + Filter = Path.GetFileName(cnJsonPath), + EnableRaisingEvents = true, + + }; + FileSystemWatcher_CN.Changed += (sender, e) => LoadJsonFile(cnJsonPath); } + + private void LoadJsonFile(string filePath) { Console.WriteLine("刷新json内存数据");