123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Base;
- using Infrastructure;
- using Model;
- using SqlSugar.IOC;
- using Util;
- namespace SqlSugar
- {
- public enum DataPermiEnum
- {
- None = 0,
- /// <summary>
- /// 全部数据权限
- /// </summary>
- All = 1,
- /// <summary>
- /// 仅本人数据权限
- /// </summary>
- SELF = 5,
- /// <summary>
- /// 部门数据权限
- /// </summary>
- DEPT = 3,
- /// <summary>
- /// 自定数据权限
- /// </summary>
- CUSTOM = 2,
- /// <summary>
- /// 部门及以下数据权限
- /// </summary>
- DEPT_CHILD = 4
- }
- /// <summary>
- /// 数据权限
- /// </summary>
- public class DataPermi
- {
- /// <summary>
- /// 数据过滤
- /// </summary>
- /// <param name="configId">多库id</param>
- public static void FilterData(int configId)
- {
- //获取当前用户的信息
- var user = JwtUtil.GetLoginUser(App.HttpContext);
- if (user == null) return;
- //管理员不过滤
- // if (user.RoleIds.Any(f => f.Equals(GlobalConstant.AdminRole))) return;
- var db = DbScoped.SugarScope.GetConnectionScope(configId);
- // var expUser = Expressionable.Create<SysUser>();
- // var expRole = Expressionable.Create<SysRole>();
- // foreach (var role in user.Roles.OrderBy(f => f.DataScope))
- // {
- // var dataScope = (DataPermiEnum)role.DataScope;
- // if (DataPermiEnum.All.Equals(dataScope))//所有权限
- // {
- // break;
- // }
- // else if (DataPermiEnum.DEPT.Equals(dataScope))//本部门数据
- // {
- // expUser.Or(it => it.DeptId == user.DeptId);
- // }
- // else if (DataPermiEnum.SELF.Equals(dataScope))//仅本人数据
- // {
- // expUser.Or(it => it.UserId == user.UserId);
- // expRole.Or(it => user.RoleIds.Contains(it.RoleKey));
- // }
- // }
- // db.QueryFilter.AddTableFilter(expUser.ToExpression());
- // db.QueryFilter.AddTableFilter(expRole.ToExpression());
- }
- }
- }
|