From d7cbeb2ed120af3db849aecfd89ac9b9980a60f1 Mon Sep 17 00:00:00 2001
From: ZQN <364596817@qq.com>
Date: 星期三, 04 九月 2024 11:11:57 +0800
Subject: [PATCH] 列表

---
 project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java b/project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java
index f890106..0305543 100644
--- a/project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java
+++ b/project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java
@@ -1,13 +1,8 @@
 package com.project.framework.aspectj;
 
-import java.util.ArrayList;
-import java.util.List;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.springframework.stereotype.Component;
 import com.project.common.annotation.DataScope;
 import com.project.common.core.domain.BaseEntity;
+import com.project.common.core.domain.BaseQuery;
 import com.project.common.core.domain.entity.SysRole;
 import com.project.common.core.domain.entity.SysUser;
 import com.project.common.core.domain.model.LoginUser;
@@ -15,6 +10,13 @@
 import com.project.common.utils.SecurityUtils;
 import com.project.common.utils.StringUtils;
 import com.project.framework.security.context.PermissionContextHolder;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 鏁版嵁杩囨护澶勭悊
@@ -51,6 +53,11 @@
     public static final String DATA_SCOPE_SELF = "5";
 
     /**
+     * 鏈満鏋勬暟鎹潈闄�
+     */
+    public static final String DATA_SCOPE_ORG = "6";
+
+    /**
      * 鏁版嵁鏉冮檺杩囨护鍏抽敭瀛�
      */
     public static final String DATA_SCOPE = "dataScope";
@@ -75,6 +82,8 @@
                 String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
                 dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
                         controllerDataScope.userAlias(), permission);
+            } else {
+
             }
         }
     }
@@ -113,29 +122,29 @@
             else if (DATA_SCOPE_CUSTOM.equals(dataScope))
             {
                 sqlString.append(StringUtils.format(
-                        " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
+                        " OR {} IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
                         role.getRoleId()));
             }
             else if (DATA_SCOPE_DEPT.equals(dataScope))
             {
-                sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
+                sqlString.append(StringUtils.format(" OR {} = {} ", deptAlias, user.getDeptId()));
             }
             else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
             {
                 sqlString.append(StringUtils.format(
-                        " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
+                        " OR {} IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
                         deptAlias, user.getDeptId(), user.getDeptId()));
             }
             else if (DATA_SCOPE_SELF.equals(dataScope))
             {
                 if (StringUtils.isNotBlank(userAlias))
                 {
-                    sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
+                    sqlString.append(StringUtils.format(" OR {} = {} ", userAlias, user.getUserId()));
                 }
                 else
                 {
                     // 鏁版嵁鏉冮檺涓轰粎鏈汉涓旀病鏈塽serAlias鍒悕涓嶆煡璇换浣曟暟鎹�
-                    sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
+                    sqlString.append(StringUtils.format(" OR {}= = 0 ", deptAlias));
                 }
             }
             conditions.add(dataScope);
@@ -147,7 +156,10 @@
             if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
             {
                 BaseEntity baseEntity = (BaseEntity) params;
-                baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
+                baseEntity.getParams().put(DATA_SCOPE, "  (" + sqlString.substring(4) + ")");
+            } else if (StringUtils.isNotNull(params) && params instanceof BaseQuery) {
+                BaseQuery baseQuery = (BaseQuery) params;
+                baseQuery.getParams().put(DATA_SCOPE, "  (" + sqlString.substring(4) + ")");
             }
         }
     }
@@ -163,5 +175,9 @@
             BaseEntity baseEntity = (BaseEntity) params;
             baseEntity.getParams().put(DATA_SCOPE, "");
         }
+        else if (StringUtils.isNotNull(params) && params instanceof BaseQuery) {
+            BaseQuery baseQuery = (BaseQuery) params;
+            baseQuery.getParams().put(DATA_SCOPE, "");
+        }
     }
 }

--
Gitblit v1.9.1