修改泛型通用接口
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);
|
||||
|
||||
@@ -137,7 +137,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
{
|
||||
await LoadVmodelNavigateAsync(vm);
|
||||
}
|
||||
await _cache.SetAsync(id, vm, TimeSpan.FromMinutes(10));
|
||||
await _cache.SetAsync(key, vm, TimeSpan.FromMinutes(10));
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
@@ -211,7 +211,6 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
ISugarQueryable<object> query = db.Queryable<object>().AS(vm.tableName, VmQueryParser.MAIN_ALIES);
|
||||
VmQueryParser parser = new(this, vm, input);
|
||||
parser.ParseQueryInput();
|
||||
await parser.LoadNavigateAsync();
|
||||
// 处理导航属性联表
|
||||
List<JoinInfoParameter> joins = parser.GetJoinInfos();
|
||||
@@ -320,7 +319,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
/// <summary>
|
||||
/// 新增数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input)
|
||||
public async Task<dynamic> CreateDataAsync(Vmodel vm, VmEditInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
ThrowIf.When(input.data == null && input.items == null, "新增数据时,data和items不可同时为空");
|
||||
@@ -386,7 +385,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
/// <summary>
|
||||
/// 更新数据 默认方法
|
||||
/// </summary>
|
||||
public async Task<dynamic> UpdateDataAsync(Vmodel vm, VmUpdateInput input)
|
||||
public async Task<dynamic> UpdateDataAsync(Vmodel vm, VmEditInput input)
|
||||
{
|
||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||
VmDbProp pk = vm.GetPrimary();
|
||||
|
||||
@@ -59,13 +59,13 @@ public interface IDataAccess : ITransient
|
||||
/// <summary>
|
||||
/// 新增数据 默认方法
|
||||
/// </summary>
|
||||
Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input);
|
||||
Task<dynamic> CreateDataAsync(Vmodel vm, VmEditInput input);
|
||||
|
||||
//Task<dynamic> UpdateDataAsync(VmUpdateInput input);
|
||||
/// <summary>
|
||||
/// 更新数据 默认方法
|
||||
/// </summary>
|
||||
Task<dynamic> UpdateDataAsync(Vmodel vm, VmUpdateInput input);
|
||||
Task<dynamic> UpdateDataAsync(Vmodel vm, VmEditInput input);
|
||||
|
||||
//Task<int> DeleteDataAsync(VmDeleteInput input);
|
||||
/// <summary>
|
||||
|
||||
@@ -83,22 +83,6 @@ public class VmGetListInput : VmBaseInput
|
||||
/// 输出字段
|
||||
/// </summary>
|
||||
public string o { get; set; } = "*";
|
||||
|
||||
/// <summary>
|
||||
/// 转换为QueryInput
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmQueryInput ToQueryInput()
|
||||
{
|
||||
VmQueryInput arg = this.Adapt<VmQueryInput>();
|
||||
|
||||
if (!string.IsNullOrEmpty(q))
|
||||
{
|
||||
arg.q = q.ToObject<DObject>();
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,7 +99,7 @@ public class VmQueryInput : VmGetListInput
|
||||
/// <summary>
|
||||
/// 新增数据输入参数
|
||||
/// </summary>
|
||||
public class VmCreateInput : VmBaseInput
|
||||
public class VmEditInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据
|
||||
@@ -128,17 +112,6 @@ public class VmCreateInput : VmBaseInput
|
||||
public List<DObject>? items { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改数据输入参数
|
||||
/// </summary>
|
||||
public class VmUpdateInput : VmCreateInput
|
||||
{
|
||||
///// <summary>
|
||||
///// 要更新的数据id
|
||||
///// </summary>
|
||||
//public string? id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除数据输入参数
|
||||
/// </summary>
|
||||
|
||||
@@ -24,11 +24,12 @@ internal class VmQueryParser
|
||||
_dataAccess = dataAccess;
|
||||
_root = rootModel;
|
||||
_input = input;
|
||||
ParseQueryInput();
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析查询参数
|
||||
/// </summary>
|
||||
public void ParseQueryInput()
|
||||
private void ParseQueryInput()
|
||||
{
|
||||
// 初始化根模型
|
||||
Navigates.Clear();
|
||||
@@ -263,6 +264,92 @@ internal class VmQueryParser
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public List<IConditionalModel> GetConditionalModels()
|
||||
{
|
||||
List<IConditionalModel> wheres = new();
|
||||
// 处理软删除
|
||||
var softDeletedProp = _root.GetSoftDeleted();
|
||||
if (softDeletedProp != null && !Navigates[MAIN_ALIES].wheres.Any(a => a.code == softDeletedProp.code))
|
||||
{
|
||||
wheres.Add(new ConditionalModel { FieldName = MAIN_ALIES + "." + softDeletedProp.field, FieldValue = "0", ConditionalType = ConditionalType.Equal, CSharpTypeName = softDeletedProp.csType });
|
||||
}
|
||||
|
||||
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))
|
||||
{
|
||||
foreach (VmWhereProp where in nav.wheres)
|
||||
{
|
||||
// 当条件为集合数据时
|
||||
if (where.value is IEnumerable<object> arrObj)
|
||||
{
|
||||
object[] val = arrObj.ToArray();
|
||||
string op = val[0].ToString()!;
|
||||
switch (op)
|
||||
{
|
||||
case "><":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case ">=<":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case "><=":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case ">=<=":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case "in":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = string.Join(',', val.Skip(1)), ConditionalType = ConditionalType.In, CSharpTypeName = where.csType });
|
||||
break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConditionalType conditionalType = ConditionalType.Equal;
|
||||
string? value = where.value?.ToString();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.Length >= 2)
|
||||
{
|
||||
string op = value[..2];
|
||||
switch (op)
|
||||
{
|
||||
case "%%": conditionalType = ConditionalType.Like; break;
|
||||
case ">>": conditionalType = ConditionalType.GreaterThan; break;
|
||||
case "<<": conditionalType = ConditionalType.LessThan; break;
|
||||
case ">=": conditionalType = ConditionalType.GreaterThanOrEqual; break;
|
||||
case "<=": conditionalType = ConditionalType.LessThanOrEqual; break;
|
||||
case "==": conditionalType = ConditionalType.Equal; break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(op))
|
||||
{
|
||||
value = value.RemovePreFix(op);
|
||||
if (value.ToLower() == "null")
|
||||
{
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = value, ConditionalType = conditionalType, CSharpTypeName = where.csType });
|
||||
}
|
||||
}
|
||||
}
|
||||
return wheres;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成查询过滤条件
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public List<IConditionalModel> FilterSofeDeleted()
|
||||
{
|
||||
List<IConditionalModel> wheres = new();
|
||||
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Tnb.Vengine.Domain;
|
||||
[SugarTable("sys_vmodel")]
|
||||
public partial class Vmodel : Entity
|
||||
{
|
||||
public string[] SOFT_DELETED = new string[] { "deleted", "isDeleted", "softDeleted" };
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -188,12 +190,23 @@ public partial class Vmodel : Entity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型的主键字段属性
|
||||
/// 获取模型的主键属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmDbProp GetPrimary()
|
||||
{
|
||||
return dbProps.First(a => a.pkey);
|
||||
var key = dbProps.FirstOrDefault(a => a.pkey);
|
||||
ThrowIf.IsNull(key, $"模型({fullCode})没有定义主键属性");
|
||||
return key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型的软删除属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmDbProp? GetSoftDeleted()
|
||||
{
|
||||
return dbProps.FirstOrDefault(a => SOFT_DELETED.Contains(a.code));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user