修复排序错误
This commit is contained in:
@@ -24,6 +24,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
{
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -34,6 +35,19 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Vmodel
|
||||
/// </summary>
|
||||
private async Task<Vmodel> GetVmodelAsync(string id)
|
||||
{
|
||||
if (_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
}
|
||||
return _models[id];
|
||||
}
|
||||
|
||||
|
||||
#region 按模型的id进行增删改查接口
|
||||
|
||||
/// <summary>
|
||||
@@ -42,14 +56,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpGet("api/[area]/[controller]/{vmid}/get")]
|
||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var ls = await ListAsync(vmid, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -59,14 +68,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpGet("api/[area]/[controller]/{vmid}/get-list")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(input.q))
|
||||
{
|
||||
arg.q = input.q.ToObject<DObject>();
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls;
|
||||
return await ListAsync(vmid, input.ToQueryInput());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,7 +77,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpPost("api/[area]/[controller]/{vmid}/list")]
|
||||
public async Task<VmPagedOutput> ListAsync(string vmid, [FromBody] VmQueryInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||
return ls;
|
||||
}
|
||||
@@ -86,7 +88,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpPost("api/[area]/[controller]/{vmid}/create")]
|
||||
public async Task<dynamic> CreateAsync(string vmid, [FromBody] VmCreateInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
@@ -97,7 +99,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpPut("api/[area]/[controller]/{vmid}/update")]
|
||||
public async Task<dynamic> UpdateAsync(string vmid, [FromBody] VmUpdateInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
@@ -108,7 +110,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpDelete("api/[area]/[controller]/{vmid}/delete")]
|
||||
public async Task<dynamic> DeleteAsync(string vmid, [FromQuery] VmDeleteInput input)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
@@ -119,8 +121,12 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
|
||||
private async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
||||
{
|
||||
var vm = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||
return vm;
|
||||
var key = areaCode + "/" + vmCode;
|
||||
if (_models.ContainsKey(key))
|
||||
{
|
||||
_models[key] = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||
}
|
||||
return _models[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -130,13 +136,8 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var ls = await ListAsync(areaCode, vmCode, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -146,14 +147,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpGet("api/{areaCode}/{vmCode}/get-list")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(input.q))
|
||||
{
|
||||
arg.q = input.q.ToObject<DObject>();
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls;
|
||||
return await ListAsync(areaCode, vmCode, input.ToQueryInput());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Aop.Api.Domain;
|
||||
using JNPF.Common.Contracts;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -20,10 +23,17 @@ namespace Tnb.Vengine.AppService;
|
||||
[Authorize]
|
||||
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, TCreateInput, TUpdateInput> : BaseAppService
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
where TQueryInput : VmQueryInput
|
||||
where TGetListInput : VmGetListInput
|
||||
where TCreateInput : VmCreateInput
|
||||
where TUpdateInput : VmUpdateInput
|
||||
{
|
||||
protected readonly IDataAccess _dataAccess;
|
||||
protected readonly ISqlSugarClient _db;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -37,71 +47,86 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
||||
protected virtual async Task<Vmodel> GetVmodelAsync()
|
||||
{
|
||||
var tp = typeof(TEntity);
|
||||
string? area = null, code = null;
|
||||
var vset = tp.GetCustomAttribute<VmodelSettingAttribute>();
|
||||
string? id = null, area = null, code = null;
|
||||
var vset = tp.GetCustomAttribute<VmodelAttribute>();
|
||||
if (vset != null)
|
||||
{
|
||||
id = vset.Id;
|
||||
area = vset.Area;
|
||||
code = vset.Code;
|
||||
}
|
||||
if (string.IsNullOrEmpty(area))
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
ThrowIf.IsNullOrEmpty(tp.Namespace, $"类型 {nameof(tp)} 的命名空间不可为空");
|
||||
area = tp.Namespace.RemovePreFix(ModuleConst.NsPrefix + ".").Replace(".Domain", "").Replace(".Entities", "").ToKebab();
|
||||
if (_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
//_models[_models[id].fullCode] = _models[id];
|
||||
}
|
||||
return _models[id];
|
||||
}
|
||||
if (string.IsNullOrEmpty(code))
|
||||
else
|
||||
{
|
||||
code = tp.Name.ToKebab();
|
||||
if (string.IsNullOrEmpty(area))
|
||||
{
|
||||
ThrowIf.IsNullOrEmpty(tp.Namespace, $"类型 {nameof(tp)} 的命名空间不可为空");
|
||||
area = tp.Namespace.RemovePreFix(ModuleConst.NsPrefix + ".").Replace(".Domain", "").Replace(".Entities", "").ToKebab();
|
||||
}
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
code = tp.Name.ToKebab();
|
||||
}
|
||||
var key = area + "/" + code;
|
||||
if (_models.ContainsKey(key))
|
||||
{
|
||||
_models[key] = await _dataAccess.GetVmodelAsync(area, code, false);
|
||||
}
|
||||
return _models[key];
|
||||
}
|
||||
var vm = await _dataAccess.GetVmodelAsync(area, code, false);
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public virtual async Task<dynamic> GetAsync([FromQuery] VmGetInput input)
|
||||
public virtual async Task<TGetOutput> GetAsync([FromQuery] TGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||
TQueryInput arg = input.Adapt<TQueryInput>();
|
||||
if (input.id != null)
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||
}
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||
return ls.items.FirstOrDefault()!;
|
||||
|
||||
var data = (await ListAsync(arg)).items.FirstOrDefault();
|
||||
return data == null ? default! : data.Adapt<TGetOutput>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public virtual async Task<VmPagedOutput> GetListAsync([FromQuery] VmGetListInput input)
|
||||
public virtual async Task<PagedOutput<TGetListOutput>> GetListAsync([FromQuery] TGetListInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input.ToListInput());
|
||||
return ls;
|
||||
return await ListAsync(input.Adapt<TQueryInput>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public virtual async Task<VmPagedOutput> ListAsync([FromBody] VmQueryInput input)
|
||||
public virtual async Task<PagedOutput<TGetListOutput>> ListAsync([FromBody] TQueryInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||
return ls;
|
||||
return ls.ToPagedOutput<TGetListOutput>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public virtual async Task<dynamic> CreateAsync([FromBody] VmCreateInput input)
|
||||
public virtual async Task<dynamic> CreateAsync([FromBody] TCreateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
@@ -112,7 +137,7 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
[HttpPut]
|
||||
public virtual async Task<dynamic> UpdateAsync([FromBody] VmUpdateInput input)
|
||||
public virtual async Task<dynamic> UpdateAsync([FromBody] TUpdateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
@@ -129,4 +154,47 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 泛型变种
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, VmCreateInput, VmUpdateInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
where TGetListInput : VmGetListInput
|
||||
where TQueryInput : VmQueryInput
|
||||
{
|
||||
public VengineAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, DObject, VmCreateInput, VmUpdateInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
where TGetListInput : VmGetListInput
|
||||
where TQueryInput : VmQueryInput
|
||||
{
|
||||
public VengineAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, VmQueryInput, VmGetListInput, DObject, VmCreateInput, VmUpdateInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
{
|
||||
public VengineAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity> :
|
||||
VengineAppService<TEntity, VmGetInput, dynamic, VmQueryInput, VmGetListInput, dynamic, VmCreateInput, VmUpdateInput>
|
||||
where TEntity : Entity
|
||||
{
|
||||
public VengineAppService(IDataAccess da) : base(da)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF;
|
||||
using JNPF.Common.Manager;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.ViewEngine;
|
||||
using Mapster;
|
||||
@@ -23,13 +24,15 @@ namespace Tnb.Vengine.AppService;
|
||||
public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||
{
|
||||
private readonly IViewEngine _viewEngine;
|
||||
private readonly ICacheManager _cache;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VmodelAppService(IDataAccess da, IViewEngine viewEngine) : base(da)
|
||||
public VmodelAppService(IDataAccess da, IViewEngine viewEngine, ICacheManager cache) : base(da)
|
||||
{
|
||||
_viewEngine = viewEngine;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,21 +62,19 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
||||
public override async Task<PagedOutput<dynamic>> GetListAsync(VmGetListInput input)
|
||||
{
|
||||
return await ListAsync(input.ToQueryInput());
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public override async Task<PagedOutput<dynamic>> ListAsync(VmQueryInput input)
|
||||
{
|
||||
VmPagedOutput ret = new();
|
||||
var q = _db.Queryable<Vmodel>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.vmCode.Contains(input.k!) || a.vmName.Contains(input.k!));
|
||||
RefAsync<int> total = 0;
|
||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||
ret.total = total;
|
||||
ret.items = data.Adapt<List<DObject>>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public override Task<VmPagedOutput> ListAsync(VmQueryInput input)
|
||||
{
|
||||
return base.ListAsync(input);
|
||||
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,6 +103,7 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||
vm.vmCode = vm.vmCode.ToKebab();
|
||||
vm.navProps.ForEach(a => a.naviModel = null);
|
||||
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(vm.id));
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -111,6 +113,7 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||
{
|
||||
var ret = await _db.Deleteable<Vmodel>(input.id).ExecuteCommandAsync();
|
||||
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(input.id!));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,15 +42,13 @@ public class VmodelPageAppService : VengineAppService<VmodelPage>, IVmodelPageAp
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
||||
public override async Task<PagedOutput<dynamic>> ListAsync(VmQueryInput input)
|
||||
{
|
||||
VmPagedOutput ret = new();
|
||||
var q = _db.Queryable<VmodelPage>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.code.Contains(input.k!) || a.name.Contains(input.k!));
|
||||
RefAsync<int> total = 0;
|
||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||
ret.total = total;
|
||||
ret.items = data.Adapt<List<DObject>>();
|
||||
return ret;
|
||||
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user