From 6441ad9f4dc3c1b2af1b9dad505c62ff75d69c4e Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 08 十月 2026 15:52:17 +0800
Subject: [PATCH] 项目重构
---
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java | 87 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 87 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..767f98e
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/PersonalScopeAspect.java
@@ -0,0 +1,87 @@
+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);
+
+ // 瓒呯骇绠$悊鍛樻煡鐪嬫姤鍛婄紪鍒舵椂涓嶉檺鍒朵负鈥滀粎鐪嬫垜鈥�
+ if (SecurityUtils.isAdmin(userId) && "business:reportPreparation".equals(annotation.permsName())) {
+ return;
+ }
+
+ // 鑾峰彇鏉冮檺鍒ゆ柇鏄惁鏄粎鐪嬫垜
+ 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