缓存修改

IRC_NewDev
he 2024-09-02 17:30:56 +08:00
parent 5d946d820e
commit 4d2589c112
2 changed files with 45 additions and 23 deletions

View File

@ -31,6 +31,29 @@ namespace IRaCIS.Core.Application.Helper
public static string UserAutoLoginOut(Guid userId) => $"UserAutoLoginOut:{userId}";
// 你可以为其他实体和模块定义更多的键
/// <summary>
/// 跳过阅片
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static string SkipReadingCacheKey(Guid userId) => $"{userId}SkipReadingCache";
/// <summary>
/// 开始阅片时间
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static string StartReadingTimeKey(Guid userId) => $"{userId}StartReadingTime";
/// <summary>
/// 开始休息时间
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static string StartRestTime(Guid userId) => $"{userId}StartRestTime";
}
public static class CacheHelper

View File

@ -25,6 +25,8 @@ using Microsoft.Extensions.Options;
using System.Linq;
using NPOI.SS.Formula.Functions;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using IRaCIS.Core.Application.Helper;
using ZiggyCreatures.Caching.Fusion;
namespace IRaCIS.Application.Services
{
@ -54,7 +56,6 @@ namespace IRaCIS.Application.Services
IRepository<OrganInfo> _organInfoRepository,
IRepository<TrialDocument> _trialDocumentRepository,
IRepository<User> _userRepository,
IEasyCachingProvider _provider,
ILuganoCalculateService _luganoCalculateService,
IRepository<ReadingCustomTag> _readingCustomTagRepository,
IRepository<ReadingTaskQuestionMark> _readingTaskQuestionMarkRepository,
@ -2656,8 +2657,8 @@ namespace IRaCIS.Application.Services
[HttpPost]
public async Task<bool> ClearSkipReadingCache()
{
var clearSkipReadingCacheKey = _userInfo.Id.ToString() + "SkipReadingCache";
_provider.Remove(clearSkipReadingCacheKey);
await _fusionCache.RemoveAsync(CacheKeys.SkipReadingCacheKey(_userInfo.Id));
return true;
}
@ -2670,20 +2671,18 @@ namespace IRaCIS.Application.Services
[HttpPost]
public async Task<bool> SetSkipReadingCache(SetSkipReadingCacheInDto inDto )
{
var clearSkipReadingCacheKey = _userInfo.Id.ToString() + "SkipReadingCache";
var clearSkipReadingCache = _provider.Get<string>(clearSkipReadingCacheKey).Value;
var clearSkipReadingCache = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.SkipReadingCacheKey(_userInfo.Id));
if (clearSkipReadingCache == null|| clearSkipReadingCache==string.Empty)
{
List<Guid> cacheIds = new List<Guid>();
cacheIds.Add(inDto.VisitTaskId);
_provider.Set(clearSkipReadingCacheKey, JsonConvert.SerializeObject(cacheIds), TimeSpan.FromHours(24));
await _fusionCache.SetAsync<string>(CacheKeys.SkipReadingCacheKey(_userInfo.Id), JsonConvert.SerializeObject(cacheIds), TimeSpan.FromHours(24));
}
else
{
List<Guid>? cacheIds=JsonConvert.DeserializeObject<List<Guid>>(clearSkipReadingCache);
cacheIds.Add(inDto.VisitTaskId);
_provider.Set(clearSkipReadingCacheKey, JsonConvert.SerializeObject(cacheIds), TimeSpan.FromHours(24));
await _fusionCache.SetAsync<string>(CacheKeys.SkipReadingCacheKey(_userInfo.Id), JsonConvert.SerializeObject(cacheIds), TimeSpan.FromHours(24));
}
return true;
}
@ -2714,8 +2713,9 @@ namespace IRaCIS.Application.Services
#region 跳过阅片
var clearSkipReadingCacheKey = _userInfo.Id.ToString() + "SkipReadingCache";
var clearSkipReadingCache = _provider.Get<string>(clearSkipReadingCacheKey).Value;
var clearSkipReadingCache = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.SkipReadingCacheKey(_userInfo.Id));
List<Guid> cacheSkipIds = new List<Guid>();
if (clearSkipReadingCache != null && clearSkipReadingCache != string.Empty)
{
@ -3014,11 +3014,12 @@ namespace IRaCIS.Application.Services
int readingMinute = _verifyConfig.CurrentValue.ContinuousReadingTimeMin; // 为60整数
int restMinute = _verifyConfig.CurrentValue.ReadingRestTimeMin; //
var startReadingTime = _provider.Get<string>(startReadingTimeKey).Value;
var startRestTime = _provider.Get<string>(startRestTimeKey).Value;
var startReadingTime = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.StartReadingTimeKey(_userInfo.Id));
var startRestTime = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.StartRestTime(_userInfo.Id));
if (startReadingTime == null && startRestTime == null)
{
_provider.Set(startReadingTimeKey, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
await _fusionCache.SetAsync<string>(CacheKeys.StartReadingTimeKey(_userInfo.Id), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
}
else if (startRestTime != null)
{
@ -3031,8 +3032,8 @@ namespace IRaCIS.Application.Services
else
{
// 休息时间>10分钟 删除休息时间的缓存 记录开始阅片时间
_provider.Remove(startRestTimeKey);
_provider.Set(startReadingTimeKey, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
await _fusionCache.RemoveAsync(CacheKeys.StartRestTime(_userInfo.Id));
await _fusionCache.SetAsync<string>(CacheKeys.StartReadingTimeKey(_userInfo.Id), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
}
}
@ -3044,9 +3045,9 @@ namespace IRaCIS.Application.Services
int timespanMin = (DateTime.Now - cacheDate).Minutes;
if (timespanMin > readingMinute)
{
await _fusionCache.RemoveAsync(CacheKeys.StartReadingTimeKey(_userInfo.Id));
await _fusionCache.SetAsync<string>(CacheKeys.StartRestTime(_userInfo.Id), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
_provider.Remove(startReadingTimeKey);
_provider.Set(startRestTimeKey, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
throw new BusinessValidationFailedException(_localizer["ReadingImage_NeedRest", readingMinute / 60m, restMinute]);
}
@ -3068,25 +3069,23 @@ namespace IRaCIS.Application.Services
userID = _userInfo.Id;
}
var startReadingTimeKey = userID.ToString() + "StartReadingTime";
var startRestTimeKey = userID.ToString() + "StartRestTime";
//int readingMinute = 120; // 为60整数
int restMinute = 10; //
var startReadingTime = _provider.Get<string>(startReadingTimeKey).Value;
var startRestTime = _provider.Get<string>(startRestTimeKey).Value;
var startReadingTime = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.StartReadingTimeKey(_userInfo.Id));
var startRestTime = await _fusionCache.GetOrDefaultAsync<string>(CacheKeys.StartRestTime(_userInfo.Id));
if (startRestTime != null)
{
var cacheStartRestTime = DateTime.Parse(startRestTime!.ToString());
int timespanMin = (DateTime.Now - cacheStartRestTime).Minutes;
if (timespanMin > restMinute)
{
_provider.Remove(startRestTimeKey);
await _fusionCache.RemoveAsync(CacheKeys.StartRestTime(_userInfo.Id));
}
}
else if (startReadingTime != null)
{
_provider.Set(startReadingTimeKey, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
await _fusionCache.SetAsync<string>(CacheKeys.StartReadingTimeKey(_userInfo.Id), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromHours(48));
}
return true;
}