fixed #II0SQ

数据权限为空,sql增强报错的问题
This commit is contained in:
冷冷 2018-02-28 16:45:25 +08:00
parent d675c21e8e
commit 2d4aa87460
1 changed files with 6 additions and 10 deletions

View File

@ -1,11 +1,9 @@
package com.github.pig.common.bean.interceptor;
import com.baomidou.mybatisplus.plugins.SqlParserHandler;
import com.baomidou.mybatisplus.plugins.pagination.PageHelper;
import com.baomidou.mybatisplus.toolkit.PluginUtils;
import com.github.pig.common.util.UserUtils;
import com.github.pig.common.vo.UserVo;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.xiaoleilu.hutool.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
@ -14,12 +12,8 @@ import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -56,9 +50,11 @@ public class DataScopeInterceptor extends SqlParserHandler implements Intercepto
} else {
String scopeName = dataScope.getScopeName();
List<Integer> deptIds = dataScope.getDeptIds();
String join = CollectionUtil.join(deptIds, ",");
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
metaObject.setValue("delegate.boundSql.sql", originalSql);
if(StrUtil.isNotBlank(scopeName) && CollectionUtil.isNotEmpty(deptIds)){
String join = CollectionUtil.join(deptIds, ",");
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
metaObject.setValue("delegate.boundSql.sql", originalSql);
}
return invocation.proceed();
}
}