| | |
| | | import com.baomidou.mybatisplus.core.toolkit.PluginUtils; |
| | | import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; |
| | | import org.dromara.common.mybatis.handler.PlusDataPermissionHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import net.sf.jsqlparser.expression.Expression; |
| | | import net.sf.jsqlparser.statement.delete.Delete; |
| | | import net.sf.jsqlparser.statement.select.PlainSelect; |
| | |
| | | import org.apache.ibatis.mapping.SqlCommandType; |
| | | import org.apache.ibatis.session.ResultHandler; |
| | | import org.apache.ibatis.session.RowBounds; |
| | | import org.dromara.common.mybatis.handler.PlusDataPermissionHandler; |
| | | |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | |
| | | * @author Lion Li |
| | | * @version 3.5.0 |
| | | */ |
| | | @Slf4j |
| | | public class PlusDataPermissionInterceptor extends JsqlParserSupport implements InnerInterceptor { |
| | | |
| | | private final PlusDataPermissionHandler dataPermissionHandler = new PlusDataPermissionHandler(); |
| | | private final PlusDataPermissionHandler dataPermissionHandler; |
| | | |
| | | public PlusDataPermissionInterceptor(String mapperPackage) { |
| | | this.dataPermissionHandler = new PlusDataPermissionHandler(mapperPackage); |
| | | } |
| | | |
| | | @Override |
| | | public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { |
| | |
| | | return; |
| | | } |
| | | // 检查是否无效 无数据权限注解 |
| | | if (dataPermissionHandler.isInvalid(ms.getId())) { |
| | | if (dataPermissionHandler.invalid(ms.getId())) { |
| | | return; |
| | | } |
| | | // 解析 sql 分配对应方法 |
| | |
| | | if (InterceptorIgnoreHelper.willIgnoreDataPermission(ms.getId())) { |
| | | return; |
| | | } |
| | | // 检查是否无效 无数据权限注解 |
| | | if (dataPermissionHandler.invalid(ms.getId())) { |
| | | return; |
| | | } |
| | | PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql(); |
| | | mpBs.sql(parserMulti(mpBs.sql(), ms.getId())); |
| | | } |
| | |
| | | @Override |
| | | protected void processSelect(Select select, int index, String sql, Object obj) { |
| | | SelectBody selectBody = select.getSelectBody(); |
| | | if (selectBody instanceof PlainSelect) { |
| | | this.setWhere((PlainSelect) selectBody, (String) obj); |
| | | if (selectBody instanceof PlainSelect plainSelect) { |
| | | this.setWhere(plainSelect, (String) obj); |
| | | } else if (selectBody instanceof SetOperationList setOperationList) { |
| | | List<SelectBody> selectBodyList = setOperationList.getSelects(); |
| | | selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj)); |