修复排序错误
This commit is contained in:
@@ -4,17 +4,17 @@
|
|||||||
/// 字典对象
|
/// 字典对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class VmodelSettingAttribute : Attribute
|
public class VmodelAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string? Id { get; set; }
|
public string? Id { get; set; }
|
||||||
public string? Area { get; set; }
|
public string? Area { get; set; }
|
||||||
public string? Code { get; set; }
|
public string? Code { get; set; }
|
||||||
|
|
||||||
public VmodelSettingAttribute(string id)
|
public VmodelAttribute(string id)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
}
|
}
|
||||||
public VmodelSettingAttribute(string area, string? code = null)
|
public VmodelAttribute(string area, string? code)
|
||||||
{
|
{
|
||||||
Area = area;
|
Area = area;
|
||||||
Code = code;
|
Code = code;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb;
|
||||||
|
|
||||||
namespace JNPF.Common.Contracts;
|
namespace JNPF.Common.Contracts;
|
||||||
|
|
||||||
public class BaseEntity<TKey> : IEntity where TKey : IEquatable<TKey>
|
public class BaseEntity<TKey> : Entity, IEntity where TKey : IEquatable<TKey>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取或设置 编号.
|
/// 获取或设置 编号.
|
||||||
@@ -10,6 +11,8 @@ public class BaseEntity<TKey> : IEntity where TKey : IEquatable<TKey>
|
|||||||
[SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true)]
|
[SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true)]
|
||||||
public TKey id { get; set; }
|
public TKey id { get; set; }
|
||||||
|
|
||||||
|
public override object[] GetKeys()
|
||||||
|
{
|
||||||
|
return [id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
using JNPF.Common.Contracts;
|
using JNPF.Common.Contracts;
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
namespace Tnb;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class Entity : IEntity
|
public abstract class Entity : IEntity
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace Tnb.Core;
|
using Mapster;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Tnb.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 字典对象
|
/// 字典对象
|
||||||
@@ -13,33 +16,35 @@ public class DObject : Dictionary<string, object>
|
|||||||
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
|
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public void AddCascade(string code, object value)
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将平面结构转换为树形嵌套结构
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="codePath">以.号分隔的多级路径</param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public void AddToCascade(string codePath, object value)
|
||||||
{
|
{
|
||||||
var keys = code.Split('.');
|
var keys = codePath.Split('.');
|
||||||
if (keys.Length == 1)
|
if (keys.Length == 1)
|
||||||
{
|
{
|
||||||
Add(code, value);
|
Add(codePath, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DObject temp = this;
|
||||||
for (int i = 0; i < keys.Length; i++)
|
for (int i = 0; i < keys.Length; i++)
|
||||||
{
|
{
|
||||||
DObject temp = this;
|
var key = keys[i];
|
||||||
if (i < keys.Length - 1)
|
if (i < keys.Length - 1)
|
||||||
{
|
{
|
||||||
if (!ContainsKey(keys[i]))
|
var obj = new DObject();
|
||||||
{
|
temp[key] = obj;
|
||||||
temp = new DObject();
|
temp = obj;
|
||||||
Add(keys[i], temp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = (DObject)temp[keys[i]];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp.Add(keys[i], value);
|
temp[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
{
|
{
|
||||||
private readonly IDataAccess _dataAccess;
|
private readonly IDataAccess _dataAccess;
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
|
private readonly Dictionary<string, Vmodel> _models = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
@@ -34,6 +35,19 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
_db = _dataAccess.GetSqlSugar();
|
_db = _dataAccess.GetSqlSugar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Vmodel
|
||||||
|
/// </summary>
|
||||||
|
private async Task<Vmodel> GetVmodelAsync(string id)
|
||||||
|
{
|
||||||
|
if (_models.ContainsKey(id))
|
||||||
|
{
|
||||||
|
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||||
|
}
|
||||||
|
return _models[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region 按模型的id进行增删改查接口
|
#region 按模型的id进行增删改查接口
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -42,14 +56,9 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpGet("api/[area]/[controller]/{vmid}/get")]
|
[HttpGet("api/[area]/[controller]/{vmid}/get")]
|
||||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
var vm = await GetVmodelAsync(vmid);
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||||
if (input.id != null)
|
var ls = await ListAsync(vmid, arg);
|
||||||
{
|
|
||||||
if (arg.q == null) arg.q = new DObject();
|
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault();
|
return ls.items.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +68,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpGet("api/[area]/[controller]/{vmid}/get-list")]
|
[HttpGet("api/[area]/[controller]/{vmid}/get-list")]
|
||||||
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
return await ListAsync(vmid, input.ToQueryInput());
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (!string.IsNullOrEmpty(input.q))
|
|
||||||
{
|
|
||||||
arg.q = input.q.ToObject<DObject>();
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,7 +77,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpPost("api/[area]/[controller]/{vmid}/list")]
|
[HttpPost("api/[area]/[controller]/{vmid}/list")]
|
||||||
public async Task<VmPagedOutput> ListAsync(string vmid, [FromBody] VmQueryInput input)
|
public async Task<VmPagedOutput> ListAsync(string vmid, [FromBody] VmQueryInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
var vm = await GetVmodelAsync(vmid);
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
@@ -86,7 +88,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpPost("api/[area]/[controller]/{vmid}/create")]
|
[HttpPost("api/[area]/[controller]/{vmid}/create")]
|
||||||
public async Task<dynamic> CreateAsync(string vmid, [FromBody] VmCreateInput input)
|
public async Task<dynamic> CreateAsync(string vmid, [FromBody] VmCreateInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
var vm = await GetVmodelAsync(vmid);
|
||||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -97,7 +99,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpPut("api/[area]/[controller]/{vmid}/update")]
|
[HttpPut("api/[area]/[controller]/{vmid}/update")]
|
||||||
public async Task<dynamic> UpdateAsync(string vmid, [FromBody] VmUpdateInput input)
|
public async Task<dynamic> UpdateAsync(string vmid, [FromBody] VmUpdateInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
var vm = await GetVmodelAsync(vmid);
|
||||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -108,7 +110,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpDelete("api/[area]/[controller]/{vmid}/delete")]
|
[HttpDelete("api/[area]/[controller]/{vmid}/delete")]
|
||||||
public async Task<dynamic> DeleteAsync(string vmid, [FromQuery] VmDeleteInput input)
|
public async Task<dynamic> DeleteAsync(string vmid, [FromQuery] VmDeleteInput input)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
var vm = await GetVmodelAsync(vmid);
|
||||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -119,8 +121,12 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
|
|
||||||
private async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
private async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
||||||
{
|
{
|
||||||
var vm = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
var key = areaCode + "/" + vmCode;
|
||||||
return vm;
|
if (_models.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_models[key] = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||||
|
}
|
||||||
|
return _models[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -130,13 +136,8 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
var arg = input.ToQueryInput(vm.GetPrimary().code);
|
||||||
if (input.id != null)
|
var ls = await ListAsync(areaCode, vmCode, arg);
|
||||||
{
|
|
||||||
if (arg.q == null) arg.q = new DObject();
|
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault();
|
return ls.items.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,14 +147,7 @@ public class VengineAppService : BaseAppService, IVengineAppService
|
|||||||
[HttpGet("api/{areaCode}/{vmCode}/get-list")]
|
[HttpGet("api/{areaCode}/{vmCode}/get-list")]
|
||||||
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
return await ListAsync(areaCode, vmCode, input.ToQueryInput());
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (!string.IsNullOrEmpty(input.q))
|
|
||||||
{
|
|
||||||
arg.q = input.q.ToObject<DObject>();
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Aop.Api.Domain;
|
||||||
|
using JNPF.Common.Contracts;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -20,10 +23,17 @@ namespace Tnb.Vengine.AppService;
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||||
[Route("api/[area]/[controller]/[action]")]
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, TCreateInput, TUpdateInput> : BaseAppService
|
||||||
|
where TEntity : Entity
|
||||||
|
where TGetInput : VmGetInput
|
||||||
|
where TQueryInput : VmQueryInput
|
||||||
|
where TGetListInput : VmGetListInput
|
||||||
|
where TCreateInput : VmCreateInput
|
||||||
|
where TUpdateInput : VmUpdateInput
|
||||||
{
|
{
|
||||||
protected readonly IDataAccess _dataAccess;
|
protected readonly IDataAccess _dataAccess;
|
||||||
protected readonly ISqlSugarClient _db;
|
protected readonly ISqlSugarClient _db;
|
||||||
|
private readonly Dictionary<string, Vmodel> _models = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
@@ -37,71 +47,86 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
|||||||
protected virtual async Task<Vmodel> GetVmodelAsync()
|
protected virtual async Task<Vmodel> GetVmodelAsync()
|
||||||
{
|
{
|
||||||
var tp = typeof(TEntity);
|
var tp = typeof(TEntity);
|
||||||
string? area = null, code = null;
|
string? id = null, area = null, code = null;
|
||||||
var vset = tp.GetCustomAttribute<VmodelSettingAttribute>();
|
var vset = tp.GetCustomAttribute<VmodelAttribute>();
|
||||||
if (vset != null)
|
if (vset != null)
|
||||||
{
|
{
|
||||||
|
id = vset.Id;
|
||||||
area = vset.Area;
|
area = vset.Area;
|
||||||
code = vset.Code;
|
code = vset.Code;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(area))
|
if (!string.IsNullOrEmpty(id))
|
||||||
{
|
{
|
||||||
ThrowIf.IsNullOrEmpty(tp.Namespace, $"类型 {nameof(tp)} 的命名空间不可为空");
|
if (_models.ContainsKey(id))
|
||||||
area = tp.Namespace.RemovePreFix(ModuleConst.NsPrefix + ".").Replace(".Domain", "").Replace(".Entities", "").ToKebab();
|
{
|
||||||
|
_models[id] = await _dataAccess.GetVmodelAsync(id, false);
|
||||||
|
//_models[_models[id].fullCode] = _models[id];
|
||||||
|
}
|
||||||
|
return _models[id];
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(code))
|
else
|
||||||
{
|
{
|
||||||
code = tp.Name.ToKebab();
|
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];
|
||||||
}
|
}
|
||||||
var vm = await _dataAccess.GetVmodelAsync(area, code, false);
|
|
||||||
|
|
||||||
return vm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取一条 数据信息
|
/// 获取一条 数据信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public virtual async Task<dynamic> GetAsync([FromQuery] VmGetInput input)
|
public virtual async Task<TGetOutput> GetAsync([FromQuery] TGetInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync();
|
var vm = await GetVmodelAsync();
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
TQueryInput arg = input.Adapt<TQueryInput>();
|
||||||
if (input.id != null)
|
if (input.id != null)
|
||||||
{
|
{
|
||||||
if (arg.q == null) arg.q = new DObject();
|
if (arg.q == null) arg.q = new DObject();
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||||
}
|
}
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault()!;
|
var data = (await ListAsync(arg)).items.FirstOrDefault();
|
||||||
|
return data == null ? default! : data.Adapt<TGetOutput>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取多条 数据列表
|
/// 获取多条 数据列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public virtual async Task<VmPagedOutput> GetListAsync([FromQuery] VmGetListInput input)
|
public virtual async Task<PagedOutput<TGetListOutput>> GetListAsync([FromQuery] TGetListInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync();
|
return await ListAsync(input.Adapt<TQueryInput>());
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input.ToListInput());
|
|
||||||
return ls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取多条 数据列表
|
/// 获取多条 数据列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual async Task<VmPagedOutput> ListAsync([FromBody] VmQueryInput input)
|
public virtual async Task<PagedOutput<TGetListOutput>> ListAsync([FromBody] TQueryInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync();
|
var vm = await GetVmodelAsync();
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||||
return ls;
|
return ls.ToPagedOutput<TGetListOutput>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新增 数据
|
/// 新增 数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual async Task<dynamic> CreateAsync([FromBody] VmCreateInput input)
|
public virtual async Task<dynamic> CreateAsync([FromBody] TCreateInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync();
|
var vm = await GetVmodelAsync();
|
||||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||||
@@ -112,7 +137,7 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
|||||||
/// 更新 数据
|
/// 更新 数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public virtual async Task<dynamic> UpdateAsync([FromBody] VmUpdateInput input)
|
public virtual async Task<dynamic> UpdateAsync([FromBody] TUpdateInput input)
|
||||||
{
|
{
|
||||||
var vm = await GetVmodelAsync();
|
var vm = await GetVmodelAsync();
|
||||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||||
@@ -130,3 +155,46 @@ public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 泛型变种
|
||||||
|
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput> :
|
||||||
|
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, TGetListOutput, VmCreateInput, VmUpdateInput>
|
||||||
|
where TEntity : Entity
|
||||||
|
where TGetInput : VmGetInput
|
||||||
|
where TGetListInput : VmGetListInput
|
||||||
|
where TQueryInput : VmQueryInput
|
||||||
|
{
|
||||||
|
public VengineAppService(IDataAccess da) : base(da)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput> :
|
||||||
|
VengineAppService<TEntity, TGetInput, TGetOutput, TQueryInput, TGetListInput, DObject, VmCreateInput, VmUpdateInput>
|
||||||
|
where TEntity : Entity
|
||||||
|
where TGetInput : VmGetInput
|
||||||
|
where TGetListInput : VmGetListInput
|
||||||
|
where TQueryInput : VmQueryInput
|
||||||
|
{
|
||||||
|
public VengineAppService(IDataAccess da) : base(da)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class VengineAppService<TEntity, TGetInput, TGetOutput> :
|
||||||
|
VengineAppService<TEntity, TGetInput, TGetOutput, VmQueryInput, VmGetListInput, DObject, VmCreateInput, VmUpdateInput>
|
||||||
|
where TEntity : Entity
|
||||||
|
where TGetInput : VmGetInput
|
||||||
|
{
|
||||||
|
public VengineAppService(IDataAccess da) : base(da)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class VengineAppService<TEntity> :
|
||||||
|
VengineAppService<TEntity, VmGetInput, dynamic, VmQueryInput, VmGetListInput, dynamic, VmCreateInput, VmUpdateInput>
|
||||||
|
where TEntity : Entity
|
||||||
|
{
|
||||||
|
public VengineAppService(IDataAccess da) : base(da)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using JNPF;
|
using JNPF;
|
||||||
|
using JNPF.Common.Manager;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using JNPF.ViewEngine;
|
using JNPF.ViewEngine;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
@@ -23,13 +24,15 @@ namespace Tnb.Vengine.AppService;
|
|||||||
public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||||
{
|
{
|
||||||
private readonly IViewEngine _viewEngine;
|
private readonly IViewEngine _viewEngine;
|
||||||
|
private readonly ICacheManager _cache;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public VmodelAppService(IDataAccess da, IViewEngine viewEngine) : base(da)
|
public VmodelAppService(IDataAccess da, IViewEngine viewEngine, ICacheManager cache) : base(da)
|
||||||
{
|
{
|
||||||
_viewEngine = viewEngine;
|
_viewEngine = viewEngine;
|
||||||
|
_cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,21 +62,19 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取多条 数据列表
|
/// 获取多条 数据列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
public override async Task<PagedOutput<dynamic>> GetListAsync(VmGetListInput input)
|
||||||
|
{
|
||||||
|
return await ListAsync(input.ToQueryInput());
|
||||||
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public override async Task<PagedOutput<dynamic>> ListAsync(VmQueryInput input)
|
||||||
{
|
{
|
||||||
VmPagedOutput ret = new();
|
VmPagedOutput ret = new();
|
||||||
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>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.vmCode.Contains(input.k!) || a.vmName.Contains(input.k!));
|
||||||
RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||||
ret.total = total;
|
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||||
ret.items = data.Adapt<List<DObject>>();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
[NonAction]
|
|
||||||
public override Task<VmPagedOutput> ListAsync(VmQueryInput input)
|
|
||||||
{
|
|
||||||
return base.ListAsync(input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -102,6 +103,7 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
|||||||
vm.vmCode = vm.vmCode.ToKebab();
|
vm.vmCode = vm.vmCode.ToKebab();
|
||||||
vm.navProps.ForEach(a => a.naviModel = null);
|
vm.navProps.ForEach(a => a.naviModel = null);
|
||||||
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||||
|
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(vm.id));
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +113,7 @@ public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
|||||||
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
public override async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||||
{
|
{
|
||||||
var ret = await _db.Deleteable<Vmodel>(input.id).ExecuteCommandAsync();
|
var ret = await _db.Deleteable<Vmodel>(input.id).ExecuteCommandAsync();
|
||||||
|
await _cache.DelAsync(_dataAccess.GetVmodelCacheKey(input.id!));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,15 +42,13 @@ public class VmodelPageAppService : VengineAppService<VmodelPage>, IVmodelPageAp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取多条 数据列表
|
/// 获取多条 数据列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
public override async Task<PagedOutput<dynamic>> ListAsync(VmQueryInput input)
|
||||||
{
|
{
|
||||||
VmPagedOutput ret = new();
|
VmPagedOutput ret = new();
|
||||||
var q = _db.Queryable<VmodelPage>().WhereIF(!string.IsNullOrEmpty(input.k), a => a.code.Contains(input.k!) || a.name.Contains(input.k!));
|
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;
|
RefAsync<int> total = 0;
|
||||||
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
var data = await q.OrderBy(input.sort).ToPageListAsync((input.pnum - 1) * input.psize, input.psize, total);
|
||||||
ret.total = total;
|
return PagedOutput.Create(total, data.Adapt<List<dynamic>>());
|
||||||
ret.items = data.Adapt<List<DObject>>();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -101,6 +101,14 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 Vmodel 的缓存键
|
||||||
|
/// </summary>
|
||||||
|
public string GetVmodelCacheKey(string id)
|
||||||
|
{
|
||||||
|
return $"tnb.vmodel:{id}";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 Vmodel, 为空时不抛异常
|
/// 获取 Vmodel, 为空时不抛异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -119,7 +127,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false)
|
public async Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false)
|
||||||
{
|
{
|
||||||
var key = $"tnb.vmodel:{id}";
|
var key = GetVmodelCacheKey(id);
|
||||||
var vm = await _cache.GetAsync<Vmodel>(key);
|
var vm = await _cache.GetAsync<Vmodel>(key);
|
||||||
if (vm == null)
|
if (vm == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ public interface IDataAccess : ITransient
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Task<Vmodel?> TryGetVmodelAsync(string id, bool loadNavigate = false);
|
Task<Vmodel?> TryGetVmodelAsync(string id, bool loadNavigate = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 Vmodel 的缓存键
|
||||||
|
/// </summary>
|
||||||
|
string GetVmodelCacheKey(string id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 Vmodel, 为空时抛异常
|
/// 获取 Vmodel, 为空时抛异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ namespace Tnb.Vengine.Domain;
|
|||||||
|
|
||||||
public class VmBaseInput
|
public class VmBaseInput
|
||||||
{
|
{
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// 视图模型id
|
/// 附加参数
|
||||||
///// </summary>
|
/// </summary>
|
||||||
//public string vmid { get; set; } = string.Empty;
|
public object? extra { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VmGetInput : VmBaseInput
|
public class VmGetInput : VmBaseInput
|
||||||
@@ -33,6 +33,23 @@ public class VmGetInput : VmBaseInput
|
|||||||
/// 输出字段
|
/// 输出字段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string o { get; set; } = "*";
|
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
|
public class VmGetListInput : VmBaseInput
|
||||||
@@ -67,7 +84,11 @@ public class VmGetListInput : VmBaseInput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string o { get; set; } = "*";
|
public string o { get; set; } = "*";
|
||||||
|
|
||||||
public VmQueryInput ToListInput()
|
/// <summary>
|
||||||
|
/// 转换为QueryInput
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public VmQueryInput ToQueryInput()
|
||||||
{
|
{
|
||||||
VmQueryInput arg = this.Adapt<VmQueryInput>();
|
VmQueryInput arg = this.Adapt<VmQueryInput>();
|
||||||
|
|
||||||
@@ -89,11 +110,6 @@ public class VmQueryInput : VmGetListInput
|
|||||||
/// 查询条件
|
/// 查询条件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new DObject? q { get; set; }
|
public new DObject? q { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 高级查询
|
|
||||||
/// </summary>
|
|
||||||
public DObject? adv { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -139,14 +155,32 @@ public class VmDeleteInput : VmBaseInput
|
|||||||
public List<string>? ids { get; set; }
|
public List<string>? ids { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PagedOutput
|
||||||
|
{
|
||||||
|
public int total { get; set; }
|
||||||
|
public object? extra { get; set; }
|
||||||
|
public static PagedOutput<T> Create<T>(int totalNum, List<T> ls)
|
||||||
|
{
|
||||||
|
return new PagedOutput<T>(totalNum, ls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分页列表输出对象
|
/// 分页列表输出对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class PagedOutput<T>
|
public class PagedOutput<T> : PagedOutput
|
||||||
{
|
{
|
||||||
public int total { get; set; }
|
|
||||||
public List<T> items { get; set; } = new List<T>();
|
public List<T> items { get; set; } = new List<T>();
|
||||||
|
|
||||||
|
public PagedOutput()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public PagedOutput(int totalNum, List<T> ls)
|
||||||
|
{
|
||||||
|
total = totalNum;
|
||||||
|
items = ls;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -154,18 +188,12 @@ public class PagedOutput<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class VmPagedOutput : PagedOutput<DObject>
|
public class VmPagedOutput : PagedOutput<DObject>
|
||||||
{
|
{
|
||||||
|
public PagedOutput<T> ToPagedOutput<T>()
|
||||||
|
{
|
||||||
|
return new PagedOutput<T>()
|
||||||
|
{
|
||||||
|
total = total,
|
||||||
|
items = items.Adapt<List<T>>()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// 查询属性信息
|
|
||||||
///// </summary>
|
|
||||||
//public class VmSelectProp
|
|
||||||
//{
|
|
||||||
// public const string MAIN_ALIES = "m";
|
|
||||||
// public string code { get; set; } = string.Empty;
|
|
||||||
// public string field { get; set; } = string.Empty;
|
|
||||||
// public List<string> navPath { get; set; } = new List<string>();
|
|
||||||
// public string navCode { get; set; } = MAIN_ALIES;
|
|
||||||
// public ePropType propType { get; set; }
|
|
||||||
// public eNavigateType navType { get; set; }
|
|
||||||
//}
|
|
||||||
@@ -56,9 +56,9 @@ internal class VmQueryParser
|
|||||||
{
|
{
|
||||||
// t1.t2.id
|
// t1.t2.id
|
||||||
List<string> outputs = output.Split(',').Distinct().ToList();
|
List<string> outputs = output.Split(',').Distinct().ToList();
|
||||||
foreach (string? outStr in outputs)
|
foreach (string? s in outputs)
|
||||||
{
|
{
|
||||||
_ = ClearStr(outStr);
|
var outStr = ClearStr(s);
|
||||||
if (string.IsNullOrWhiteSpace(outStr))
|
if (string.IsNullOrWhiteSpace(outStr))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -126,15 +126,15 @@ internal class VmQueryParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
string[] orders = sort.Split(',');
|
string[] orders = sort.Split(',');
|
||||||
foreach (string orderStr in orders)
|
foreach (string s in orders)
|
||||||
{
|
{
|
||||||
_ = ClearStr(orderStr);
|
var orderStr = ClearStr(s);
|
||||||
if (string.IsNullOrWhiteSpace(orderStr))
|
if (string.IsNullOrWhiteSpace(orderStr))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 拆分 m.code desc
|
// 拆分 m.code desc
|
||||||
string[] codes = orderStr.Split(' ', 1);
|
string[] codes = orderStr.Split(' ', 2);
|
||||||
// 拆分 m.code
|
// 拆分 m.code
|
||||||
(string?, string) orderPath = codes[0].GetParent(NAVI_SEPERATE);
|
(string?, string) orderPath = codes[0].GetParent(NAVI_SEPERATE);
|
||||||
orderPath.Item1 ??= MAIN_ALIES;
|
orderPath.Item1 ??= MAIN_ALIES;
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ using System.ComponentModel;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using JNPF.Common.Contracts;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.Core;
|
using Tnb.Core;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
@@ -65,19 +65,19 @@ public partial class Vmodel : Entity
|
|||||||
/// 表字段属性
|
/// 表字段属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "db_props", IsNullable = false, IsJson = true)]
|
[SugarColumn(ColumnName = "db_props", IsNullable = false, IsJson = true)]
|
||||||
public List<VmDbProp> dbProps { get; set; } = new List<VmDbProp>();
|
public List<VmDbProp> dbProps { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 导航属性
|
/// 导航属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "nav_props", IsNullable = true, IsJson = true)]
|
[SugarColumn(ColumnName = "nav_props", IsNullable = true, IsJson = true)]
|
||||||
public List<VmNavProp> navProps { get; set; } = new List<VmNavProp>();
|
public List<VmNavProp> navProps { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 计算属性
|
/// 计算属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "cal_props", IsNullable = true, IsJson = true)]
|
[SugarColumn(ColumnName = "cal_props", IsNullable = true, IsJson = true)]
|
||||||
public List<VmCalProp> calProps { get; set; } = new List<VmCalProp>();
|
public List<VmCalProp> calProps { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 排序
|
/// 排序
|
||||||
@@ -134,8 +134,7 @@ public partial class Vmodel : Entity
|
|||||||
public string? modifyId { get; set; }
|
public string? modifyId { get; set; }
|
||||||
|
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
public string fullCode
|
public string fullCode => areaCode + "/" + vmCode;
|
||||||
{ get { return areaCode + "/" + vmCode; } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主键
|
/// 主键
|
||||||
@@ -157,7 +156,7 @@ public partial class Vmodel : Entity
|
|||||||
public static Vmodel CreateByEntity(Type tpEntity, string? dbCode = null)
|
public static Vmodel CreateByEntity(Type tpEntity, string? dbCode = null)
|
||||||
{
|
{
|
||||||
Vmodel model = new() { dbCode = dbCode, vmCode = tpEntity.Name };
|
Vmodel model = new() { dbCode = dbCode, vmCode = tpEntity.Name };
|
||||||
var sugarTableAttr = tpEntity.GetCustomAttribute<SugarTable>();
|
SugarTable? sugarTableAttr = tpEntity.GetCustomAttribute<SugarTable>();
|
||||||
if (sugarTableAttr != null)
|
if (sugarTableAttr != null)
|
||||||
{
|
{
|
||||||
model.tableName = sugarTableAttr.TableName;
|
model.tableName = sugarTableAttr.TableName;
|
||||||
@@ -171,12 +170,12 @@ public partial class Vmodel : Entity
|
|||||||
{
|
{
|
||||||
model.vmName = tpEntity.GetCustomAttribute<DisplayAttribute>()?.Name ?? tpEntity.GetCustomAttribute<DescriptionAttribute>()?.Description ?? model.vmCode;
|
model.vmName = tpEntity.GetCustomAttribute<DisplayAttribute>()?.Name ?? tpEntity.GetCustomAttribute<DescriptionAttribute>()?.Description ?? model.vmCode;
|
||||||
}
|
}
|
||||||
var props = tpEntity.GetProperties(BindingFlags.Public);
|
PropertyInfo[] props = tpEntity.GetProperties(BindingFlags.Public);
|
||||||
int n = 1;
|
int n = 1;
|
||||||
foreach (var p in props)
|
foreach (PropertyInfo p in props)
|
||||||
{
|
{
|
||||||
VmDbProp prop = new();
|
VmDbProp prop = new();
|
||||||
var sugarColumn = p.GetCustomAttribute<SugarColumn>();
|
SugarColumn? sugarColumn = p.GetCustomAttribute<SugarColumn>();
|
||||||
if (sugarColumn != null)
|
if (sugarColumn != null)
|
||||||
{
|
{
|
||||||
prop = sugarColumn.Adapt<VmDbProp>();
|
prop = sugarColumn.Adapt<VmDbProp>();
|
||||||
@@ -204,10 +203,7 @@ public partial class Vmodel : Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string? PropToFieldCode(string propCode)
|
public string? PropToFieldCode(string propCode)
|
||||||
{
|
{
|
||||||
if(_mapProps == null)
|
_mapProps ??= dbProps.ToDictionary(a => a.code);
|
||||||
{
|
|
||||||
_mapProps = dbProps.ToDictionary(a=>a.code);
|
|
||||||
}
|
|
||||||
return _mapProps.GetOrDefault(propCode)?.field;
|
return _mapProps.GetOrDefault(propCode)?.field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,10 +215,7 @@ public partial class Vmodel : Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public VmDbProp? GetDbProp(string propCode)
|
public VmDbProp? GetDbProp(string propCode)
|
||||||
{
|
{
|
||||||
if (_mapProps == null)
|
_mapProps ??= dbProps.ToDictionary(a => a.code);
|
||||||
{
|
|
||||||
_mapProps = dbProps.ToDictionary(a => a.code);
|
|
||||||
}
|
|
||||||
return _mapProps.GetOrDefault(propCode);
|
return _mapProps.GetOrDefault(propCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,8 +225,8 @@ public partial class Vmodel : Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public DObject GetDefaultDObject()
|
public DObject GetDefaultDObject()
|
||||||
{
|
{
|
||||||
DObject obj = new();
|
DObject obj = [];
|
||||||
foreach (var p in dbProps)
|
foreach (VmDbProp p in dbProps)
|
||||||
{
|
{
|
||||||
obj.Add(p.code, p.GetDefaultValue()!);
|
obj.Add(p.code, p.GetDefaultValue()!);
|
||||||
}
|
}
|
||||||
@@ -246,8 +239,8 @@ public partial class Vmodel : Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public DObject ToCreateEntity(DObject input, IUserManager user)
|
public DObject ToCreateEntity(DObject input, IUserManager user)
|
||||||
{
|
{
|
||||||
DObject obj = new();
|
DObject obj = [];
|
||||||
foreach (var p in dbProps)
|
foreach (VmDbProp p in dbProps)
|
||||||
{
|
{
|
||||||
if (input.ContainsKey(p.code))
|
if (input.ContainsKey(p.code))
|
||||||
{
|
{
|
||||||
@@ -280,8 +273,8 @@ public partial class Vmodel : Entity
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public DObject ToUpdateEntity(DObject input, IUserManager user)
|
public DObject ToUpdateEntity(DObject input, IUserManager user)
|
||||||
{
|
{
|
||||||
DObject obj = new();
|
DObject obj = [];
|
||||||
foreach (var p in dbProps)
|
foreach (VmDbProp p in dbProps)
|
||||||
{
|
{
|
||||||
if (input.ContainsKey(p.code))
|
if (input.ContainsKey(p.code))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Contracts;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Contracts;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|||||||
Reference in New Issue
Block a user