修改泛型通用接口
This commit is contained in:
@@ -35,6 +35,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
#region 按模型的id进行增删改查接口
|
||||
/// <summary>
|
||||
/// 获取Vmodel
|
||||
/// </summary>
|
||||
@@ -47,9 +48,6 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
return _models[id];
|
||||
}
|
||||
|
||||
|
||||
#region 按模型的id进行增删改查接口
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
@@ -68,7 +66,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpGet("api/[area]/[controller]/{vmid}/get-list")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
return await ListAsync(vmid, input.ToQueryInput());
|
||||
return await ListAsync(vmid, input.Adapt<VmQueryInput>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,7 +84,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
[HttpPost("api/[area]/[controller]/{vmid}/create")]
|
||||
public async Task<dynamic> CreateAsync(string vmid, [FromBody] VmCreateInput input)
|
||||
public async Task<dynamic> CreateAsync(string vmid, [FromBody] VmEditInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
@@ -97,7 +95,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
[HttpPut("api/[area]/[controller]/{vmid}/update")]
|
||||
public async Task<dynamic> UpdateAsync(string vmid, [FromBody] VmUpdateInput input)
|
||||
public async Task<dynamic> UpdateAsync(string vmid, [FromBody] VmEditInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
@@ -147,7 +145,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
[HttpGet("api/{areaCode}/{vmCode}/get-list")]
|
||||
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
||||
{
|
||||
return await ListAsync(areaCode, vmCode, input.ToQueryInput());
|
||||
return await ListAsync(areaCode, vmCode, input.Adapt<VmQueryInput>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +163,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
/// 新增 数据
|
||||
/// </summary>
|
||||
[HttpPost("api/{areaCode}/{vmCode}/create")]
|
||||
public async Task<dynamic> CreateAsync(string areaCode, string vmCode, [FromBody] VmCreateInput input)
|
||||
public async Task<dynamic> CreateAsync(string areaCode, string vmCode, [FromBody] VmEditInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
@@ -176,7 +174,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
[HttpPut("api/{areaCode}/{vmCode}/update")]
|
||||
public async Task<dynamic> UpdateAsync(string areaCode, string vmCode, [FromBody] VmUpdateInput input)
|
||||
public async Task<dynamic> UpdateAsync(string areaCode, string vmCode, [FromBody] VmEditInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
|
||||
@@ -28,8 +28,8 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
where TGetInput : VmGetInput
|
||||
where TQueryInput : VmQueryInput
|
||||
where TGetListInput : VmGetListInput
|
||||
where TCreateInput : VmCreateInput
|
||||
where TUpdateInput : VmUpdateInput
|
||||
where TCreateInput : VmEditInput
|
||||
where TUpdateInput : VmEditInput
|
||||
{
|
||||
protected readonly IDataAccess _dataAccess;
|
||||
protected readonly ISqlSugarClient _db;
|
||||
@@ -158,7 +158,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
|
||||
#region 泛型变种
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, VmCreateInput, VmUpdateInput>
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, VmEditInput, VmEditInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
where TGetListInput : VmGetListInput
|
||||
@@ -169,7 +169,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, dynamic, VmCreateInput, VmUpdateInput>
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, dynamic, VmEditInput, VmEditInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
where TGetListInput : VmGetListInput
|
||||
@@ -180,7 +180,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity, TGetInput, TGetOutput> :
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, VmQueryInput, VmGetListInput, dynamic, VmCreateInput, VmUpdateInput>
|
||||
VengineAppService<TEntity, TGetInput, TGetOutput, VmQueryInput, VmGetListInput, dynamic, VmEditInput, VmEditInput>
|
||||
where TEntity : Entity
|
||||
where TGetInput : VmGetInput
|
||||
{
|
||||
@@ -189,7 +189,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput> :
|
||||
}
|
||||
}
|
||||
public class VengineAppService<TEntity> :
|
||||
VengineAppService<TEntity, VmGetInput, dynamic, VmQueryInput, VmGetListInput, dynamic, VmCreateInput, VmUpdateInput>
|
||||
VengineAppService<TEntity, VmGetInput, dynamic, VmQueryInput, VmGetListInput, dynamic, VmEditInput, VmEditInput>
|
||||
where TEntity : Entity
|
||||
{
|
||||
public VengineAppService(IDataAccess da) : base(da)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Tnb.Vengine.AppService;
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, KeepVerb = true, Order = 1102)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel>, IVmodelAppService
|
||||
public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel, VmQueryInput, VmGetListInput, Vmodel, VmodelCreateInput, VmodelUpdateInput>, IVmodelAppService
|
||||
{
|
||||
private readonly IViewEngine _viewEngine;
|
||||
private readonly ICacheManager _cache;
|
||||
@@ -36,51 +36,45 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// 获取一条 数据信息, q参数无效
|
||||
/// </summary>
|
||||
public override async Task<Vmodel> GetAsync(VmodelGetInput input)
|
||||
{
|
||||
//VmodelGetInput para = new VmodelGetInput();
|
||||
//if (!string.IsNullOrEmpty(input.q))
|
||||
//{
|
||||
// para = input.q.ToObject<VmodelGetInput>();
|
||||
//}
|
||||
//var query = _db.Queryable<Vmodel>().Where(a => a.deleted == 0);
|
||||
//Vmodel? vm = null;
|
||||
//if (!string.IsNullOrEmpty(input.id))
|
||||
//{
|
||||
// vm = await _dataAccess.GetVmodelAsync(input.id, para.drill);
|
||||
//}
|
||||
//else if (!string.IsNullOrEmpty(para.areaCode) && !string.IsNullOrEmpty(para.vmCode))
|
||||
//{
|
||||
// vm = await _dataAccess.GetVmodelAsync(para.areaCode, para.vmCode, para.drill);
|
||||
//}
|
||||
//ThrowIf.IsNull(vm, "输入参数有误, id 和 areaCode,vmCode 不可同时为空");
|
||||
return await base.GetAsync(input);
|
||||
var query = _db.Queryable<Vmodel>().Where(a => a.deleted == 0);
|
||||
Vmodel? vm = null;
|
||||
if (!string.IsNullOrEmpty(input.id))
|
||||
{
|
||||
vm = await _dataAccess.GetVmodelAsync(input.id, input.drill);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(input.areaCode) && !string.IsNullOrEmpty(input.vmCode))
|
||||
{
|
||||
vm = await _dataAccess.GetVmodelAsync(input.areaCode, input.vmCode, input.drill);
|
||||
}
|
||||
ThrowIf.IsNull(vm, "输入参数有误, id 和 areaCode,vmCode 不可同时为空");
|
||||
return vm;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 获取多条 数据列表
|
||||
///// </summary>
|
||||
//public override async Task<PagedOutput<dynamic>> GetListAsync(VmGetListInput input)
|
||||
//{
|
||||
// return await ListAsync(input.ToQueryInput());
|
||||
//}
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
public override async Task<PagedOutput<Vmodel>> GetListAsync(VmGetListInput input)
|
||||
{
|
||||
return await ListAsync(input.Adapt<VmQueryInput>());
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public override async Task<PagedOutput<dynamic>> ListAsync(VmQueryInput input)
|
||||
public override async Task<PagedOutput<Vmodel>> 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);
|
||||
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||
return PagedOutput.Create(total, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 模型
|
||||
/// </summary>
|
||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
public override async Task<dynamic> CreateAsync(VmodelCreateInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.data);
|
||||
//ArgumentNullException.ThrowIfNull(input.data);
|
||||
@@ -94,7 +88,7 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
public override async Task<dynamic> UpdateAsync(VmodelUpdateInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.data);
|
||||
//ArgumentNullException.ThrowIfNull(input.data);
|
||||
@@ -104,7 +98,7 @@ public class VmodelAppService : VengineAppService<Vmodel, VmodelGetInput, Vmodel
|
||||
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;
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,29 @@ using Tnb.Vengine.Domain;
|
||||
|
||||
namespace Tnb.Vengine.AppService;
|
||||
|
||||
public class VmodelGetInput : VmGetInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模块code, areaCode和vmCode为一组
|
||||
/// </summary>
|
||||
public string? areaCode { get; set; }
|
||||
/// <summary>
|
||||
/// 模型code, areaCode和vmCode为一组
|
||||
/// </summary>
|
||||
public string? vmCode { get; set; }
|
||||
/// <summary>
|
||||
/// 是否钻取子模型
|
||||
/// </summary>
|
||||
public bool drill { get; set; } = false;
|
||||
}
|
||||
public class VmodelCreateInput : VmEditInput
|
||||
{
|
||||
public new Vmodel? data { get; set; }
|
||||
}
|
||||
public class VmodelUpdateInput : VmEditInput
|
||||
{
|
||||
public new Vmodel? data { get; set; }
|
||||
}
|
||||
public class VmodelCreateFromTableInput
|
||||
{
|
||||
public string? dbCode { get; set; }
|
||||
@@ -17,17 +40,19 @@ public class VmodelCreateFromTableInput
|
||||
public string areaCode { get; set; } = "edp";
|
||||
}
|
||||
|
||||
public class CreatePageFromVmodelInput
|
||||
public class VmodelPageCreateInput : VmEditInput
|
||||
{
|
||||
public new VmodelPage? data { get; set; }
|
||||
}
|
||||
|
||||
public class VmodelPageUpdateInput : VmEditInput
|
||||
{
|
||||
public new VmodelPage? data { get; set; }
|
||||
}
|
||||
|
||||
public class VmodelPageCreateFromVmodelInput
|
||||
{
|
||||
public Guid? viewId { get; set; }
|
||||
public string? vmid { get; set; }
|
||||
}
|
||||
|
||||
public class VmodelGetInput : VmGetInput
|
||||
{
|
||||
public string? areaCode { get; set; }
|
||||
public string? vmCode { get; set; }
|
||||
public string? dbCode { get; set; }
|
||||
public string? tableName { get; set; }
|
||||
public bool drill { get; set; } = false;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace Tnb.Vengine.AppService;
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1104, KeepVerb = true)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class VmodelPageAppService : VengineAppService<VmodelPage>, IVmodelPageAppService
|
||||
public class VmodelPageAppService : VengineAppService<VmodelPage, VmGetInput, VmodelPage, VmQueryInput, VmGetListInput, VmodelPage, VmodelPageCreateInput, VmodelPageUpdateInput>, IVmodelPageAppService
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -29,70 +29,39 @@ public class VmodelPageAppService : VengineAppService<VmodelPage>, IVmodelPageAp
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
public override async Task<dynamic> GetAsync(VmGetInput input)
|
||||
{
|
||||
var query = _db.Queryable<VmodelPage>().Where(a => a.deleted == 0 && a.id == input.id);
|
||||
VmodelPage vm = await query.FirstAsync();
|
||||
return vm;
|
||||
}
|
||||
///// <summary>
|
||||
///// 新增 模型
|
||||
///// </summary>
|
||||
//public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
//{
|
||||
// ThrowIf.IsNull(input.data);
|
||||
// VmodelPage vpage = input.data.Adapt<VmodelPage>();
|
||||
// await _db.Insertable(vpage).ExecuteCommandAsync();
|
||||
// return vpage;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取多条 数据列表
|
||||
/// </summary>
|
||||
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);
|
||||
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增 模型
|
||||
/// </summary>
|
||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.data);
|
||||
VmodelPage vpage = input.data.Adapt<VmodelPage>();
|
||||
await _db.Insertable(vpage).ExecuteCommandAsync();
|
||||
return vpage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.data);
|
||||
if (!input.data.ContainsKey(nameof(VmodelPage.id)))
|
||||
{
|
||||
throw new Exception($"更新数据时主键({nameof(VmodelPage.id)})不可为空");
|
||||
}
|
||||
var id = input.data[nameof(VmodelPage.id)].ToString();
|
||||
var model = await _db.Queryable<VmodelPage>().FirstAsync(a => a.id == id);
|
||||
ThrowIf.IsNull(model, $"找不到id={id}的视图页面数据");
|
||||
input.data.Adapt(model, TypeAdapter.IgnoreNull);
|
||||
await _db.Updateable(model).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除 数据
|
||||
/// </summary>
|
||||
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||
{
|
||||
var ret = await _db.Deleteable<VmodelPage>(input.id).ExecuteCommandAsync();
|
||||
return ret;
|
||||
}
|
||||
///// <summary>
|
||||
///// 更新 数据
|
||||
///// </summary>
|
||||
//public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||
//{
|
||||
// ThrowIf.IsNull(input.data);
|
||||
// if (!input.data.ContainsKey(nameof(VmodelPage.id)))
|
||||
// {
|
||||
// throw new Exception($"更新数据时主键({nameof(VmodelPage.id)})不可为空");
|
||||
// }
|
||||
// var id = input.data[nameof(VmodelPage.id)].ToString();
|
||||
// var model = await _db.Queryable<VmodelPage>().FirstAsync(a => a.id == id);
|
||||
// ThrowIf.IsNull(model, $"找不到id={id}的视图页面数据");
|
||||
// input.data.Adapt(model, TypeAdapter.IgnoreNull);
|
||||
// await _db.Updateable(model).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||
// return model;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据表创建模型
|
||||
/// </summary>
|
||||
public async Task<VmodelPage> CreateByVmodel(CreatePageFromVmodelInput input)
|
||||
public async Task<VmodelPage> CreateByVmodel(VmodelPageCreateFromVmodelInput input)
|
||||
{
|
||||
ThrowIf.IsNull(input.vmid);
|
||||
var vm = await _dataAccess.GetVmodelAsync(input.vmid);
|
||||
|
||||
Reference in New Issue
Block a user