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();
|
}
|
}
|
}
|