Browse Source

发布 3.5.0.1-SNAPSHOT fixed gitee issues/I4P9EN

hubin 3 years ago
parent
commit
4660b248a0

+ 1 - 1
build.gradle

@@ -2,7 +2,7 @@ import java.time.LocalDateTime
 
 allprojects {
     group = 'com.baomidou'
-    version = "3.5.0"
+    version = "3.5.0.1-SNAPSHOT"
 }
 
 ext {

+ 16 - 19
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptor.java

@@ -41,14 +41,7 @@ import org.apache.ibatis.session.RowBounds;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -106,9 +99,9 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
             processSelectBody(withItem.getSubSelect().getSelectBody());
         } else {
             SetOperationList operationList = (SetOperationList) selectBody;
-            List<SelectBody> selectBodys = operationList.getSelects();
-            if (CollectionUtils.isNotEmpty(selectBodys)) {
-                selectBodys.forEach(this::processSelectBody);
+            List<SelectBody> selectBodyList = operationList.getSelects();
+            if (CollectionUtils.isNotEmpty(selectBodyList)) {
+                selectBodyList.forEach(this::processSelectBody);
             }
         }
     }
@@ -397,7 +390,7 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
                 processSelectBody(subSelect.getSelectBody());
             }
         } else if (fromItem instanceof ValuesList) {
-            logger.debug("Perform a subquery, if you do not give us feedback");
+            logger.debug("Perform a subQuery, if you do not give us feedback");
         } else if (fromItem instanceof LateralSubSelect) {
             LateralSubSelect lateralSubSelect = (LateralSubSelect) fromItem;
             if (lateralSubSelect.getSubSelect() != null) {
@@ -433,15 +426,14 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
      * @return List<Table> 右连接查询的 Table 列表
      */
     private List<Table> processJoins(List<Table> mainTables, List<Join> joins) {
-        if (mainTables == null) {
-            mainTables = new ArrayList<>();
-        }
-
         // join 表达式中最终的主表
         Table mainTable = null;
         // 当前 join 的左表
         Table leftTable = null;
-        if (mainTables.size() == 1) {
+
+        if (mainTables == null) {
+            mainTables = new ArrayList<>();
+        } else if (mainTables.size() == 1) {
             mainTable = mainTables.get(0);
             leftTable = mainTable;
         }
@@ -485,13 +477,19 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
                         onTables = Collections.singletonList(joinTable);
                     }
                 } else if (join.isInner()) {
-                    if (mainTable == null) {
+                    if (joinTableNeedIgnore) {
+                        if (mainTable != null) {
+                            onTables = Collections.singletonList(mainTable);
+                        }
+                    } else
+                        if (mainTable == null) {
                         onTables = Collections.singletonList(joinTable);
                     } else {
                         onTables = Arrays.asList(mainTable, joinTable);
                     }
                     mainTable = null;
                 }
+
                 mainTables = new ArrayList<>();
                 if (mainTable != null) {
                     mainTables.add(mainTable);
@@ -527,7 +525,6 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
                 processOtherFromItem(joinItem);
                 leftTable = null;
             }
-
         }
 
         return mainTables;

+ 12 - 0
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptorTest.java

@@ -5,6 +5,8 @@ import net.sf.jsqlparser.expression.Expression;
 import net.sf.jsqlparser.expression.LongValue;
 import org.junit.jupiter.api.Test;
 
+import java.util.Objects;
+
 import static org.assertj.core.api.Assertions.assertThat;
 
 /**
@@ -21,6 +23,9 @@ class TenantLineInnerInterceptorTest {
 
         @Override
         public boolean ignoreTable(String tableName) {
+            if (Objects.equals(tableName, "sys_dict")) {
+                return true;
+            }
             return tableName.startsWith("with_as");
         }
     });
@@ -397,6 +402,13 @@ class TenantLineInnerInterceptorTest {
             "WITH with_as_A AS (SELECT * FROM entity WHERE entity.tenant_id = 1) SELECT * FROM with_as_A");
     }
 
+
+    @Test
+    void selectIgnoreTable() {
+        assertSql(" SELECT dict.dict_code, item.item_text AS \"text\", item.item_value AS \"value\" FROM sys_dict_item item INNER JOIN sys_dict dict ON dict.id = item.dict_id WHERE dict.dict_code IN (1, 2, 3) AND item.item_value IN (1, 2, 3)",
+            "SELECT dict.dict_code, item.item_text AS \"text\", item.item_value AS \"value\" FROM sys_dict_item item INNER JOIN sys_dict dict ON dict.id = item.dict_id AND item.tenant_id = 1 WHERE dict.dict_code IN (1, 2, 3) AND item.item_value IN (1, 2, 3)");
+    }
+
     void assertSql(String sql, String targetSql) {
         assertThat(interceptor.parserSingle(sql, null)).isEqualTo(targetSql);
     }