Commit 81d21b0d authored by tianbo's avatar tianbo

数据权限拦截器优化

parent f87ef47f
...@@ -79,26 +79,13 @@ public class PermissionInterceptor implements Interceptor { ...@@ -79,26 +79,13 @@ public class PermissionInterceptor implements Interceptor {
if(!ValidationUtil.isEmpty(dataAuth)){ if(!ValidationUtil.isEmpty(dataAuth)){
dataAuthRule = !ValidationUtil.isEmpty(dataAuthRule) ? dataAuthRule : dataAuth.interfacePath(); dataAuthRule = !ValidationUtil.isEmpty(dataAuthRule) ? dataAuthRule : dataAuth.interfacePath();
} }
// 数据权限地址为空返回空数据
if(ValidationUtil.isEmpty(dataAuthRule)){
// method.getReturnType().isPrimitive() = true 是count语句
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
}
ReginParams reginParam = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId() ReginParams reginParam = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId()
, RequestContext.getToken())).toString(), ReginParams.class); , RequestContext.getToken())).toString(), ReginParams.class);
if (ValidationUtil.isEmpty(reginParam) || ValidationUtil.isEmpty(reginParam.getUserModel())) {
// method.getReturnType().isPrimitive() = true 是count语句
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
}
// 用户数据权限配置信息 // 用户数据权限配置信息
Map<String, List<PermissionDataruleModel>> dataAuthorization = Privilege.permissionDataruleClient.queryByUser(reginParam.getUserModel().getUserId(), Map<String, List<PermissionDataruleModel>> dataAuthorization = null;
dataAuthRule).getResult(); if (!ValidationUtil.isEmpty(reginParam) && !ValidationUtil.isEmpty(reginParam.getUserModel())) {
// 没有数据权限直接返回空数据 dataAuthorization = Privilege.permissionDataruleClient.queryByUser(reginParam.getUserModel().getUserId(),
if (ValidationUtil.isEmpty(dataAuthorization)) { dataAuthRule).getResult();
PermissionInterceptorContext.clean();
return method.getReturnType().isPrimitive() ? invocation.proceed() : null;
} }
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
...@@ -194,15 +181,19 @@ public class PermissionInterceptor implements Interceptor { ...@@ -194,15 +181,19 @@ public class PermissionInterceptor implements Interceptor {
mainTable : selectBody.getFromItem().getAlias().getName(); mainTable : selectBody.getFromItem().getAlias().getName();
String authSql; String authSql;
// 过滤没有配置数据权限的用户组 if (ValidationUtil.isEmpty(dataAuthorization)) {
Map<String, List<PermissionDataruleModel>> nonEmptyDataAuthorization =
dataAuthorization.entrySet().stream().filter(map -> !ValidationUtil.isEmpty(map.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// 没有配置数据权限直接返回 false 条件
if (ValidationUtil.isEmpty(nonEmptyDataAuthorization)) {
authSql = falseCondition; authSql = falseCondition;
} else { } else {
// 解析数据权限sql // 过滤没有配置数据权限的用户组
authSql = parseDataAuthorization(nonEmptyDataAuthorization, reginParams, mainTableAlias, boundSql); Map<String, List<PermissionDataruleModel>> nonEmptyDataAuthorization =
dataAuthorization.entrySet().stream().filter(map -> !ValidationUtil.isEmpty(map.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// 没有配置数据权限直接返回 false 条件
if (ValidationUtil.isEmpty(nonEmptyDataAuthorization)) {
authSql = falseCondition;
} else {
// 解析数据权限sql
authSql = parseDataAuthorization(nonEmptyDataAuthorization, reginParams, mainTableAlias, boundSql);
}
} }
// 替换数据权限 // 替换数据权限
if (!ValidationUtil.isEmpty(authSql)) { if (!ValidationUtil.isEmpty(authSql)) {
......
...@@ -2041,12 +2041,12 @@ ...@@ -2041,12 +2041,12 @@
<!-- <if test="orgCode != null">--> <!-- <if test="orgCode != null">-->
<!-- AND c.org_code = #{orgCode}--> <!-- AND c.org_code = #{orgCode}-->
<!-- </if>--> <!-- </if>-->
ORDER BY c.check_time DESC
<choose>
<when test="pageSize==-1"></when>
<when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
</choose>
</where> </where>
ORDER BY c.check_time DESC
<choose>
<when test="pageSize==-1"></when>
<when test="pageSize!=-1">limit #{offset},#{pageSize}</when>
</choose>
</select> </select>
<select id="getCheckListByTaskId" resultType="com.yeejoin.amos.supervision.dao.entity.Check"> <select id="getCheckListByTaskId" resultType="com.yeejoin.amos.supervision.dao.entity.Check">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment