SystemAuthStrategy.cs 3.59 KB
// ***********************************************************************
// <summary>
// 超级管理员授权策略
// </summary>
// ***********************************************************************

using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Hh.Mes.Service.SystemAuth
{
    /// <summary>
    /// 领域服务
    /// <para>超级管理员权限</para>
    /// <para>超级管理员使用guid.empty为ID,可以根据需要修改</para>
    /// </summary>
    public class SystemAuthStrategy : RepositorySqlSugar<SysUser>
    {
        protected SysUser _user;

        public List<SysModuleView> Modules
        {
            get
            {
                List<SysModuleView> modules = null;
                List<SysModuleElement> elements = null;

                //if (SystemCache.GetInstance.SysModuleViewCache.Count > 0)
                //{
                //    modules = SystemCache.GetInstance.SysModuleViewCache;
                //}
                //else
                //{
                    //根据用户的模块ID来获取具体模块信息
                    var moduleList = Context.Queryable<SysModule>().Where(t => true).ToList();
                    //组合成页面展示需要的SysModuleView格式
                    modules = new List<SysModuleView>();
                    foreach (var item in moduleList.OrderBy(u => u.SortNo))
                    {
                        SysModuleView sysModuleView = new SysModuleView();
                        sysModuleView.Id = item.Id;
                        sysModuleView.Code = item.Code;
                        sysModuleView.Name = item.Name;
                        sysModuleView.CascadeId = item.CascadeId;
                        sysModuleView.IconName = item.IconName;
                        sysModuleView.Url = item.Url;
                        sysModuleView.ParentId = item.ParentId;
                        sysModuleView.ParentName = item.ParentName;
                        sysModuleView.SortNo = item.SortNo;
                        sysModuleView.IsShow = item.IsShow.Value;
                        modules.Add(sysModuleView);
                    }
                //    SystemCache.GetInstance.SysModuleViewCache = modules;
                //}

                //if (SystemCache.GetInstance.SysModuleElementCache.Count > 0)
                //{
                //    elements = SystemCache.GetInstance.SysModuleElementCache;
                //}
                //else
                //{
                    //根据模块内元素ID
                    elements = Context.Queryable<SysModuleElement>().Where(t => true).ToList();
                    //SystemCache.GetInstance.SysModuleElementCache = elements;
                //}

                foreach (var module in modules)
                {
                    module.Elements = elements.Where(t => t.ModuleId == module.Id).OrderBy(t => t.Sort).ToList();
                }
                return modules;
            }
        }

        public List<SysRole> Roles
        {
            get 
            { 
                return Context.Queryable<SysRole>().Where(t => true).ToList(); 
            }
        }

        public List<SysDept> Orgs
        {
            get
            {
                return Context.Queryable<SysDept>().Where(t => true).ToList();
            }
        }

        public SysUser User
        {
            get 
            { 
                return _user; 
            }
            set 
            {
                _user = value;
            }
        }
    }

}