调整地区数据缓存

This commit is contained in:
yxw
2026-01-02 17:02:00 +08:00
parent 85c91244cd
commit 1331477ac9
6 changed files with 199 additions and 107 deletions

View File

@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Atomx.Utils.Extension
{
public static class TreeExtension
{
public static List<T> ToTree<T>(this List<T> list, Func<T, string> getId, Func<T, string> getParentId, Action<T, List<T>> setChildren, string rootParentId = "0")
{
var lookup = new Dictionary<string, T>();
var result = new List<T>();
foreach (var item in list)
{
var id = getId(item);
lookup[id] = item;
}
foreach (var item in list)
{
var parentId = getParentId(item);
if (parentId == rootParentId || !lookup.ContainsKey(parentId))
{
result.Add(item);
}
else
{
var parent = lookup[parentId];
var children = new List<T>();
setChildren(parent, children);
children.Add(item);
}
}
return result;
}
}
}