初步完成代码级重写通用接口功能
This commit is contained in:
@@ -22,32 +22,17 @@ namespace Tnb.Vengine.AppService;
|
||||
[Route("/")]
|
||||
public class VengineAppService : BaseAppService, IVengineAppService
|
||||
{
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
//private readonly ISqlSugarClient _db;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VengineAppService(IDataAccess da)
|
||||
public VengineAppService(IDataAccess da):base(da)
|
||||
{
|
||||
_dataAccess = da;
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
//_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
#region 按模型的id进行增删改查接口
|
||||
/// <summary>
|
||||
/// 获取Vmodel
|
||||
/// </summary>
|
||||
private async Task<Vmodel> GetVmodelAsync(string id)
|
||||
{
|
||||
if (!_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
}
|
||||
return _models[id];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
@@ -55,7 +40,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var arg = input.Adapt<VmQueryInput>();
|
||||
arg.AddQueryParaIf(!string.IsNullOrEmpty(input.id), vm.GetPrimary().code, input.id!);
|
||||
|
||||
var ls = await ListAsync(vmid, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
@@ -116,17 +103,6 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
#endregion 按模型的id进行增删改查接口
|
||||
|
||||
#region 按模型的areaCode和vmcode进行增删改查接口
|
||||
|
||||
private 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];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
@@ -134,7 +110,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var arg = input.Adapt<VmQueryInput>();
|
||||
arg.AddQueryParaIf(!string.IsNullOrEmpty(input.id), vm.GetPrimary().code, input.id!);
|
||||
|
||||
var ls = await ListAsync(areaCode, vmCode, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user