using System; using System.Collections.Generic; using System.Text; namespace APT.BaseData.Domain.ApiModel.FM { public class RolePermissionTreeModel { // public Guid ID { get; set; } public bool IsCheck { get; set; } public string title { get; set; } public string key { get; set; } public List children { get; set; } = new List(); public static List GetRolePermissionTree(List formInfos) { var res = new List();//所有最终父节点 var dic = new Dictionary();//所有节点 foreach (var item in formInfos) { RolePermissionTreeModel rolePermissionTreeModel, prolePermissionTreeModel; if (dic.ContainsKey(item.Code)) { rolePermissionTreeModel = dic[item.Code]; rolePermissionTreeModel.title = item.Title; rolePermissionTreeModel.IsCheck = item.IsCheck; if (res.Contains(rolePermissionTreeModel)) res.Remove(rolePermissionTreeModel); } else { rolePermissionTreeModel = new RolePermissionTreeModel() { key = item.Code, title = item.Title, IsCheck=item.IsCheck }; dic.Add(rolePermissionTreeModel.key, rolePermissionTreeModel); } if (dic.ContainsKey(item.ParentCode)) prolePermissionTreeModel = dic[item.ParentCode]; else { prolePermissionTreeModel = new RolePermissionTreeModel() { key = item.ParentCode }; dic.Add(prolePermissionTreeModel.key, prolePermissionTreeModel); if (!res.Contains(prolePermissionTreeModel)) res.Add(prolePermissionTreeModel); } prolePermissionTreeModel.children.Add(rolePermissionTreeModel); } return res; } } public class FormInfo { public string Title { get; set; } public bool IsCheck { get; set; } public string Code { get; set; } public string ParentCode { get; set; } } public class RolePermissionResul { public List checks { get; set; } public List checkLastKey { get; set; } public List orgChecks { get; set; } public List orgCheckLastKey { get; set; } public List checkTenants { get; set; } public List rolePermissionTreeModels { get; set; } public List orgRolePermissionTreeModels { get; set; } public bool isRoot { get; set; } } }