using Microsoft.AspNetCore.Http; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using System; using System.Collections.Generic; using System.Text; using VOL.Core.Const; using VOL.Core.Enums; using VOL.Core.ManageUser; using VOL.Core.UserManager; using VOL.Entity.DomainModels; namespace VOL.Core.Infrastructure { public static class DictionaryHandler { /*2020.05.01增加根据用户信息加载字典数据源sql*/ /// /// 获取自定义数据源sql /// /// /// /// public static string GetCustomDBSql(string dicNo, string originalSql) { switch (dicNo) { case "roles": //2020.05.24增加绑定table表时,获取所有的角色列表 //注意,如果是2020.05.24之前获取的数据库脚本 //请在菜单【下拉框绑定设置】添加一个字典编号【t_roles】,除了字典编号,其他内容随便填写 case "t_roles": case "tree_roles": originalSql = GetRolesSql(originalSql); break; default: break; } return originalSql; } /// /// 获取解决的数据源,只能看到自己与下级所有角色 /// /// /// /// public static string GetRolesSql(string originalSql) { if (UserContext.Current.IsSuperAdmin) { return originalSql; } int currnetRoleId = UserContext.Current.RoleId; List roleIds = RoleContext.GetAllChildrenIds(currnetRoleId); roleIds.Add(currnetRoleId); if (DBType.Name == DbCurrentType.PgSql.ToString()) { originalSql = $"SELECT \"Role_Id\" AS \"id\",\"ParentId\" as \"parentId\",\"Role_Id\" AS \"key\",\"RoleName\" AS \"value\" FROM \"Sys_Role\"" + $" where \"Role_Id\" in ({string.Join(',', roleIds)})"; } else if (DBType.Name == DbCurrentType.Oracle.ToString() || DBType.Name == DbCurrentType.DM.ToString()) { originalSql = "SELECT ROLE_ID AS \"id\", PARENTID AS \"parentId\", ROLE_ID AS \"key\", ROLENAME AS \"value\" FROM SYS_ROLE where 1=1 "; return $" {originalSql} and ROLE_ID in ({string.Join(',', roleIds)})"; } else { originalSql = $@"SELECT Role_Id as 'key',Role_Id AS id,ParentId AS parentId,RoleName as 'value' FROM Sys_Role WHERE Enable=1 and Role_Id in ({string.Join(',', roleIds)})"; } return originalSql; } } }