ningshuxia
2024-05-27 f51ccee7e76f598c1f718190d216f96b5ea1ca46
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
155
156
157
namespace Yw.Application
{
    /// <summary>
    /// MenuAuthority
    /// </summary>
    [Route("Auth/Menu/Authority")]
    [ApiDescriptionSettings("Auth", Name = "菜单权限", Order = 4000)]
    public class MenuAuthority_Controller : IDynamicApiController
    {
 
        private readonly Service.MenuAuthority _service = new();
 
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        [Route("GetMenuList@V1.0")]
        [HttpGet]
        public List<MenuAuthorityDto> GetMenuList([FromQuery][Required] UserIDUnderSoftwareIDInput input)
        {
            var dict = _service.GetMenuDict(input.UserID, input.SoftwareID);
            if (dict == null || dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<MenuAuthorityDto>();
            foreach (var item in dict)
            {
                if (item.Value)
                {
                    var vm = new MenuAuthorityDto(item.Key);
                    if (vm.ParentID > 0)
                    {
                        var vmParent = vmList.Find(x => x.ID == vm.ParentID);
                        if (vmParent != null)
                        {
                            vmList.Add(vm);
                        }
                    }
                    else
                    {
                        vmList.Add(vm);
                    }
                }
            }
            return vmList;
        }
 
        /// <summary>
        /// 获取菜单树列表
        /// </summary>
        [Route("GetMenuTreeList@V1.0")]
        [HttpGet]
        public List<MenuAuthorityTreeDto> GetMenuTreeList([FromQuery][Required] UserIDUnderSoftwareIDInput input)
        {
            var dict = _service.GetMenuDict(input.UserID, input.SoftwareID);
            if (dict == null || dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<MenuAuthorityTreeDto>();
            var tempList = new List<MenuAuthorityTreeDto>();
            foreach (var item in dict)
            {
                if (item.Value)
                {
                    var vm = new MenuAuthorityTreeDto(item.Key);
                    if (vm.ParentID > 0)
                    {
                        var vmParent = tempList.Find(x => x.ID == vm.ParentID);
                        if (vmParent != null)
                        {
                            vmParent.Children.Add(vm);
                        }
                    }
                    else
                    {
                        vmList.Add(vm);
                    }
                    tempList.Add(vm);
                }
            }
            return vmList;
        }
 
        /// <summary>
        /// 获取拥有菜单列表
        /// </summary>
        [Route("GetHaveMenuList@V1.0")]
        [HttpGet]
        public List<MenuAuthorityHaveDto> GetHaveMenuList([FromQuery][Required] UserIDUnderSoftwareIDInput input)
        {
            var dict = _service.GetMenuDict(input.UserID, input.SoftwareID);
            if (dict == null || dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<MenuAuthorityHaveDto>();
            foreach (var item in dict)
            {
                var vm = new MenuAuthorityHaveDto(item.Key, item.Value);
                if (vm.ParentID > 0)
                {
                    var vmParent = vmList.Find(x => x.ID == vm.ParentID);
                    if (vmParent != null)
                    {
                        if (!vmParent.Have)
                        {
                            vm.Have = false;
                        }
                    }
                }
                vmList.Add(vm);
            }
            return vmList;
        }
 
        /// <summary>
        /// 获取拥有菜单树列表
        /// </summary>
        [Route("GetHaveMenuTreeList@V1.0")]
        [HttpGet]
        public List<MenuAuthorityHaveTreeDto> GetHaveMenuTreeList([FromQuery][Required] UserIDUnderSoftwareIDInput input)
        {
            var dict = _service.GetMenuDict(input.UserID, input.SoftwareID);
            if (dict == null || dict.Count < 1)
            {
                return default;
            }
            var vmList = new List<MenuAuthorityHaveTreeDto>();
            var tempList = new List<MenuAuthorityHaveTreeDto>();
            foreach (var item in dict)
            {
                var vm = new MenuAuthorityHaveTreeDto(item.Key, item.Value);
                if (vm.ParentID > 0)
                {
                    var vmParent = tempList.Find(x => x.ID == vm.ParentID);
                    if (vmParent != null)
                    {
                        if (!vmParent.Have)
                        {
                            vm.Have = false;
                        }
                        vmParent.Children.Add(vm);
                    }
                }
                else
                {
                    vmList.Add(vm);
                }
                tempList.Add(vm);
            }
            return vmList;
        }
 
 
    }
}