| 
					
				 | 
			
			
				@@ -0,0 +1,73 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.ozs.framework.config; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.PluginUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.TableNameParser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.executor.Executor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.executor.statement.StatementHandler; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.mapping.BoundSql; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.mapping.MappedStatement; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.mapping.SqlCommandType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.session.ResultHandler; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.ibatis.session.RowBounds; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.Connection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.sql.SQLException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class KindBaseSqlMybatisIntercepts implements InnerInterceptor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 重写查询方法修改表名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 非忽略执行 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mpBs.sql(this.changeTable(mpBs.sql())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 重写 插入、删除、修改方法的表名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        MappedStatement ms = mpSh.mappedStatement(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SqlCommandType sct = ms.getSqlCommandType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 非忽略执行 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                mpBs.sql(this.changeTable(mpBs.sql())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    protected String changeTable(String sql) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TableNameParser parser = new TableNameParser(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TableNameParser.SqlToken> names = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parser.accept(names::add); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        StringBuilder builder = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int last = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (TableNameParser.SqlToken name : names) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String tname = name.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int start = name.getStart(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (start != last) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                builder.append(sql, last, start); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                builder.append("vehicle."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                builder.append(tname); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                builder.append("\""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            last = name.getEnd(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (last != sql.length()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            builder.append(sql.substring(last)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return builder.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |