修复排序错误

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

@@ -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))
{