ZQN
2024-06-21 cdb4df5b86eefa7c36e4746b7fc00d7d15b52ce6
project-framework/src/main/java/com/project/framework/aspectj/DataScopeAspect.java
@@ -2,6 +2,7 @@
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;
@@ -81,6 +82,8 @@
                String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
                dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
                        controllerDataScope.userAlias(), permission);
            } else {
            }
        }
    }
@@ -124,19 +127,13 @@
            }
            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 {} IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
                        deptAlias, user.getDeptId(), user.getDeptId()));
            }
            else if (DATA_SCOPE_ORG.equals(dataScope))
            {
                sqlString.append(StringUtils.format(
                        " OR {} IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
                        deptAlias, user.getRecommendUser(), user.getRecommendUser()));
            }
            else if (DATA_SCOPE_SELF.equals(dataScope))
            {
@@ -159,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) + ")");
            }
        }
    }
@@ -175,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, "");
        }
    }
}