public List <Common.Model.LayuiSelectItem> GetChildServiceSelectTreeData(InfoEarthFrameDbContext db, string id, string userId)
        {
            var list    = new List <LayuiSelectItem>();
            var parents = new List <Tbl_LayerManager>();

            if (userId.ToLower() == "admin")
            {
                parents = db.LayerManagers.Where(p => p.PID == id).ToList();
            }
            else
            {
                var sql = "SELECT" +
                          "	r.*" +
                          "FROM" +
                          "	\"TBL_LAYERMANAGER\" r" +
                          " JOIN (" +
                          "	SELECT" +
                          "		K .\"Id\","+
                          "		K .\"MapId\""+
                          "	FROM" +
                          "		\"TBL_GROUP_RIGHT\" r"+
                          "	LEFT JOIN (" +
                          "		SELECT"+
                          "			P .\"Id\","+
                          "			l.\"Id\" AS \"MapId\""+
                          "		FROM"+
                          "			\"TBL_LAYERMANAGER\" l"+
                          "		LEFT JOIN \"TBL_DATAMAIN\" M ON l.\"DataMainID\" = M .\"Id\""+
                          "		LEFT JOIN \"TBL_GEOLOGYMAPPINGTYPE\" P ON P .\"Id\" = M .\"MappingTypeID\""+
                          "	) K ON K .\"Id\" = r.\"LayerId\"" +
                          "	WHERE" +
                          "		r.\"GroupId\" IN ("+
                          "			SELECT"+
                          "				gu.\"GroupId\""+
                          "			FROM"+
                          "				\"TBL_GROUP_USER\" gu"+
                          "			LEFT JOIN sdms_user u ON u.\"Id\" = gu.\"UserId\""+
                          "			WHERE 1=1"+
                          "			AND	u.\"Id\" = \'"+ userId + "\'" +
                          "		)"+
                          "	AND K .\"Id\" IS NOT NULL" +
                          " AND \"IsBrowse\"=1" +
                          ") T ON r.\"Id\" = T .\"MapId\"" +
                          "where (\"PID\"='" + id + "')";

                parents = db.Database.SqlQuery <Tbl_LayerManager>(sql).ToList();
            }
            if (parents != null && parents.Any())
            {
                foreach (var p in parents)
                {
                    var current = new LayuiSelectItem
                    {
                        name     = p.TEXT,
                        value    = p.Id,
                        children = GetChildServiceSelectTreeData(db, p.Id, userId),
                        tag      = p.DATASERVERKEY,
                        tag1     = p.URL,
                        tag2     = p.ZEROLEVELSIZE,
                        tag3     = p.TILESIZE,
                        tag4     = p.SERVICETYPE
                    };
                    list.Add(current);
                }
            }

            return(list);
        }
        public List <Common.Model.LayuiSelectItem> GetServiceSelectTreeData(string name, string userId)
        {
            var list    = new List <LayuiSelectItem>();
            var db      = (InfoEarthFrameDbContext)_iLayerManagerRepository.GetDbContext();
            var query   = db.LayerManagers.AsQueryable();
            var parents = new List <Tbl_LayerManager>();

            if (userId.ToLower() == "admin")
            {
                if (!string.IsNullOrEmpty(name))
                {
                    query = query.Where(p => p.TEXT != null && p.TEXT.ToLower().Contains(name.ToLower()));
                }
                parents = query.Where(p => string.IsNullOrEmpty(p.PID)).ToList();
            }
            else
            {
                var where1 = "";
                if (!string.IsNullOrEmpty(name))
                {
                    where1 += "			AND \"TEXT\" like '%"+ name + "%'";
                }
                var sql = "SELECT" +
                          "	r.*" +
                          "FROM" +
                          "	\"TBL_LAYERMANAGER\" r" +
                          " JOIN (" +
                          "	SELECT" +
                          "		K .\"Id\","+
                          "		K .\"MapId\""+
                          "	FROM" +
                          "		\"TBL_GROUP_RIGHT\" r"+
                          "	LEFT JOIN (" +
                          "		SELECT"+
                          "			P .\"Id\","+
                          "			l.\"Id\" AS \"MapId\""+
                          "		FROM"+
                          "			\"TBL_LAYERMANAGER\" l"+
                          "		LEFT JOIN \"TBL_DATAMAIN\" M ON l.\"DataMainID\" = M .\"Id\""+
                          "		LEFT JOIN \"TBL_GEOLOGYMAPPINGTYPE\" P ON P .\"Id\" = M .\"MappingTypeID\""+
                          "	) K ON K .\"Id\" = r.\"LayerId\"" +
                          "	WHERE" +
                          "		r.\"GroupId\" IN ("+
                          "			SELECT"+
                          "				gu.\"GroupId\""+
                          "			FROM"+
                          "				\"TBL_GROUP_USER\" gu"+
                          "			LEFT JOIN sdms_user u ON u.\"Id\" = gu.\"UserId\""+
                          "			WHERE 1=1"+
                          "AND	u.\"Id\" = \'"+ userId + "\'" +
                          "		)"+
                          "	AND K .\"Id\" IS NOT NULL" +
                          " AND \"IsBrowse\"=1" +
                          ") T ON r.\"Id\" = T .\"MapId\"" +
                          "where (\"PID\" is  null or(\"PID\"='')) " + where1 + "";
                parents = db.Database.SqlQuery <Tbl_LayerManager>(sql).ToList();
            }
            if (parents != null && parents.Any())
            {
                foreach (var p in parents)
                {
                    var current = new LayuiSelectItem
                    {
                        name     = p.TEXT,
                        value    = p.Id,
                        tag      = p.DATASERVERKEY,
                        tag1     = p.URL,
                        tag2     = p.ZEROLEVELSIZE,
                        tag3     = p.TILESIZE,
                        tag4     = p.SERVICETYPE,
                        children = GetChildServiceSelectTreeData(db, p.Id, userId)
                    };

                    list.Add(current);
                }
            }

            return(list);
        }