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

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

@@ -4,6 +4,7 @@
/////////////////////////////////////////////////////////////////////////////////
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Manager;
using JNPF.Common.Security;
using JNPF.ViewEngine;
@@ -13,26 +14,29 @@ using SqlSugar;
using Tnb.Core;
using Tnb.Vengine.DataAccess;
using Tnb.Vengine.Domain;
using Yitter.IdGenerator;
namespace Tnb.Vengine.AppService;
/// <summary>
/// 视图模型服务类
/// 视图模型服务类,
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, KeepVerb = true, Order = 1102)]
[Route("api/[area]/[controller]/[action]")]
//[Route("api/[area]/[controller]/[action]")]
public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel, VmQueryInput, VmGetListInput, Vmodel, VmodelCreateInput, VmodelUpdateInput>, IVmodelAppService
{
private readonly IViewEngine _viewEngine;
private readonly ICacheManager _cache;
private readonly IUserManager _user;
/// <summary>
/// 构造函数
/// </summary>
public VmodelAppService(IDataAccess da, IViewEngine viewEngine, ICacheManager cache) : base(da)
public VmodelAppService(IDataAccess da, IViewEngine viewEngine, ICacheManager cache, IUserManager user) : base(da)
{
_viewEngine = viewEngine;
_cache = cache;
_user = user;
}
/// <summary>
@@ -65,7 +69,8 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
[NonAction]
public override async Task<PagedOutput<Vmodel>> ListAsync(VmQueryInput input)
{
var q = _db.Queryable<Vmodel>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.vmCode.Contains(input.k!) || a.vmName.Contains(input.k!));
var q = _db.Queryable<Vmodel>().Where(a => a.deleted == 0)
.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);
return PagedOutput.Create(total, data);
@@ -77,10 +82,12 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
public override async Task<dynamic> CreateAsync(VmodelCreateInput input)
{
ThrowIf.IsNull(input.data);
//ArgumentNullException.ThrowIfNull(input.data);
Vmodel vm = input.data.ToObject<Vmodel>();
Vmodel vm = input.data.Adapt<Vmodel>();
vm.id = YitIdHelper.NextId().ToString();
vm.areaCode = vm.areaCode.ToKebab();
vm.vmCode = vm.vmCode.ToKebab();
vm.createTime = DateTime.Now;
vm.createId = _user.UserId;
await _db.Insertable(vm).ExecuteCommandAsync();
return vm;
}
@@ -91,11 +98,14 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
public override async Task<dynamic> UpdateAsync(VmodelUpdateInput input)
{
ThrowIf.IsNull(input.data);
//ArgumentNullException.ThrowIfNull(input.data);
Vmodel vm = input.data.ToObject<Vmodel>();
ThrowIf.IsNullOrEmpty(input.data.id, $"更新数据时主键(id)不可为空");
Vmodel vm = input.data.Adapt<Vmodel>();
vm.areaCode = vm.areaCode.ToKebab();
vm.vmCode = vm.vmCode.ToKebab();
vm.navProps.ForEach(a => a.naviModel = null);
vm.modifyTime = DateTime.Now;
vm.modifyId = _user.UserId;
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(vm.id));
return vm;
@@ -106,7 +116,7 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
/// </summary>
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
{
var ret = await _db.Deleteable<Vmodel>(input.id).ExecuteCommandAsync();
var ret = await _db.Updateable<Vmodel>().SetColumns(a => a.deleted, 1).Where(a => a.id == input.id).ExecuteCommandAsync();
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(input.id!));
return ret;
}