コード例 #1
0
        /// <summary>
        /// 最新---取区域图树结构数据
        /// </summary>
        /// <param name="geologyMappingTypeInput"></param>
        /// <returns></returns>
        public async Task <List <GeologyMappingTypeOutput> > GetMappingTree(string userId)
        {
            List <GeologyMappingTypeOutput> rootList = new List <GeologyMappingTypeOutput>();
            var result = await _GeologyMappingType.GetAllListAsync();

            List <GeologyMappingType> rightList = new List <GeologyMappingType>();
            string ProvinceID = System.Configuration.ConfigurationManager.AppSettings["ProvinceID"] ?? "";
            List <GeologyMappingType> returnList = result.FindAll(//根据ParentID == nul判断查找根节点
                delegate(GeologyMappingType gmt)
            {
                if (ProvinceID == "0")
                {
                    return(gmt.ParentID == null);
                }
                else
                {
                    return(gmt.ParentID == ProvinceID);
                }
            });

            returnList = returnList.OrderBy(s => s.Sn).ToList();
            if (userId.ToLower() != "admin")
            {
                using (var db = new InfoEarthFrameDbContext())
                {
                    var sql = "select * FROM" +
                              "	\"TBL_GEOLOGYMAPPINGTYPE\" T where  EXISTS(" +
                              "select \"LayerId\"  from \"TBL_GROUP_RIGHT\" r " +
                              " where r.\"GroupId\" in(" +
                              "select u.\"GroupId\"  from \"TBL_GROUP_USER\" u where u.\"UserId\"=\'" + userId + "\' and r.\"IsBrowse\"=1" +
                              "group by u.\"GroupId\" " +
                              ") and t.\"Id\"=r.\"LayerId\"" +
                              ")";

                    rightList = db.Database.SqlQuery <GeologyMappingType>(sql).ToList();
                    var roots = rightList.Where(p => string.IsNullOrEmpty(p.ParentID)).ToList();
                    returnList = returnList.Where(p => roots.Any(p1 => p1.Id == p.Id)).ToList();
                }
            }

            foreach (GeologyMappingType returnItem in returnList)
            {
                GeologyMappingTypeOutput rootItem = new GeologyMappingTypeOutput();
                rootItem.Id       = returnItem.Id;
                rootItem.Pid      = returnItem.ParentID;
                rootItem.Label    = returnItem.ClassName;
                rootItem.Paths    = returnItem.Paths;
                rootItem.Sn       = returnItem.Sn;
                rootItem.Children = CreatTree(result, rightList, returnItem.Id, userId);
                rootList.Add(rootItem);
            }
            return(rootList);
        }
コード例 #2
0
        //递归创建树
        private List <GeologyMappingTypeOutput> CreatTree(List <GeologyMappingType> list, List <GeologyMappingType> rightList, string pid, string userId)
        {
            List <GeologyMappingTypeOutput> treeList = new List <GeologyMappingTypeOutput>();
            var childList = list.FindAll(
                delegate(GeologyMappingType gmt)
            {
                return(gmt.ParentID == pid);
            });

            if (userId.ToLower() != "admin")
            {
                foreach (GeologyMappingType childItem in childList)
                {
                    foreach (var right in rightList)
                    {
                        if (right.Id == childItem.Id)
                        {
                            GeologyMappingTypeOutput item = new GeologyMappingTypeOutput();
                            item.Id       = childItem.Id;
                            item.Pid      = childItem.ParentID;
                            item.Label    = childItem.ClassName;
                            item.Paths    = childItem.Paths;
                            item.Sn       = childItem.Sn;
                            item.Children = CreatTree(list, rightList, item.Id, userId);
                            treeList.Add(item);
                            break;
                        }
                    }
                }
            }
            else
            {
                foreach (GeologyMappingType childItem in childList)
                {
                    GeologyMappingTypeOutput item = new GeologyMappingTypeOutput();
                    item.Id       = childItem.Id;
                    item.Pid      = childItem.ParentID;
                    item.Label    = childItem.ClassName;
                    item.Paths    = childItem.Paths;
                    item.Sn       = childItem.Sn;
                    item.Children = CreatTree(list, rightList, item.Id, userId);
                    treeList.Add(item);
                }
            }

            return(treeList);
        }