优化功能

This commit is contained in:
不做码农 2023-11-12 10:08:42 +08:00
parent 2bc2911718
commit f78ccc2b4c
9 changed files with 61 additions and 42 deletions

View File

@ -157,6 +157,7 @@ namespace Infrastructure
{
new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()),
new Claim(ClaimTypes.Name, user.UserName),
new Claim(ClaimTypes.GroupSid, user.DeptId.ToString()),
new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user))
};

View File

@ -19,6 +19,7 @@ namespace Infrastructure
types.GetProperty("CreateBy", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("Create_by", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("UserId", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("DeptId", flag)?.SetValue(source, context.GetDeptId(), null);
return source;
}

View File

@ -80,6 +80,17 @@ namespace Infrastructure.Extensions
return !string.IsNullOrEmpty(uid) ? long.Parse(uid) : 0;
}
/// <summary>
/// 获取部门id
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static long GetDeptId(this HttpContext context)
{
var deptId = context.User.FindFirstValue(ClaimTypes.GroupSid);
return !string.IsNullOrEmpty(deptId) ? long.Parse(deptId) : 0;
}
/// <summary>
/// 获取登录用户名
/// </summary>

View File

@ -1,6 +1,5 @@
using Lazy.Captcha.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
@ -15,8 +14,6 @@ namespace ZR.Admin.WebApi.Controllers.System
[ApiExplorerSettings(GroupName = "sys")]
public class SysLoginController : BaseController
{
//static readonly NLog.Logger logger = NLog.LogManager.GetLogger("LoginController");
private readonly IHttpContextAccessor httpContextAccessor;
private readonly ISysUserService sysUserService;
private readonly ISysMenuService sysMenuService;
private readonly ISysLoginService sysLoginService;
@ -24,20 +21,16 @@ namespace ZR.Admin.WebApi.Controllers.System
private readonly ICaptcha SecurityCodeHelper;
private readonly ISysConfigService sysConfigService;
private readonly ISysRoleService roleService;
private readonly OptionsSetting optionSettings;
public SysLoginController(
IHttpContextAccessor contextAccessor,
ISysMenuService sysMenuService,
ISysUserService sysUserService,
ISysLoginService sysLoginService,
ISysPermissionService permissionService,
ISysConfigService configService,
ISysRoleService sysRoleService,
ICaptcha captcha,
IOptions<OptionsSetting> optionSettings)
ICaptcha captcha)
{
httpContextAccessor = contextAccessor;
SecurityCodeHelper = captcha;
this.sysMenuService = sysMenuService;
this.sysUserService = sysUserService;
@ -45,7 +38,6 @@ namespace ZR.Admin.WebApi.Controllers.System
this.permissionService = permissionService;
this.sysConfigService = configService;
roleService = sysRoleService;
this.optionSettings = optionSettings.Value;
}

View File

@ -37,7 +37,7 @@
"ShowDbLog": true, //db
"InitDb": false, //db
"DemoMode": false, //
"SingleLogin": false,//
"SingleLogin": false,///
"Upload": {
"uploadUrl": "http://localhost:8888", //访
"localSavePath": "", // wwwroot

View File

@ -1,5 +1,6 @@
using Infrastructure;
using SqlSugar.IOC;
using ZR.Model.Business;
using ZR.Model.System;
namespace ZR.ServiceCore.SqlSugar
@ -85,35 +86,5 @@ namespace ZR.ServiceCore.SqlSugar
db.QueryFilter.AddTableFilter(expRole.ToExpression());
db.QueryFilter.AddTableFilter(expLoginlog.ToExpression());
}
public static void FilterData1(int configId)
{
//获取当前用户的信息
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user == null) return;
var db = DbScoped.SugarScope.GetConnectionScope(configId);
foreach (var role in user.Roles.OrderBy(f => f.DataScope))
{
var dataScope = (DataPermiEnum)role.DataScope;
if (DataPermiEnum.All.Equals(dataScope))//所有权限
{
break;
}
else if (DataPermiEnum.CUSTOM.Equals(dataScope))//自定数据权限
{
}
else if (DataPermiEnum.DEPT.Equals(dataScope))//本部门数据
{
}
else if (DataPermiEnum.DEPT_CHILD.Equals(dataScope))//本部门及以下数据
{
}
else if (DataPermiEnum.SELF.Equals(dataScope))//仅本人数据
{
}
}
}
}
}

View File

@ -0,0 +1,43 @@
using Infrastructure;
using SqlSugar.IOC;
using ZR.ServiceCore.SqlSugar;
namespace ZR.ServiceCore
{
public class DataPermiSevice
{
/// <summary>
/// 你的业务库数据权限过滤方法
/// </summary>
/// <param name="configId"></param>
public static void FilterData(int configId)
{
//获取当前用户的信息
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user == null) return;
var db = DbScoped.SugarScope.GetConnectionScope(configId);
foreach (var role in user.Roles.OrderBy(f => f.DataScope))
{
var dataScope = (DataPermiEnum)role.DataScope;
if (DataPermiEnum.All.Equals(dataScope))//所有权限
{
break;
}
else if (DataPermiEnum.CUSTOM.Equals(dataScope))//自定数据权限
{
}
else if (DataPermiEnum.DEPT.Equals(dataScope))//本部门数据
{
}
else if (DataPermiEnum.DEPT_CHILD.Equals(dataScope))//本部门及以下数据
{
}
else if (DataPermiEnum.SELF.Equals(dataScope))//仅本人数据
{
}
}
}
}
}

View File

@ -42,7 +42,7 @@ namespace ZR.ServiceCore.SqlSugar
{
DataPermi.FilterData(0);
//ConfigId = 1的数据权限过滤
//DataPermi.FilterData1(1);
//DataPermiSevice.FilterData(1);
}
iocList.ForEach(iocConfig =>