从缓存读取数据连接和用户名称

This commit is contained in:
2023-03-28 17:01:15 +08:00
parent d636034f06
commit bf847beeae
3 changed files with 344 additions and 312 deletions

View File

@@ -13,6 +13,7 @@ using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using SqlSugar;
namespace JNPF.Systems;
@@ -42,17 +43,21 @@ public class DbLinkService : IDbLinkService, IDynamicApiController, ITransient
/// </summary>
private readonly IDataBaseManager _dataBaseManager;
private readonly IMemoryCache _memCache;
/// <summary>
/// 初始化一个<see cref="DbLinkService"/>类型的新实例.
/// </summary>
public DbLinkService(
ISqlSugarRepository<DbLinkEntity> repository,
IDictionaryDataService dictionaryDataService,
IDataBaseManager dataBaseManager)
IDataBaseManager dataBaseManager,
IMemoryCache memCache)
{
_repository = repository;
_dictionaryDataService = dictionaryDataService;
_dataBaseManager = dataBaseManager;
_memCache = memCache;
}
#region GET
@@ -313,7 +318,13 @@ public class DbLinkService : IDbLinkService, IDynamicApiController, ITransient
[NonAction]
public async Task<DbLinkEntity> GetInfo(string id)
{
var model = await _memCache.GetOrCreateAsync($"DbLink_{id}", async entry =>
{
//entry.AbsoluteExpiration = DateTime.Now.AddMinutes(60);
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return await _repository.GetFirstAsync(m => m.Id == id && m.DeleteMark == null);
});
return model;
}
#endregion
}

View File

@@ -22,6 +22,7 @@ using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
using JNPF.VisualDev.Interfaces;
using JNPF.WorkFlow.Entitys.Entity;
using Mapster;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using SqlSugar;
@@ -54,6 +55,11 @@ public class FormDataParsing : ITransient
/// </summary>
private readonly ICacheManager _cacheManager;
/// <summary>
/// 缓存管理.
/// </summary>
private readonly IMemoryCache _memCache;
/// <summary>
/// 服务基础仓储.
/// </summary>
@@ -72,13 +78,15 @@ public class FormDataParsing : ITransient
ICacheManager cacheManager,
IDataBaseManager databaseService,
IDataInterfaceService dataInterfaceService,
ISqlSugarRepository<VisualDevEntity> context)
ISqlSugarRepository<VisualDevEntity> context,
IMemoryCache memCache)
{
_userManager = userManager;
_cacheManager = cacheManager;
_databaseService = databaseService;
_dataInterfaceService = dataInterfaceService;
_db = context;
_memCache = memCache;
}
#endregion
@@ -1707,18 +1715,30 @@ public class FormDataParsing : ITransient
}
break;
case JnpfKeyConst.CURRDEPT:
dataMap[key] = (await _db.AsSugarClient().Queryable<OrganizeEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
dataMap[key] = await _memCache.GetOrCreateAsync($"organizeId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return (await _db.AsSugarClient().Queryable<OrganizeEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
});
break;
case JnpfKeyConst.MODIFYUSER:
case JnpfKeyConst.CREATEUSER:
dataMap[key] = await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.Id == dataValue.ToString()).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
dataMap[key] = await _memCache.GetOrCreateAsync($"userId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return await _db.AsSugarClient().Queryable<UserEntity>().Where(x => x.Id == dataValue.ToString()).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)).FirstAsync();
});
break;
case JnpfKeyConst.MODIFYTIME:
case JnpfKeyConst.CREATETIME:
dataMap[key] = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dataMap[key].ToString().ParseToDateTime());
break;
case JnpfKeyConst.CURRPOSITION:
dataMap[key] = (await _db.AsSugarClient().Queryable<PositionEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
dataMap[key] = await _memCache.GetOrCreateAsync($"positionId_{dataValue}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromSeconds(60);
return (await _db.AsSugarClient().Queryable<PositionEntity>().FirstAsync(x => x.Id == dataValue.ToString()))?.FullName;
});
break;
case JnpfKeyConst.POPUPTABLESELECT:
case JnpfKeyConst.POPUPSELECT:

View File

@@ -205,6 +205,7 @@ public class RunService : IRunService, ITransient
{
if (templateInfo.SingleFormData.Any(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()))
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson != null && x.__config__.templateJson.Any()).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
else
realList.list = await _formDataParsing.GetKeyData(templateInfo.SingleFormData.Where(x => x.__config__.templateJson == null).ToList(), realList.list, templateInfo.ColumnData, actionType, templateInfo.WebType, primaryKey);
// 如果是无表数据并且排序字段不为空,再进行数据排序