v3.4.6
This commit is contained in:
@@ -160,6 +160,79 @@ public static class CodeGenHelper
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据列表生成树形表格.
|
||||
/// </summary>
|
||||
/// <param name="realList">数据列表.</param>
|
||||
/// <param name="parentField">树形父级字段.</param>
|
||||
/// <param name="treeShowField">树形显示字段.</param>
|
||||
/// <returns></returns>
|
||||
public static List<Dictionary<string, object>> GetTreeList(List<Dictionary<string, object>> realList, string parentField, string treeShowField)
|
||||
{
|
||||
var res = new List<Dictionary<string, object>>();
|
||||
if (realList.Any())
|
||||
{
|
||||
var parentFieldId = SnowflakeIdHelper.NextId();
|
||||
|
||||
foreach (var item in realList)
|
||||
{
|
||||
if (realList.Any(x => x["id"].Equals(item[parentField]))) item[parentFieldId] = item[parentField];
|
||||
else item[parentFieldId] = null;
|
||||
item[parentField] = realList.Find(x => x["id"] == item["id"])[treeShowField];
|
||||
}
|
||||
var parentFieldRep = parentField.Substring(0, parentField.Length - 4);
|
||||
for (int i = 0; i < realList.Count; i++)
|
||||
{
|
||||
if (realList[i][parentFieldId].IsNullOrEmpty())
|
||||
{
|
||||
if (realList[i][parentFieldRep] == null) realList[i][parentFieldRep] = realList[i][treeShowField];
|
||||
var childList = realList.Where(x => x[parentFieldId] != null && x[parentFieldId].Equals(realList[i]["id"])).ToList();
|
||||
if (childList.Any()) GetTreeList(realList, realList[i], parentFieldId);
|
||||
res.Add(realList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static void GetTreeList(List<Dictionary<string, object>> allList, Dictionary<string, object> currentItem, string pId)
|
||||
{
|
||||
var childList = allList.Where(x => x[pId] != null && x[pId].Equals(currentItem["id"])).ToList();
|
||||
if (childList.Any()) childList.ForEach(x => GetTreeList(allList, x, pId));
|
||||
if (childList.Any())
|
||||
{
|
||||
var item = allList.Find(x => x["id"].Equals(currentItem["id"]));
|
||||
item["children"] = childList;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据集合捞取所有子集id.
|
||||
/// </summary>
|
||||
/// <param name="allList">key : 主键Id , value : 父亲Id.</param>
|
||||
/// <param name="currentId">当前id.</param>
|
||||
/// <param name="resList">res.</param>
|
||||
public static List<string> GetChildIdList(Dictionary<string, string> allList, string currentId, List<string> resList)
|
||||
{
|
||||
if (resList == null) resList = new List<string>() { currentId };
|
||||
else resList.Add(currentId);
|
||||
if (allList.Any())
|
||||
{
|
||||
var cItemList = allList.Where(x => x.Value.IsNotEmptyOrNull() && x.Value.Equals(currentId)).ToList();
|
||||
if (cItemList.Any())
|
||||
{
|
||||
foreach (var item in cItemList)
|
||||
{
|
||||
var cIdList = GetChildIdList(allList, item.Key, resList);
|
||||
resList.Add(item.Key);
|
||||
if (cIdList.Any()) resList.AddRange(cIdList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取排序真实字段.
|
||||
/// </summary>
|
||||
@@ -190,7 +263,7 @@ public static class CodeGenHelper
|
||||
field = entityInfo.Columns.Find(it => it.PropertyName.Equals(sort.ToUpperCase()))?.DbColumnName;
|
||||
break;
|
||||
}
|
||||
return string.IsNullOrEmpty(field) ? "" : field;
|
||||
return string.IsNullOrEmpty(field) ? null : field;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user