增加数据权限

This commit is contained in:
不做码农
2022-01-22 20:47:48 +08:00
parent f5f5000854
commit bf26823a85
10 changed files with 275 additions and 118 deletions

View File

@@ -3,6 +3,7 @@ using Infrastructure.Attribute;
using Infrastructure.Enums;
using Microsoft.AspNetCore.Mvc;
using System.Collections;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Common;
using ZR.Model.System;
@@ -73,6 +74,24 @@ namespace ZR.Admin.WebApi.Controllers.System
return SUCCESS(DeptService.BuildDeptTreeSelect(depts), TIME_FORMAT_FULL);
}
/// <summary>
/// 获取角色部门信息
/// 加载对应角色部门列表树
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
[HttpGet("roleDeptTreeselect/{roleId}")]
public IActionResult RoleMenuTreeselect(int roleId)
{
var depts = DeptService.GetSysDepts(new SysDept());
var checkedKeys = DeptService.SelectRoleDepts(roleId);
return SUCCESS(new
{
checkedKeys,
depts = DeptService.BuildDeptTreeSelect(depts),
});
}
/// <summary>
/// 根据部门编号获取详细信息
/// </summary>

View File

@@ -103,13 +103,10 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
}
}
sysRoleDto.Update_by = User.Identity.Name;
int upResult = sysRoleService.UpdateRole(sysRoleDto);
if (upResult > 0)
{
//TODO 更新缓存用户权限信息
return SUCCESS(upResult);
}
return ToResponse(ApiResult.Error($"修改角色'{sysRoleDto.RoleName}'失败,请联系管理员"));

View File

@@ -45,13 +45,12 @@ namespace ZR.Admin.WebApi.Extensions
IsAutoCloseConnection = true//自动释放
}
});
//每次Sql执行前事件
//每次Sql执行前事件
DbScoped.SugarScope.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
{
var param = DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
FilterData(DbScoped.SugarScope.GetConnection(0));
FilterData();
logger.Info($"{sql}{param}");
};
@@ -79,7 +78,10 @@ namespace ZR.Admin.WebApi.Extensions
};
}
private static void FilterData(SqlSugarProvider db0)
/// <summary>
/// 分页获取count 不会追加sql
/// </summary>
private static void FilterData()
{
var u = App.User;
if (u == null) return;
@@ -98,9 +100,11 @@ namespace ZR.Admin.WebApi.Extensions
}
else if (DATA_SCOPE_CUSTOM.Equals(dataScope))//自定数据权限
{
//有问题
//var roleDepts = db0.Queryable<SysRoleDept>()
//.Where(f => f.RoleId == role.RoleId).Select(f => f.DeptId).ToList();
//var filter1 = new TableFilterItem<SysDept>(it => roleDepts.Contains(it.DeptId));
//DbScoped.SugarScope.GetConnection(0).QueryFilter.Add(filter1);
}
else if (DATA_SCOPE_DEPT.Equals(dataScope))//本部门数据
{