初步完成代码级重写通用接口功能

This commit is contained in:
2023-11-17 14:05:05 +08:00
parent 47fe9030d6
commit e5ab4d6887
12 changed files with 177 additions and 145 deletions

View File

@@ -5,6 +5,8 @@
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using Tnb.Vengine.DataAccess;
using Tnb.Vengine.Domain;
namespace Tnb.Vengine.AppService;
@@ -13,6 +15,37 @@ namespace Tnb.Vengine.AppService;
/// </summary>
public class BaseAppService : IDynamicApiController, ITransient
{
protected readonly IDataAccess _dataAccess;
private readonly Dictionary<string, Vmodel> _models = new();
public BaseAppService(IDataAccess dataAccess)
{
_dataAccess = dataAccess;
}
/// <summary>
/// 根据id获取Vmodel
/// </summary>
protected async Task<Vmodel> GetVmodelAsync(string id)
{
if (!_models.ContainsKey(id))
{
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
}
return _models[id];
}
/// <summary>
/// 根据areaCode和vmCode获取Vmodel
/// </summary>
protected async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
{
var key = areaCode + "/" + vmCode;
if (!_models.ContainsKey(key))
{
_models[key] = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
}
return _models[key];
}
}
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 100)]