From 15b3e7a59fd14e802a5e48a8310e1cb8cb689bc7 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 26 三月 2025 14:04:18 +0800 Subject: [PATCH] 增加营业部权限控制 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java | 41 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 40 insertions(+), 1 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java index a6f3d53..01e7e68 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java @@ -1,5 +1,6 @@ package com.ruoyi.common.utils; +import com.ruoyi.common.core.domain.model.LoginUserApplet; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -43,7 +44,20 @@ throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED); } } - + /** + * 获取营业部ID + **/ + public static String getBusinessDeptId() + { + try + { + return getLoginUser().getUser().getBusinessDeptId(); + } + catch (Exception e) + { + throw new ServiceException("获取营业部ID异常", HttpStatus.UNAUTHORIZED); + } + } /** * 获取用户账户 **/ @@ -52,6 +66,20 @@ try { return getLoginUser().getUsername(); + } + catch (Exception e) + { + throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED); + } + } + /** + * 获取用户账户小程序 + **/ + public static String getUsernameApplet() + { + try + { + return getLoginUserApplet().getUsername(); } catch (Exception e) { @@ -73,6 +101,17 @@ throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED); } } + public static LoginUserApplet getLoginUserApplet() + { + try + { + return (LoginUserApplet) getAuthentication().getPrincipal(); + } + catch (Exception e) + { + throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED); + } + } /** * 获取Authentication -- Gitblit v1.7.1