From 177aa6f1c4601e4fb34aff04c4e328c98b489888 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 07 八月 2025 10:17:14 +0800 Subject: [PATCH] fix:bug --- FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenusQueryHandler.cs | 21 ++++++---- FlexJobApi.Core/Utils/JwtUtils/CurrentLogier.cs | 10 +++++ FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenuQueryHandler.cs | 22 +++++++---- FlexJobApi.User.Application/Auths/Commands/PasswordLoginCommandHandler.cs | 2 + FlexJobApi.Core/FlexJobApi.Core.xml | 10 +++++ FlexJobApi.Core/Models/User/Auths/Commands/PasswordLoginCommand.cs | 1 FlexJobApi.Core/Utils/JwtUtils/JwtUtils.cs | 14 ++++-- FlexJobApi.Core/Utils/StringUtils/StringUtils.cs | 12 +++++ 8 files changed, 69 insertions(+), 23 deletions(-) diff --git a/FlexJobApi.Core/FlexJobApi.Core.xml b/FlexJobApi.Core/FlexJobApi.Core.xml index 8c53358..e1b7912 100644 --- a/FlexJobApi.Core/FlexJobApi.Core.xml +++ b/FlexJobApi.Core/FlexJobApi.Core.xml @@ -4865,6 +4865,16 @@ 绾у埆 </summary> </member> + <member name="P:FlexJobApi.Core.CurrentLogier.Type"> + <summary> + 鐢ㄦ埛绫诲瀷 + </summary> + </member> + <member name="P:FlexJobApi.Core.CurrentLogier.ClientType"> + <summary> + 瀹㈡埛绔被鍨� + </summary> + </member> <member name="M:FlexJobApi.Core.JwtHandler.PipelineAsync(Microsoft.AspNetCore.Authorization.AuthorizationHandlerContext,Microsoft.AspNetCore.Http.DefaultHttpContext)"> <summary> 楠岃瘉绠¢亾锛屼篃灏辨槸楠岃瘉鏍稿績浠g爜 diff --git a/FlexJobApi.Core/Models/User/Auths/Commands/PasswordLoginCommand.cs b/FlexJobApi.Core/Models/User/Auths/Commands/PasswordLoginCommand.cs index d425e82..06b7e12 100644 --- a/FlexJobApi.Core/Models/User/Auths/Commands/PasswordLoginCommand.cs +++ b/FlexJobApi.Core/Models/User/Auths/Commands/PasswordLoginCommand.cs @@ -19,7 +19,6 @@ /// 璐﹀彿 /// </summary> [Required] - [DataValidation(ValidationTypes.Username)] public string UserName { get; set; } /// <summary> /// 瀵嗙爜 diff --git a/FlexJobApi.Core/Utils/JwtUtils/CurrentLogier.cs b/FlexJobApi.Core/Utils/JwtUtils/CurrentLogier.cs index be1f47e..019533f 100644 --- a/FlexJobApi.Core/Utils/JwtUtils/CurrentLogier.cs +++ b/FlexJobApi.Core/Utils/JwtUtils/CurrentLogier.cs @@ -47,5 +47,15 @@ /// 绾у埆 /// </summary> public int Level { get; set; } + + /// <summary> + /// 鐢ㄦ埛绫诲瀷 + /// </summary> + public EnumUserType Type { get; set; } + + /// <summary> + /// 瀹㈡埛绔被鍨� + /// </summary> + public EnumClientType ClientType { get; set; } } } diff --git a/FlexJobApi.Core/Utils/JwtUtils/JwtUtils.cs b/FlexJobApi.Core/Utils/JwtUtils/JwtUtils.cs index 232979c..5f1f8ad 100644 --- a/FlexJobApi.Core/Utils/JwtUtils/JwtUtils.cs +++ b/FlexJobApi.Core/Utils/JwtUtils/JwtUtils.cs @@ -35,6 +35,8 @@ { "UserName",logier.UserName }, { "PhoneNumber",logier.PhoneNumber }, { "Level",logier.Level }, + { "Type",logier.Type }, + { "ClientType",logier.ClientType }, }); // 鑾峰彇鍒锋柊 token logier.RefreshToken = JWTEncryption.GenerateRefreshToken(logier.AccessToken, 60 * 24); @@ -55,11 +57,13 @@ var logier = new CurrentLogier(); if (Guid.TryParse(App.User?.FindFirstValue("UserInfoId"), out var userInfoId)) logier.UserInfoId = userInfoId; else return null; - logier.Level = App.User?.FindFirstValue("Level")?.ToInt() ?? 0; - logier.Avatar = App.User?.FindFirstValue("Avatar"); - logier.Name = App.User?.FindFirstValue("Name"); - logier.UserName = App.User?.FindFirstValue("UserName"); - logier.PhoneNumber = App.User?.FindFirstValue("PhoneNumber"); + logier.Level = App.User.FindFirstValue("Level")?.ToInt() ?? 0; + logier.Avatar = App.User.FindFirstValue("Avatar"); + logier.Name = App.User.FindFirstValue("Name"); + logier.UserName = App.User.FindFirstValue("UserName"); + logier.PhoneNumber = App.User.FindFirstValue("PhoneNumber"); + logier.Type = App.User.FindFirstValue("Type").ToEnum<EnumUserType>("璇峰~鍐欑敤鎴风被鍨�").Value; + logier.ClientType = App.User.FindFirstValue("ClientType").ToEnum<EnumClientType>("璇峰~鍐欏鎴风绫诲瀷").Value; return logier; } return null; diff --git a/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs b/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs index 9fcf514..c8fa2cf 100644 --- a/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs +++ b/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs @@ -1,4 +1,6 @@ -锘縰sing System; +锘縰sing Furion.FriendlyException; +using Mapster.Utils; +using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Diagnostics.CodeAnalysis; @@ -45,6 +47,14 @@ return null; } + public static T? ToEnum<T>(this string str, string requiredMessage = null) + where T : struct + { + if (str.IsNotNull() && Enum.TryParse<T>(str, out var @enum)) return @enum; + if (requiredMessage.IsNotNull()) throw Oops.Oh(EnumErrorCodeType.s400, requiredMessage); + return null; + } + /// <summary> /// 鑾峰彇澶嶆暟鑻辨枃鍚� /// </summary> diff --git a/FlexJobApi.User.Application/Auths/Commands/PasswordLoginCommandHandler.cs b/FlexJobApi.User.Application/Auths/Commands/PasswordLoginCommandHandler.cs index a981cce..4e26bd1 100644 --- a/FlexJobApi.User.Application/Auths/Commands/PasswordLoginCommandHandler.cs +++ b/FlexJobApi.User.Application/Auths/Commands/PasswordLoginCommandHandler.cs @@ -53,6 +53,8 @@ UserName = userInfo.UserName, PhoneNumber = userInfo.PhoneNumber, Level = userInfo.Level, + Type = request.Type, + ClientType = request.ClientType }; JwtUtils.GenerateToken(logier); diff --git a/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenuQueryHandler.cs b/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenuQueryHandler.cs index a4d973e..d541762 100644 --- a/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenuQueryHandler.cs +++ b/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenuQueryHandler.cs @@ -34,14 +34,20 @@ .ProjectToType<GetMenuQueryResult>() .FirstOrDefaultAsync(cancellationToken); if (model == null) throw Oops.Oh(EnumErrorCodeType.s404, "璇ヨ彍鍗�"); - var items = await (from m in repMenu.AsQueryable().AsNoTracking() - join rm in repRoleMenu.AsQueryable().AsNoTracking() on m.Id equals rm.MenuId into rmg - from rmgi in rmg.DefaultIfEmpty() - join ur in repUserInfoRole.AsQueryable().AsNoTracking() on rmgi.RoleId equals ur.RoleId into urg - from urgi in urg.DefaultIfEmpty() - where m.ParentId == request.Id && (logier.Level == 999 || urgi.UserInfoId == logier.UserInfoId) && !m.IsDisabled - && (m.Type == EnumMenuType.Button || m.Type == EnumMenuType.Field) - select m).ProjectToType<GetMenuQueryResultItem>().ToListAsync(cancellationToken); + var q = repMenu.AsQueryable().AsNoTracking() + .Where(it => it.ParentId == model.Id) + .Where(it => it.Type == EnumMenuType.Button || it.Type == EnumMenuType.Field); + if (logier.Level != 999) + { + var menuIds = await repRoleMenu.AsQueryable().AsNoTracking() + .Where(it => it.Role.UserInfoRoles.Any(ur => ur.UserInfoId == logier.UserInfoId)) + .Select(it => it.MenuId) + .ToListAsync(cancellationToken); + q = q.Where(it => menuIds.Contains(it.Id)); + } + var items = await q + .ProjectToType<GetMenuQueryResultItem>() + .ToListAsync(cancellationToken); model.Groups = items.GroupBy(it => it.Group ?? "default") .Select(it => new GetMenuQueryResultGroup { diff --git a/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenusQueryHandler.cs b/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenusQueryHandler.cs index e89cda8..4176b12 100644 --- a/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenusQueryHandler.cs +++ b/FlexJobApi.User.Application/Auths/Queries/GetCurrentLogierMenusQueryHandler.cs @@ -31,14 +31,19 @@ public async Task<List<GetMenusQueryResultItem>> Handle(GetCurrentLogierMenusQuery request, CancellationToken cancellationToken) { var logier = JwtUtils.GetCurrentLogier(); - var all = await (from m in repMenu.AsQueryable().AsNoTracking() - join rm in repRoleMenu.AsQueryable().AsNoTracking() on m.Id equals rm.MenuId into rmg - from rmgi in rmg.DefaultIfEmpty() - join ur in repUserInfoRole.AsQueryable().AsNoTracking() on rmgi.RoleId equals ur.RoleId into urg - from urgi in urg.DefaultIfEmpty() - where (logier.Level == 999 || urgi.UserInfoId == logier.UserInfoId) && !m.IsDisabled - && (m.Type == EnumMenuType.Menu || m.Type == EnumMenuType.Page || m.Type == EnumMenuType.Modal) - select m).ProjectToType<GetMenusQueryResultItem>().ToListAsync(); + var q = repMenu.AsQueryable().AsNoTracking() + .OrderBy(it => it.Sort) + .Where(it => it.UserType == logier.Type && it.ClientType == logier.ClientType) + .Where(it => it.Type == EnumMenuType.Menu || it.Type == EnumMenuType.Page || it.Type == EnumMenuType.Modal); + if (logier.Level != 999) + { + var menuIds = await repRoleMenu.AsQueryable().AsNoTracking() + .Where(it => it.Role.UserInfoRoles.Any(ur => ur.UserInfoId == logier.UserInfoId)) + .Select(it => it.MenuId) + .ToListAsync(cancellationToken); + q = q.Where(it => menuIds.Contains(it.Id)); + } + var all = await q.ProjectToType<GetMenusQueryResultItem>().ToListAsync(); var models = all.Where(it => it.ParentId == null).ToList(); LoopChildrens(models, all, []); return models; -- Gitblit v1.9.1