修改时区 修改时间

IRC_NewDev
hang 2024-03-14 15:59:13 +08:00
parent 64b750b06e
commit 41e5f9fd78
2 changed files with 45 additions and 16 deletions

View File

@ -50,10 +50,29 @@ namespace IRaCIS.Core.API
DateTime dateTime; 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); var serverZoneTime = TimeZoneInfo.ConvertTime(dateTime, _clientTimeZone, TimeZoneInfo.Local);

View File

@ -8,6 +8,7 @@ using IRaCIS.Core.Infrastructure;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using SharpCompress.Common;
namespace IRaCIS.Application.Services.BackGroundJob 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 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<Trial> _trialRepository; private readonly IRepository<Trial> _trialRepository;
private readonly IEasyCachingProvider _provider; private readonly IEasyCachingProvider _provider;
private readonly ILogger<IRaCISCHangfireJob> _logger; private readonly ILogger<IRaCISCHangfireJob> _logger;
@ -124,32 +127,39 @@ namespace IRaCIS.Application.Services.BackGroundJob
//监测Json文件变更 实时刷新数据 //监测Json文件变更 实时刷新数据
WatchJsonFile(usJsonPath);
WatchJsonFile(cnJsonPath);
} if (!File.Exists(usJsonPath)|| !File.Exists(cnJsonPath))
public void WatchJsonFile(string filePath)
{
if (!File.Exists(filePath))
{ {
throw new BusinessValidationFailedException(StaticData.International("IRaCISCHangfireJob_FileNotFound")); throw new BusinessValidationFailedException(StaticData.International("IRaCISCHangfireJob_FileNotFound"));
} }
var watcher = new FileSystemWatcher FileSystemWatcher_US = new FileSystemWatcher
{ {
Path = Path.GetDirectoryName(filePath)!, Path = Path.GetDirectoryName(usJsonPath)!,
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size|NotifyFilters.LastAccess, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size,
Filter = Path.GetFileName(filePath), Filter = Path.GetFileName(usJsonPath),
EnableRaisingEvents = true, EnableRaisingEvents = true,
}; };
// 添加文件更改事件的处理程序
FileSystemWatcher_US.Changed += (sender, e) => LoadJsonFile(usJsonPath);
watcher.Changed += (sender, e) => LoadJsonFile(filePath);
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) private void LoadJsonFile(string filePath)
{ {
Console.WriteLine("刷新json内存数据"); Console.WriteLine("刷新json内存数据");