Browse Source

fix 修复数据权限 仅自己 相关问题

疯狂的狮子li 3 năm trước cách đây
mục cha
commit
c5dbd04c9c

+ 11 - 6
ruoyi-common/src/main/java/com/ruoyi/common/enums/DataScopeType.java

@@ -23,34 +23,39 @@ public enum DataScopeType {
     /**
      * 全部数据权限
      */
-    ALL("1", ""),
+    ALL("1", "", ""),
 
     /**
      * 自定数据权限
      */
-    CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) "),
+    CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) ", ""),
 
     /**
      * 部门数据权限
      */
-    DEPT("3", " #{#deptName} = #{#user.deptId} "),
+    DEPT("3", " #{#deptName} = #{#user.deptId} ", ""),
 
     /**
      * 部门及以下数据权限
      */
-    DEPT_AND_CHILD("4", " #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} )"),
+    DEPT_AND_CHILD("4", " #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} )", ""),
 
     /**
      * 仅本人数据权限
      */
-    SELF("5", " #{#userName?:1} = #{#user.userId} ");
+    SELF("5", " #{#userName} = #{#user.userId} " , " 1 = 0 ");
 
     private final String code;
 
     /**
      * 语法 采用 spel 模板表达式
      */
-    private final String sql;
+    private final String sqlTemplate;
+
+    /**
+     * 不满足 sqlTemplate 则填充
+     */
+    private final String elseSql;
 
     public static DataScopeType findCode(String code) {
         if (StringUtils.isBlank(code)) {

+ 3 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/handler/PlusDataPermissionHandler.java

@@ -96,13 +96,14 @@ public class PlusDataPermissionHandler {
                     return "";
                 }
                 // 不包含 key 变量 则不处理
-                if (!StringUtils.contains(type.getSql(), "#" + dataColumn.key())) {
+                if (!StringUtils.contains(type.getSqlTemplate(), "#" + dataColumn.key())) {
+                    sqlString.append(type.getElseSql());
                     continue;
                 }
                 // 更新或删除需满足所有条件
                 sqlString.append(isSelect ? " OR " : " AND ");
                 // 解析sql模板并填充
-                String sql = parser.parseExpression(type.getSql(), parserContext).getValue(context, String.class);
+                String sql = parser.parseExpression(type.getSqlTemplate(), parserContext).getValue(context, String.class);
                 sqlString.append(sql);
             }
         }