using NewPdaSqlServer.DB; // ÄãµÄRepository»ùÀàËùÔÚµÄÃüÃû¿Õ¼ä using NewPdaSqlServer.Dto.Simple; using NewPdaSqlServer.entity; // ÒýÓÃʵÌå using SqlSugar; namespace NewPdaSqlServer.service.Simple; /// /// ¿´°å²Ëµ¥ÒµÎñ¹ÜÀíÆ÷ /// public class SimpleManager : Repository { /// /// »ñÈ¡Ê÷Ðβ˵¥ /// public ResultDto> GetTree() { try { var allNodes = Db.Queryable() .Where(m => m.IsEnabled && !m.IsDeleted) .OrderBy(m => m.SortOrder) .ToList(); var tree = BuildTree(allNodes, null); return ResultDto>.Ok(tree, tree.Count); } catch (Exception ex) { return ResultDto>.Error("»ñÈ¡Ê÷Ðβ˵¥Ê§°Ü: " + ex.Message); } } private List BuildTree(List allNodes, long? parentId) { return allNodes .Where(x => x.ParentId == parentId) .Select(x => new TreeViewDto { Id = x.Id, Title = x.Title, Field = x.Code, Spread = x.IsExpanded, Href = x.Url, NodeType = x.NodeType, Children = BuildTree(allNodes, x.Id) }) .ToList(); } /// /// »ñÈ¡²Ëµ¥Áбí /// public ResultDto> GetMenuList() { try { var list = Db.Queryable() .Where(m => m.IsEnabled && !m.IsDeleted) .OrderBy(m => m.SortOrder) .Select(m => new MesSimpleDto { Id = m.Id, ParentId = m.ParentId, NodeType = m.NodeType, NodeLevel = m.NodeLevel, Code = m.Code, Title = m.Title, Url = m.Url, CarouselDuration = m.CarouselDuration, IsExpanded = m.IsExpanded, IsEnabled = m.IsEnabled, SortOrder = m.SortOrder }) .ToList(); return ResultDto>.Ok(list, list.Count); } catch (Exception ex) { return ResultDto>.Error(ex.Message); } } /// /// ¸ù¾ÝID»ñÈ¡ÊÓͼÁбí /// Âß¼­Éý¼¶£º /// 1. ÏÈÕÒ×Ó½Úµã (ÂÖ²¥Ä£Ê½) /// 2. Èç¹ûû×ӽڵ㣬µ«×Ô¼ºÓÐURL (µ¥Ò³Ä£Ê½)£¬Ôò·µ»Ø×Ô¼º /// public ResultDto> GetBiViewsByMenuId(long menuId) { try { // 1. Ê×ÏȲéѯµã»÷µÄÕâ¸ö½Úµã±¾Éí (±ØÐëÊÇÆôÓÃÇÒδɾ³ý) var selfNode = Db.Queryable() .First(m => m.Id == menuId && m.IsEnabled && !m.IsDeleted); if (selfNode == null) return ResultDto>.Error("¸Ã½Úµã²»´æÔÚ»òÒѽûÓÃ"); // °²È«¼ì²é£ºÈç¹ûǰ¶Ë´«ÁË NodeType=0 µÄ ID ½øÀ´£¬ÕâÀïÀ¹½Ø if (selfNode.NodeType == 0) return ResultDto>.Error("Ŀ¼½Úµã²»¿ÉÖ±½ÓÔ¤ÀÀ"); // 2. ÅжÏ×Ô¼ºÊÇ·ñÓÐ URL // Åųý¿ÕÖµºÍռλ·û "ÂÖ²¥" if (!string.IsNullOrEmpty(selfNode.Url) && selfNode.Url != "ÂÖ²¥") { var selfView = new BiViewDto { Id = selfNode.Id, ParentId = selfNode.ParentId, Title = selfNode.Title, Url = selfNode.Url, Duration = (selfNode.CarouselDuration == null || selfNode.CarouselDuration <= 0) ? 10 : selfNode.CarouselDuration }; return ResultDto>.Ok(new List { selfView }, 1); } // 3. ×Ô¼ºÃ»ÓÐ URL£¬²éÕÒ×ÓĿ¼/×ÓÏî // ²éѯ ParentId = menuId ÇÒÀàÐÍΪ 2 µÄ×ÓÏî var childNodes = Db.Queryable() .Where(b => b.ParentId == menuId && b.NodeType == 2 && b.IsEnabled && !b.IsDeleted) .OrderBy(b => b.SortOrder) .ToList(); if (childNodes.Count > 0) { var resultList = childNodes.Select(b => new BiViewDto { Id = b.Id, ParentId = b.ParentId, Title = b.Title, Url = b.Url, // ×ÓÏîÈç¹ûûʱ¼ä£¬¼Ì³Ðµ±Ç° menuId ½ÚµãµÄʱ¼äÅäÖà Duration = (b.CarouselDuration == null || b.CarouselDuration <= 0) ? (selfNode.CarouselDuration ?? 10) : b.CarouselDuration }).ToList(); return ResultDto>.Ok(resultList, resultList.Count); } // 4. ×Ô¼ºÃ» URL ÇÒ ×ÓÏîҲû URL // ·µ»Ø¿ÕÁÐ±í£¬Ç°¶Ë bi_view.html ÊÕµ½ºó»áµ¯³ö¡°µ±Ç°²Ëµ¥ÏÂûÓпÉÂÖ²¥µÄÄÚÈÝ¡± return ResultDto>.Ok(new List(), 0); } catch (Exception ex) { return ResultDto>.Error("Êý¾Ý²éѯʧ°Ü: " + ex.Message); } } }