Compare commits

..

No commits in common. "5f6b174dd9891be3eed04a73e59b83e70369e734" and "47706913cad593417216cdcd8c2399ee82fa88b6" have entirely different histories.

2 changed files with 23 additions and 45 deletions

View File

@ -31,29 +31,6 @@ namespace IRaCIS.Core.Application.Helper
public static string UserAutoLoginOut(Guid userId) => $"UserAutoLoginOut:{userId}"; 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 public static class CacheHelper

View File

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