初步完成代码级重写通用接口功能
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using Tnb.Vengine.DataAccess;
|
||||
using Tnb.Vengine.Domain;
|
||||
|
||||
namespace Tnb.Vengine.AppService;
|
||||
|
||||
@@ -13,6 +15,37 @@ namespace Tnb.Vengine.AppService;
|
||||
/// </summary>
|
||||
public class BaseAppService : IDynamicApiController, ITransient
|
||||
{
|
||||
protected readonly IDataAccess _dataAccess;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
|
||||
public BaseAppService(IDataAccess dataAccess)
|
||||
{
|
||||
_dataAccess = dataAccess;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据id获取Vmodel
|
||||
/// </summary>
|
||||
protected async Task<Vmodel> GetVmodelAsync(string id)
|
||||
{
|
||||
if (!_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
}
|
||||
return _models[id];
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据areaCode和vmCode获取Vmodel
|
||||
/// </summary>
|
||||
protected async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
||||
{
|
||||
var key = areaCode + "/" + vmCode;
|
||||
if (!_models.ContainsKey(key))
|
||||
{
|
||||
_models[key] = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||
}
|
||||
return _models[key];
|
||||
}
|
||||
}
|
||||
|
||||
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 100)]
|
||||
|
||||
@@ -22,32 +22,17 @@ namespace Tnb.Vengine.AppService;
|
||||
[Route("/")]
|
||||
public class VengineAppService : BaseAppService, IVengineAppService
|
||||
{
|
||||
private readonly IDataAccess _dataAccess;
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
//private readonly ISqlSugarClient _db;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VengineAppService(IDataAccess da)
|
||||
public VengineAppService(IDataAccess da):base(da)
|
||||
{
|
||||
_dataAccess = da;
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
//_db = _dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
#region 按模型的id进行增删改查接口
|
||||
/// <summary>
|
||||
/// 获取Vmodel
|
||||
/// </summary>
|
||||
private async Task<Vmodel> GetVmodelAsync(string id)
|
||||
{
|
||||
if (!_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
}
|
||||
return _models[id];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
@@ -55,7 +40,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(vmid);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var arg = input.Adapt<VmQueryInput>();
|
||||
arg.AddQueryParaIf(!string.IsNullOrEmpty(input.id), vm.GetPrimary().code, input.id!);
|
||||
|
||||
var ls = await ListAsync(vmid, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
@@ -116,17 +103,6 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
#endregion 按模型的id进行增删改查接口
|
||||
|
||||
#region 按模型的areaCode和vmcode进行增删改查接口
|
||||
|
||||
private async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
||||
{
|
||||
var key = areaCode + "/" + vmCode;
|
||||
if (!_models.ContainsKey(key))
|
||||
{
|
||||
_models[key] = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||
}
|
||||
return _models[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条 数据信息
|
||||
/// </summary>
|
||||
@@ -134,7 +110,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||
var arg = input.Adapt<VmQueryInput>();
|
||||
arg.AddQueryParaIf(!string.IsNullOrEmpty(input.id), vm.GetPrimary().code, input.id!);
|
||||
|
||||
var ls = await ListAsync(areaCode, vmCode, arg);
|
||||
return ls.items.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Aop.Api.Domain;
|
||||
using JNPF;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Extension;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using SqlSugar;
|
||||
using Tnb.Core;
|
||||
using Tnb.Vengine.DataAccess;
|
||||
@@ -31,57 +35,55 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
where TCreateInput : VmEditInput
|
||||
where TUpdateInput : VmEditInput
|
||||
{
|
||||
protected readonly IDataAccess _dataAccess;
|
||||
protected readonly ISqlSugarClient _db;
|
||||
private readonly Dictionary<string, Vmodel> _models = new();
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public VengineAppService(IDataAccess dataAccess)
|
||||
public VengineAppService(IDataAccess dataAccess) : base(dataAccess)
|
||||
{
|
||||
_dataAccess = dataAccess;
|
||||
_db = _dataAccess.GetSqlSugar();
|
||||
_db = dataAccess.GetSqlSugar();
|
||||
}
|
||||
|
||||
protected virtual async Task<Vmodel> GetVmodelAsync()
|
||||
{
|
||||
string? areaCode = null, vmCode = null;
|
||||
// 1.优先从路由中获取模型code
|
||||
IHttpContextAccessor httpContextAccessor = App.GetService<IHttpContextAccessor>();
|
||||
var routes = httpContextAccessor.HttpContext?.Request.RouteValues;
|
||||
//HttpContext.GetEndpoint()?.Metadata.GetMetadata<ControllerActionDescriptor>();
|
||||
if (routes != null)
|
||||
{
|
||||
areaCode = routes.GetOrDefault("area")?.ToString();
|
||||
vmCode = routes.GetOrDefault("controller")?.ToString();
|
||||
if (!string.IsNullOrEmpty(areaCode) && !string.IsNullOrEmpty(vmCode))
|
||||
{
|
||||
return await GetVmodelAsync(areaCode, vmCode);
|
||||
}
|
||||
}
|
||||
// 2.其次从实体特性中获取模型code
|
||||
var tp = typeof(TEntity);
|
||||
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(vset.Id))
|
||||
{
|
||||
return await GetVmodelAsync(vset.Id);
|
||||
}
|
||||
areaCode = vset.Area;
|
||||
vmCode = vset.Code;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
// 3.从实体命名空间中获取模型code
|
||||
if (string.IsNullOrEmpty(areaCode))
|
||||
{
|
||||
if (!_models.ContainsKey(id))
|
||||
{
|
||||
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||
//_models[_models[id].fullCode] = _models[id];
|
||||
}
|
||||
return _models[id];
|
||||
ThrowIf.IsNullOrEmpty(tp.Namespace, $"类型 {nameof(tp)} 的命名空间不可为空");
|
||||
areaCode = tp.Namespace.RemovePreFix(ModuleConst.NsPrefix + ".").Replace(".Domain", "").Replace(".Entities", "").ToKebab();
|
||||
}
|
||||
else
|
||||
if (string.IsNullOrEmpty(vmCode))
|
||||
{
|
||||
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];
|
||||
vmCode = tp.Name.ToKebab();
|
||||
}
|
||||
return await GetVmodelAsync(areaCode, vmCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,11 +94,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
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);
|
||||
}
|
||||
arg.AddQueryParaIf(!string.IsNullOrEmpty(input.id), vm.GetPrimary().code, input.id!);
|
||||
|
||||
var data = (await ListAsync(arg)).items.FirstOrDefault();
|
||||
return data == null ? default! : data.Adapt<TGetOutput>();
|
||||
@@ -129,7 +127,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
public virtual async Task<dynamic> CreateAsync([FromBody] TCreateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||
var ret = await _dataAccess.CreateDataAsync(vm, input.ToEditInput());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -140,7 +138,7 @@ public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGet
|
||||
public virtual async Task<dynamic> UpdateAsync([FromBody] TUpdateInput input)
|
||||
{
|
||||
var vm = await GetVmodelAsync();
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||
var ret = await _dataAccess.UpdateDataAsync(vm, input.ToEditInput());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Mapster;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using Tnb.Core;
|
||||
using Tnb.Vengine.Domain;
|
||||
|
||||
namespace Tnb.Vengine.AppService;
|
||||
|
||||
public record VmodelCreateData(string areaCode, string vmCode, string vmName, string? dbCode, string tableName, List<VmDbProp> dbProps, List<VmNavPropCreateData> navProps, List<VmCalProp> calProps, int ordinal, short softDelete, short enabled, string? descrip);
|
||||
public record VmNavPropCreateData(string code, string name, string vmid, eNavigateType navType, string refCode, string refProp, string fkProp);
|
||||
public record VmodelUpdateData(string id, string areaCode, string vmCode, string vmName, string? dbCode, string tableName, List<VmDbProp> dbProps, List<VmNavPropCreateData> navProps, List<VmCalProp> calProps, int ordinal, short softDelete, short enabled, string? descrip);
|
||||
|
||||
public class VmodelGetInput : VmGetInput
|
||||
{
|
||||
/// <summary>
|
||||
@@ -24,11 +32,17 @@ public class VmodelGetInput : VmGetInput
|
||||
}
|
||||
public class VmodelCreateInput : VmEditInput
|
||||
{
|
||||
public new Vmodel? data { get; set; }
|
||||
public new VmodelCreateData? data { get; set; }
|
||||
public override VmEditInput ToEditInput()
|
||||
{
|
||||
VmEditInput input = this;
|
||||
input.data = DObject.FromObject(data);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
public class VmodelUpdateInput : VmEditInput
|
||||
{
|
||||
public new Vmodel? data { get; set; }
|
||||
public new VmodelUpdateData? data { get; set; }
|
||||
}
|
||||
public class VmodelCreateFromTableInput
|
||||
{
|
||||
@@ -43,11 +57,23 @@ public class VmodelCreateFromTableInput
|
||||
public class VmodelPageCreateInput : VmEditInput
|
||||
{
|
||||
public new VmodelPage? data { get; set; }
|
||||
public override VmEditInput ToEditInput()
|
||||
{
|
||||
VmEditInput input = this;
|
||||
input.data = DObject.FromObject(data);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public class VmodelPageUpdateInput : VmEditInput
|
||||
{
|
||||
public new VmodelPage? data { get; set; }
|
||||
public override VmEditInput ToEditInput()
|
||||
{
|
||||
VmEditInput input = this;
|
||||
input.data = DObject.FromObject(data);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public class VmodelPageCreateFromVmodelInput
|
||||
|
||||
@@ -19,7 +19,6 @@ 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, VmGetInput, VmodelPage, VmQueryInput, VmGetListInput, VmodelPage, VmodelPageCreateInput, VmodelPageUpdateInput>, IVmodelPageAppService
|
||||
{
|
||||
/// <summary>
|
||||
@@ -29,35 +28,6 @@ public class VmodelPageAppService : VengineAppService<VmodelPage, VmGetInput, 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<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>
|
||||
|
||||
@@ -394,14 +394,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||
if (input.data != null)
|
||||
{
|
||||
DObject model = vm.ToUpdateEntity(input.data, _user);
|
||||
if (!model.ContainsKey(pk.field))
|
||||
{
|
||||
throw new Exception($"更新数据时主键({pk.code})不可为空");
|
||||
}
|
||||
//if (!model.ContainsKey(pk.field) && input.id != null)
|
||||
//{
|
||||
// model.Add(pk.field, input.id);
|
||||
//}
|
||||
ThrowIf.When(!model.ContainsKey(pk.field), $"更新数据时主键({pk.code})不可为空");
|
||||
num = await db.Updateable(model).AS(vm.tableName).WhereColumns(pk.field).ExecuteCommandAsync();
|
||||
}
|
||||
//批量修改数据
|
||||
|
||||
@@ -34,22 +34,6 @@ public class VmGetInput : VmBaseInput
|
||||
/// </summary>
|
||||
public string o { get; set; } = "*";
|
||||
|
||||
/// <summary>
|
||||
/// 转换为QueryInput
|
||||
/// </summary>
|
||||
/// <param name="primaryKey"></param>
|
||||
/// <returns></returns>
|
||||
public VmQueryInput ToQueryInput(string primaryKey)
|
||||
{
|
||||
VmQueryInput arg = this.Adapt<VmQueryInput>();
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
if (arg.q == null) arg.q = new DObject();
|
||||
arg.q.Add(primaryKey, id);
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
public class VmGetListInput : VmBaseInput
|
||||
@@ -94,6 +78,27 @@ public class VmQueryInput : VmGetListInput
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public new DObject? q { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个查询条件
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void AddQueryPara(string key, object value)
|
||||
{
|
||||
if (q == null) q = new DObject();
|
||||
q.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个查询条件
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void AddQueryParaIf(bool condition, string key, object value)
|
||||
{
|
||||
if(condition) AddQueryPara(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,6 +115,11 @@ public class VmEditInput : VmBaseInput
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
public List<DObject>? items { get; set; }
|
||||
|
||||
public virtual VmEditInput ToEditInput()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Tnb.Vengine.Domain;
|
||||
[SugarTable("sys_vmodel")]
|
||||
public partial class Vmodel : Entity
|
||||
{
|
||||
public string[] SOFT_DELETED = new string[] { "deleted", "isDeleted", "softDeleted" };
|
||||
private static string[] SOFT_DELETED = new string[] { "deleted", "isDeleted", "softDeleted" };
|
||||
|
||||
#region Properties
|
||||
|
||||
@@ -88,7 +88,7 @@ public partial class Vmodel : Entity
|
||||
public int ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 软删除
|
||||
/// 是否软删除
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "soft_delete", IsNullable = false)]
|
||||
public short softDelete { get; set; }
|
||||
@@ -103,7 +103,7 @@ public partial class Vmodel : Entity
|
||||
/// 是否删除
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "deleted", IsNullable = false)]
|
||||
public short deleted { get; set; }
|
||||
public short deleted { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Mapster;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tnb.Vengine;
|
||||
|
||||
public class TypeAdapter
|
||||
{
|
||||
public static TypeAdapterConfig IgnoreNull { get; }
|
||||
|
||||
static TypeAdapter()
|
||||
{
|
||||
TypeAdapterConfig.GlobalSettings.Default.PreserveReference(true);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JToken, JToken>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JObject, JObject>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JArray, JArray>().MapWith(json => json);
|
||||
IgnoreNull = TypeAdapterConfig.GlobalSettings.Clone();
|
||||
IgnoreNull.Default.IgnoreNullValues(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user