| | |
| | | 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.entity.SysRole; |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * 数据过滤处理 |
| | |
| | | * 仅本人数据权限 |
| | | */ |
| | | public static final String DATA_SCOPE_SELF = "5"; |
| | | |
| | | /** |
| | | * 本机构数据权限 |
| | | */ |
| | | public static final String DATA_SCOPE_ORG = "6"; |
| | | |
| | | /** |
| | | * 数据权限过滤关键字 |
| | |
| | | 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)) |
| | |
| | | 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_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)) |
| | | { |
| | | if (StringUtils.isNotBlank(userAlias)) |
| | | { |
| | | sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); |
| | | sqlString.append(StringUtils.format(" OR {} = {} ", userAlias, user.getUserId())); |
| | | } |
| | | else |
| | | { |
| | | // 数据权限为仅本人且没有userAlias别名不查询任何数据 |
| | | sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); |
| | | sqlString.append(StringUtils.format(" OR {}= = 0 ", deptAlias)); |
| | | } |
| | | } |
| | | conditions.add(dataScope); |