From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001 From: maven <2163098428@qq.com> Date: 星期五, 01 八月 2025 13:27:59 +0800 Subject: [PATCH] yys 密码已重置 --- ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java | 82 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java new file mode 100644 index 0000000..c336760 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java @@ -0,0 +1,82 @@ +package com.ruoyi.framework.aspectj; + +import com.ruoyi.common.annotation.PersonalScope; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.system.domain.vo.SysRoleVo; +import com.ruoyi.system.mapper.SysRoleMenuMapper; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Field; +import java.util.List; + +/** + * 浠呯湅鎴戞潈闄� + * + * @Author zhuo + * @Date 2025/2/20 + */ +@Aspect +@Component +public class PersonalScopeAspect { + + @Autowired + private SysRoleMenuMapper sysRoleMenuMapper; + + @Pointcut("@annotation(com.ruoyi.common.annotation.PersonalScope)") + public void dataScopePointCut() { + } + + @Before("dataScopePointCut()") + public void doBefore(JoinPoint point) throws Throwable { + Long userId = SecurityUtils.getUserId(); + + // 鑾峰彇鐩爣鏂规硶鐨勭鍚� + MethodSignature signature = (MethodSignature) point.getSignature(); + // 鑾峰彇鐩爣鏂规硶涓婄殑娉ㄨВ + PersonalScope annotation = signature.getMethod().getAnnotation(PersonalScope.class); + + // 鑾峰彇鏉冮檺鍒ゆ柇鏄惁鏄粎鐪嬫垜 + SysRoleVo sysRoleVo = sysRoleMenuMapper.selectRoleMenu(annotation.permsName(), userId); + + //娌℃湁浠呯湅鎴戞潈闄愯烦杩� + if (sysRoleVo == null || sysRoleVo.getIsRersonal() == null || !sysRoleVo.getIsRersonal().equals(1)) { + return; + } + + // 鑾峰彇鏂归潰涓婃墍鏈夌殑瀵硅薄 + Object[] args = point.getArgs(); + for (Object arg : args) { + // 寰幆鏌ユ壘鍖归厤鐨勫璞� + if (arg.getClass().equals(annotation.objectName())) { + Class<?> argClass = arg.getClass(); + // 鏌ユ壘闇�瑕佸~鍏呯殑瀛楁 + Field declaredField = getField(argClass, annotation.paramName()); + declaredField.setAccessible(true); + // 娣诲姞鐢ㄦ埛Id + declaredField.set(arg, userId.intValue()); + } + } + } + + // 閫掑綊鏌ユ壘瀛楁 + private Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException { + // 浠庡綋鍓嶇被寮�濮嬫煡鎵惧瓧娈� + try { + return clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + // 濡傛灉褰撳墠绫绘病鏈夋壘鍒帮紝妫�鏌ョ埗绫� + Class<?> superClass = clazz.getSuperclass(); + if (superClass != null) { + return getField(superClass, fieldName); + } else { + throw e; + } + } + } +} -- Gitblit v1.9.3