修复排序错误

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,4 +1,7 @@
namespace Tnb.Core;
using Mapster;
using SqlSugar;
namespace Tnb.Core;
/// <summary>
/// 字典对象
@@ -13,33 +16,35 @@ public class DObject : Dictionary<string, object>
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)
{
Add(code, value);
Add(codePath, value);
return;
}
DObject temp = this;
for (int i = 0; i < keys.Length; i++)
{
DObject temp = this;
var key = keys[i];
if (i < keys.Length - 1)
{
if (!ContainsKey(keys[i]))
{
temp = new DObject();
Add(keys[i], temp);
}
else
{
temp = (DObject)temp[keys[i]];
}
var obj = new DObject();
temp[key] = obj;
temp = obj;
}
else
{
temp.Add(keys[i], value);
temp[key] = value;
}
}
}
}