username@email.com
2023-11-21 a7ae63ad871b986eb1bede54219638edd4e29b63
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using DTO;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace zhengcaioa.Models
{
   public   class UserPage
    {
 
        
 
        /// <summary>
        ///  数据实体转换
        /// </summary>
        /// <param name="datadt"></param>
        /// <returns></returns>
        public static List<PageEntity> GetUserPage(string userid, List<int> systemidlist, string page_method)
        {
            List<PageEntity> entityList = new List<PageEntity>();
            
            var connectionString = "";
                try
            {
                var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.Development.json");
                connectionString = builder.Build().GetValue<string>("ConnectionStrings:" + "DefaultConnection");
            }
            catch
            {
                var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                               .AddJsonFile("appsettings.json");
                connectionString = builder.Build().GetValue<string>("ConnectionStrings:" + "DefaultConnection");
 
            }
 
            
            var dbContextOptionBuilder = new DbContextOptionsBuilder<zhengcaioaContext>();
            using (var db = new zhengcaioaContext(dbContextOptionBuilder.UseSqlServer(connectionString).Options))
            {
 
                #region 超级管理员操作
                var roleId = db.PltUserRoles.Where(o => o.UserId == userid).Select(o => o.RoleId).ToList(); ;//获取角色类型
                var rolename = db.PltRoles.Where(o => roleId.Contains(o.Id) && o.RoleName == "系统管理员").ToList();
 
                if (rolename!=null&& rolename.Count>0)//超级管理员操作
                {
                    var adminList = from page in db.PltPages
                                    where
                                    page.RecStatus == "A" &&
                                    new List<string> { "M", "P" }.Contains(page.PageType)
                                    orderby page.DisplaySeq
                                    select new PageEntity()
                                    {
                                        Open_Type = page.OpenType ?? 0,
                                        PageID = page.Id,
                                        SystemID = page.SystemId,
                                        PageName = page.PageName,
                                        DisplaySeq = page.DisplaySeq ?? 0,
                                        PagePath = page.PagePath,
                                        PageType = page.PageType,
                                        PageSuperior = page.PageSuperior,
                                        PageIco = page.PageIco ?? "",  //fa  fa-angle-right
                                        OpenType = page.OpenType ?? 0,
                                    };
                    entityList = adminList.ToList();
                }
                #endregion
                else
                {
                    var list = from user in db.PltUsers
                               join user_role in db.PltUserRoles on user.Id equals user_role.UserId
                               join role in db.PltRoles on user_role.RoleId equals role.Id
                               join auth in db.PltAuths.Distinct() on role.Id equals auth.RoleId
                               join page in db.PltPages on auth.ItemId equals page.Id
                               where
                               user.Id == userid &&
                               user.RecStatus == "A" &&
                               user_role.RecStatus == "A" &&
                               role.RecStatus == "A" &&
                               auth.RecStatus == "A" &&
                               page.RecStatus == "A" &&
                               new List<string> { "M", "P" }.Contains(page.PageType) &&
                               //systemidlist.Contains(page.system_id) &&
                               (string.IsNullOrEmpty(page_method) ? true : page.PageMethod == page_method)
                               orderby page.DisplaySeq
                               select new PageEntity()
                               {
                                   Open_Type = page.OpenType ?? 0,
                                   PageID = page.Id,
                                   SystemID = page.SystemId,
                                   PageName = page.PageName,
                                   DisplaySeq = page.DisplaySeq ?? 0,
                                   PagePath = page.PagePath,
                                   PageType = page.PageType,
                                   PageSuperior = page.PageSuperior,
                                   PageIco = page.PageIco ?? "",  //fa  fa-angle-right
                                   OpenType = page.OpenType ?? 0,
                               };
                    entityList = list.ToList().Distinct(new PageEntityIdComparer()).ToList();
                }
            }
 
            return entityList;
        }
 
        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <returns></returns>
        public static string GetMeum(string userid)
        {
            StringBuilder sbm = new StringBuilder();
            int count = 0;
            List<PageEntity> list = GetUserPage(userid, new List<int> { 1 }, "").OrderBy(D => D.DisplaySeq).ToList();
 
            list.Where(d => d.PageType == "M").Where(d => d.PageSuperior == "0").OrderBy(o => o.DisplaySeq).ToList().ForEach(f =>
            {
                count++;
                string exp = "";
                if (count == 1)
                {
                    exp = "class=\"active\"";
                }
                var leve2 = list.Where(d => d.PageSuperior == f.PageID && d.PageType == "M").ToList();
                sbm.Append("<li " + exp + " >");
                sbm.Append(" <a href = \"" + f.PagePath + "\" >");
                sbm.Append("<i class=\"" + f.PageIco + "\"></i><span class=\"nav-label\">" + f.PageName + "</span>");
                if (leve2.Count > 0)
                {
                    sbm.Append("<span class=\"fa arrow\"></span>");
                }
                sbm.Append(" </a>");
                #region 二级
                if (leve2.Count > 0)
                {
                    leve2.ForEach(t =>
                    {
                        var level3 = list.Where(d => d.PageSuperior == t.PageID && d.PageType == "M").OrderBy(o => o.DisplaySeq).ToList();
 
                        sbm.Append(" <ul class=\"nav nav-second-level\"> ");
                        sbm.Append("     <li>");
                        string arrow3 = "";
                        if (level3.Count > 0)
                        {
                            arrow3 = " <span class=\"fa arrow\"></span>";
                        }
                        sbm.Append("    <a  " + (level3.Count == 0 ? " class=\"J_menuItem\" " : "") + "    href = \"" + t.PagePath + "\" > <i class=\"" + t.PageIco + "\"></i>" + t.PageName + " " + arrow3 + "</a>");
                        #region 三级
                        if (level3.Count > 0)
                        {
                            sbm.Append("     <ul class=\"nav nav-third-level\"> ");
                            level3.ForEach(t3 =>
                            {
                                sbm.Append("      <li><a class=\"J_menuItem\" href=\"" + t3.PagePath + "\"> <i class=\"" + t3.PageIco + "\"></i>" + t3.PageName + "</a> </li> ");
                            });
                            sbm.Append("     </ul> ");
                        }
                        #endregion
                        sbm.Append("   </li>");
                        sbm.Append("</ul>");
 
                    });
                }
                #endregion
                sbm.Append("</li>");
            });
            return sbm.ToString();
        }
    }
}