|
@@ -1,6 +1,7 @@
|
|
|
package com.miaxis.framework.aspectj;
|
|
|
|
|
|
import com.miaxis.common.annotation.DataScope;
|
|
|
+import com.miaxis.common.core.domain.BaseBusinessEntity;
|
|
|
import com.miaxis.common.core.domain.BaseEntity;
|
|
|
import com.miaxis.common.core.domain.entity.SysRole;
|
|
|
import com.miaxis.common.core.domain.entity.SysUser;
|
|
@@ -58,6 +59,11 @@ public class DataScopeAspect
|
|
|
*/
|
|
|
public static final String DATA_SCOPE = "dataScope";
|
|
|
|
|
|
+ /**
|
|
|
+ * 部门表id(抽象概念,比如可以是驾校等)
|
|
|
+ */
|
|
|
+ public static final String DEPT_ID = "id";
|
|
|
+
|
|
|
// 配置织入点
|
|
|
@Pointcut("@annotation(com.miaxis.common.annotation.DataScope)")
|
|
|
public void dataScopePointCut()
|
|
@@ -114,17 +120,17 @@ public class DataScopeAspect
|
|
|
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 {}." +DEPT_ID+ " 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 {}." +DEPT_ID+ " = {} ", 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 {}." +DEPT_ID+ " 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))
|
|
@@ -144,10 +150,15 @@ public class DataScopeAspect
|
|
|
if (StringUtils.isNotBlank(sqlString.toString()))
|
|
|
{
|
|
|
Object params = joinPoint.getArgs()[0];
|
|
|
- if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
|
|
|
- {
|
|
|
- BaseEntity baseEntity = (BaseEntity) params;
|
|
|
- baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
|
+ if (StringUtils.isNotNull(params) ){
|
|
|
+ if (params instanceof BaseEntity){
|
|
|
+ BaseEntity baseEntity = (BaseEntity) params;
|
|
|
+ baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
|
+ }else if (params instanceof BaseBusinessEntity){
|
|
|
+ BaseBusinessEntity baseEntity = (BaseBusinessEntity) params;
|
|
|
+ baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|