修改泛型通用接口
This commit is contained in:
@@ -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