仓库权限问题
This commit is contained in:
@@ -58,6 +58,7 @@ public class DataScopeAspect
|
||||
* 数据权限过滤关键字
|
||||
*/
|
||||
public static final String DATA_SCOPE = "dataScope";
|
||||
public static final String WAREHOUSE_DATA_SCOPE = "warehouseDataScope";
|
||||
|
||||
@Before("@annotation(controllerDataScope)")
|
||||
public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable
|
||||
@@ -77,7 +78,7 @@ public class DataScopeAspect
|
||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
{
|
||||
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias(), permission);
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias(),controllerDataScope.warehouseAlias(), permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +92,7 @@ public class DataScopeAspect
|
||||
* @param userAlias 用户别名
|
||||
* @param permission 权限字符
|
||||
*/
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission)
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias,String warehouseAlias, String permission)
|
||||
{
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
List<String> conditions = new ArrayList<String>();
|
||||
@@ -170,6 +171,31 @@ public class DataScopeAspect
|
||||
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
Object params = joinPoint.getArgs()[0];
|
||||
List<String> warehouseList = new ArrayList<String>();
|
||||
StringBuilder warehouseSqlString = new StringBuilder();
|
||||
for (SysRole role : user.getRoles()) {
|
||||
warehouseList.addAll(role.getWarehouseDataScope());
|
||||
if (role.isAdmin()){
|
||||
BaseEntity baseEntity = (BaseEntity) params;
|
||||
if (StringUtils.isNotEmpty(warehouseAlias)) {
|
||||
baseEntity.getParams().put(WAREHOUSE_DATA_SCOPE, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
warehouseSqlString.append(StringUtils.format(" OR {}.warehouse_id IN ({}) ", warehouseAlias,
|
||||
warehouseList.stream().map(s -> "'" + s + "'").collect(Collectors.joining(","))));
|
||||
|
||||
|
||||
if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
|
||||
BaseEntity baseEntity = (BaseEntity) params;
|
||||
if (StringUtils.isNotEmpty(warehouseAlias)){
|
||||
baseEntity.getParams().put(WAREHOUSE_DATA_SCOPE, " AND (" + warehouseSqlString.substring(4) + ")");
|
||||
}else {
|
||||
baseEntity.getParams().put(WAREHOUSE_DATA_SCOPE, " AND (" + warehouseSqlString.substring(5) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user