huawei
4 天以前 63d047db30e03608479ab3d340e925bc3366357c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using NewPdaSqlServer.DB; // ÄãµÄRepository»ùÀàËùÔÚµÄÃüÃû¿Õ¼ä
using NewPdaSqlServer.Dto.Simple;
using NewPdaSqlServer.entity; // ÒýÓÃʵÌå
using SqlSugar;
 
namespace NewPdaSqlServer.service.Simple;
 
/// <summary>
///     ¿´°å²Ëµ¥ÒµÎñ¹ÜÀíÆ÷
/// </summary>
public class SimpleManager : Repository<MesSimple>
{
    /// <summary>
    ///     »ñÈ¡Ê÷Ðβ˵¥
    /// </summary>
    public ResultDto<List<TreeViewDto>> GetTree()
    {
        try
        {
            var allNodes = Db.Queryable<MesSimple>()
                .Where(m => m.IsEnabled && !m.IsDeleted)
                .OrderBy(m => m.SortOrder)
                .ToList();
 
            var tree = BuildTree(allNodes, null);
            return ResultDto<List<TreeViewDto>>.Ok(tree, tree.Count);
        }
        catch (Exception ex)
        {
            return ResultDto<List<TreeViewDto>>.Error("»ñÈ¡Ê÷Ðβ˵¥Ê§°Ü: " + ex.Message);
        }
    }
 
    private List<TreeViewDto> BuildTree(List<MesSimple> 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();
    }
 
    /// <summary>
    ///     »ñÈ¡²Ëµ¥Áбí
    /// </summary>
    public ResultDto<List<MesSimpleDto>> GetMenuList()
    {
        try
        {
            var list = Db.Queryable<MesSimple>()
                .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<List<MesSimpleDto>>.Ok(list, list.Count);
        }
        catch (Exception ex)
        {
            return ResultDto<List<MesSimpleDto>>.Error(ex.Message);
        }
    }
 
    /// <summary>
    ///     ¸ù¾ÝID»ñÈ¡ÊÓͼÁбí
    ///     Âß¼­Éý¼¶£º
    ///     1. ÏÈÕÒ×Ó½Úµã (ÂÖ²¥Ä£Ê½)
    ///     2. Èç¹ûû×ӽڵ㣬µ«×Ô¼ºÓÐURL (µ¥Ò³Ä£Ê½)£¬Ôò·µ»Ø×Ô¼º
    /// </summary>
 public ResultDto<List<BiViewDto>> GetBiViewsByMenuId(long menuId)
{
    try
    {
        // 1. Ê×ÏȲéѯµã»÷µÄÕâ¸ö½Úµã±¾Éí (±ØÐëÊÇÆôÓÃÇÒδɾ³ý)
        var selfNode = Db.Queryable<MesSimple>()
            .First(m => m.Id == menuId && m.IsEnabled && !m.IsDeleted);
 
        if (selfNode == null) return ResultDto<List<BiViewDto>>.Error("¸Ã½Úµã²»´æÔÚ»òÒѽûÓÃ");
        
        // °²È«¼ì²é£ºÈç¹ûǰ¶Ë´«ÁË NodeType=0 µÄ ID ½øÀ´£¬ÕâÀïÀ¹½Ø
        if (selfNode.NodeType == 0) return ResultDto<List<BiViewDto>>.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<List<BiViewDto>>.Ok(new List<BiViewDto> { selfView
}, 1);
        }
 
        // 3. ×Ô¼ºÃ»ÓРURL£¬²éÕÒ×ÓĿ¼/×ÓÏî
        // ²éѯ ParentId = menuId ÇÒÀàÐÍΪ 2 µÄ×ÓÏî
        var childNodes = Db.Queryable<MesSimple>()
            .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<List<BiViewDto>>.Ok(resultList, resultList.Count);
}
 
// 4. ×Ô¼ºÃ» URL ÇÒ ×ÓÏîҲû URL
// ·µ»Ø¿ÕÁÐ±í£¬Ç°¶Ë bi_view.html ÊÕµ½ºó»áµ¯³ö¡°µ±Ç°²Ëµ¥ÏÂûÓпÉÂÖ²¥µÄÄÚÈÝ¡±
return ResultDto<List<BiViewDto>>.Ok(new List<BiViewDto>(), 0);
    }
    catch (Exception ex)
    {
        return ResultDto<List<BiViewDto>>.Error("Êý¾Ý²éѯʧ°Ü: " + ex.Message);
    }
}
   
}