修复排序错误

This commit is contained in:
2023-11-16 14:55:37 +08:00
parent 5b49890a4f
commit a5f3d473e6
15 changed files with 261 additions and 154 deletions

View File

@@ -1,30 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
// 宁波拓通e智造平台 ToTong Next Builder //
// https://git.tuotong-tech.com/tnb/tnb.server //
/////////////////////////////////////////////////////////////////////////////////
using JNPF.Common.Contracts;
namespace Tnb.Vengine.Domain;
[Serializable]
public abstract class Entity : IEntity
{
protected Entity()
{
//EntityHelper.TrySetTenantId(this);
}
/// <inheritdoc/>
public override string ToString()
{
return $"[ENTITY: {GetType().Name}] Keys = {string.Join(", ", GetKeys())}";
}
public abstract object[] GetKeys();
//public bool EntityEquals(IEntity other)
//{
// return EntityHelper.EntityEquals(this, other);
//}
}

View File

@@ -11,10 +11,10 @@ namespace Tnb.Vengine.Domain;
public class VmBaseInput
{
///// <summary>
///// 视图模型id
///// </summary>
//public string vmid { get; set; } = string.Empty;
/// <summary>
/// 附加参数
/// </summary>
public object? extra { get; set; }
}
public class VmGetInput : VmBaseInput
@@ -33,6 +33,23 @@ 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
@@ -67,7 +84,11 @@ public class VmGetListInput : VmBaseInput
/// </summary>
public string o { get; set; } = "*";
public VmQueryInput ToListInput()
/// <summary>
/// 转换为QueryInput
/// </summary>
/// <returns></returns>
public VmQueryInput ToQueryInput()
{
VmQueryInput arg = this.Adapt<VmQueryInput>();
@@ -89,11 +110,6 @@ public class VmQueryInput : VmGetListInput
/// 查询条件
/// </summary>
public new DObject? q { get; set; }
/// <summary>
/// 高级查询
/// </summary>
public DObject? adv { get; set; }
}
/// <summary>
@@ -139,14 +155,32 @@ public class VmDeleteInput : VmBaseInput
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>
/// <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 PagedOutput()
{
}
public PagedOutput(int totalNum, List<T> ls)
{
total = totalNum;
items = ls;
}
}
/// <summary>
@@ -154,18 +188,12 @@ public class PagedOutput<T>
/// </summary>
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; }
//}

View File

@@ -56,9 +56,9 @@ internal class VmQueryParser
{
// t1.t2.id
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))
{
continue;
@@ -126,15 +126,15 @@ internal class VmQueryParser
}
string[] orders = sort.Split(',');
foreach (string orderStr in orders)
foreach (string s in orders)
{
_ = ClearStr(orderStr);
var orderStr = ClearStr(s);
if (string.IsNullOrWhiteSpace(orderStr))
{
continue;
}
// 拆分 m.code desc
string[] codes = orderStr.Split(' ', 1);
string[] codes = orderStr.Split(' ', 2);
// 拆分 m.code
(string?, string) orderPath = codes[0].GetParent(NAVI_SEPERATE);
orderPath.Item1 ??= MAIN_ALIES;

View File

@@ -7,10 +7,10 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
using JNPF.Common.Contracts;
using JNPF.Common.Core.Manager;
using JNPF.Common.Extension;
using Mapster;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Tnb.Core;
using Yitter.IdGenerator;
@@ -65,19 +65,19 @@ public partial class Vmodel : Entity
/// 表字段属性
/// </summary>
[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>
[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>
[SugarColumn(ColumnName = "cal_props", IsNullable = true, IsJson = true)]
public List<VmCalProp> calProps { get; set; } = new List<VmCalProp>();
public List<VmCalProp> calProps { get; set; } = [];
/// <summary>
/// 排序
@@ -134,8 +134,7 @@ public partial class Vmodel : Entity
public string? modifyId { get; set; }
[SugarColumn(IsIgnore = true)]
public string fullCode
{ get { return areaCode + "/" + vmCode; } }
public string fullCode => areaCode + "/" + vmCode;
/// <summary>
/// 主键
@@ -157,7 +156,7 @@ public partial class Vmodel : Entity
public static Vmodel CreateByEntity(Type tpEntity, string? dbCode = null)
{
Vmodel model = new() { dbCode = dbCode, vmCode = tpEntity.Name };
var sugarTableAttr = tpEntity.GetCustomAttribute<SugarTable>();
SugarTable? sugarTableAttr = tpEntity.GetCustomAttribute<SugarTable>();
if (sugarTableAttr != null)
{
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;
}
var props = tpEntity.GetProperties(BindingFlags.Public);
PropertyInfo[] props = tpEntity.GetProperties(BindingFlags.Public);
int n = 1;
foreach (var p in props)
foreach (PropertyInfo p in props)
{
VmDbProp prop = new();
var sugarColumn = p.GetCustomAttribute<SugarColumn>();
SugarColumn? sugarColumn = p.GetCustomAttribute<SugarColumn>();
if (sugarColumn != null)
{
prop = sugarColumn.Adapt<VmDbProp>();
@@ -204,10 +203,7 @@ public partial class Vmodel : Entity
/// <returns></returns>
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;
}
@@ -219,10 +215,7 @@ public partial class Vmodel : Entity
/// <returns></returns>
public VmDbProp? GetDbProp(string propCode)
{
if (_mapProps == null)
{
_mapProps = dbProps.ToDictionary(a => a.code);
}
_mapProps ??= dbProps.ToDictionary(a => a.code);
return _mapProps.GetOrDefault(propCode);
}
@@ -232,8 +225,8 @@ public partial class Vmodel : Entity
/// <returns></returns>
public DObject GetDefaultDObject()
{
DObject obj = new();
foreach (var p in dbProps)
DObject obj = [];
foreach (VmDbProp p in dbProps)
{
obj.Add(p.code, p.GetDefaultValue()!);
}
@@ -246,8 +239,8 @@ public partial class Vmodel : Entity
/// <returns></returns>
public DObject ToCreateEntity(DObject input, IUserManager user)
{
DObject obj = new();
foreach (var p in dbProps)
DObject obj = [];
foreach (VmDbProp p in dbProps)
{
if (input.ContainsKey(p.code))
{
@@ -280,8 +273,8 @@ public partial class Vmodel : Entity
/// <returns></returns>
public DObject ToUpdateEntity(DObject input, IUserManager user)
{
DObject obj = new();
foreach (var p in dbProps)
DObject obj = [];
foreach (VmDbProp p in dbProps)
{
if (input.ContainsKey(p.code))
{

View File

@@ -3,6 +3,7 @@
// https://git.tuotong-tech.com/tnb/tnb.server //
/////////////////////////////////////////////////////////////////////////////////
using JNPF.Common.Contracts;
using SqlSugar;
using Yitter.IdGenerator;

View File

@@ -3,6 +3,7 @@
// https://git.tuotong-tech.com/tnb/tnb.server //
/////////////////////////////////////////////////////////////////////////////////
using JNPF.Common.Contracts;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Yitter.IdGenerator;