fix 先移除redis优化
This commit is contained in:
@@ -6,23 +6,22 @@ using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
public class DevicePermissionService : IDevicePermissionService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public DevicePermissionService(IDbContext dbContext, RedisCache redisCache)
|
||||
public DevicePermissionService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_redisCache = redisCache;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task AssignAsync(DevicePermissionSaveReuqest reuqest)
|
||||
@@ -63,42 +62,36 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
public async Task GenerateDeviceTasksAsync(Func<Task> func, List<string> userNos)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
//var redisKey = "devicePermissions:" + _currentUser.GetStringTenantId();
|
||||
|
||||
//获取当前所有人的权限
|
||||
if (userNos.IsEmpty())
|
||||
userNos = await GetPermissionUserNosAsync();
|
||||
|
||||
var beforeDic = new Dictionary<string, List<Guid>>();
|
||||
if (await _redisCache.KeyExistsAsync("devicePermissions"))
|
||||
{
|
||||
var cache = await _redisCache.StringGetAsync<Dictionary<string, List<Guid>>>("devicePermissions");
|
||||
if (cache?.Any() == true)
|
||||
{
|
||||
beforeDic = cache;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
beforeDic = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
}
|
||||
var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos); // new Dictionary<string, List<Guid>>();
|
||||
//if (await _redisCache.KeyExistsAsync(redisKey))
|
||||
//{
|
||||
// var cache = await _redisCache.StringGetAsync<Dictionary<string, List<Guid>>>(redisKey);
|
||||
// if (cache?.Any() == true)
|
||||
// {
|
||||
// beforeDic = cache;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// beforeDic = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
//}
|
||||
|
||||
await Console.Out.WriteLineAsync($"获取当前所有人的权限耗时:{sw.ElapsedMilliseconds}");
|
||||
|
||||
sw.Restart();
|
||||
//业务处理
|
||||
await func();
|
||||
await Console.Out.WriteLineAsync($"业务处理耗时:{sw.ElapsedMilliseconds}");
|
||||
|
||||
sw.Restart();
|
||||
//获取业务处理后所有人的权限
|
||||
var nextUserNos = await GetPermissionUserNosAsync();
|
||||
if (nextUserNos.Any())
|
||||
userNos = userNos.Concat(nextUserNos).Distinct().ToList();
|
||||
|
||||
var currentDic = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
await Console.Out.WriteLineAsync($"获取业务处理后所有人的权限耗时:{sw.ElapsedMilliseconds}");
|
||||
|
||||
sw.Restart();
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var waitTasks = new List<DeviceTaskEntity>();
|
||||
foreach (var userNo in userNos)
|
||||
@@ -145,15 +138,10 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
waitTasks.AddRange(toDeleted.Concat(toAdd).ToList());
|
||||
}
|
||||
|
||||
await Console.Out.WriteLineAsync($"比对任务生成耗时:{sw.ElapsedMilliseconds}");
|
||||
|
||||
if (waitTasks.Any())
|
||||
{
|
||||
sw.Restart();
|
||||
await _redisCache.StringSetAsync("devicePermissions", JsonConvert.SerializeObject(currentDic));
|
||||
//await _redisCache.StringSetAsync(redisKey, JsonConvert.SerializeObject(currentDic));
|
||||
await _dbContext.InsertAsync(waitTasks);
|
||||
|
||||
await Console.Out.WriteLineAsync($"任务写入耗时:{sw.ElapsedMilliseconds}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user