Explorar el Código

调整依赖改为jdk8 支持

hubin hace 7 años
padre
commit
db2e5d1a76

+ 26 - 20
build.gradle

@@ -49,7 +49,6 @@ allprojects {
     version = '3.0.1-SNAPSHOT'
 }
 
-
 description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
 
 buildscript {
@@ -63,6 +62,7 @@ buildscript {
 
 configure(subprojects) {
     apply plugin: 'propdeps'
+    apply plugin: 'propdeps-maven'
     apply plugin: 'propdeps-idea'
     apply plugin: 'propdeps-eclipse'
 }
@@ -71,7 +71,6 @@ subprojects {
 
     apply plugin: 'java'
     apply plugin: 'signing'
-    apply plugin: 'maven-deploy'
 
     sourceCompatibility = "${javaVersion}"
     targetCompatibility = "${javaVersion}"
@@ -115,29 +114,36 @@ subprojects {
         archives javadocJar
     }
 
+    tasks.whenTaskAdded { task ->
+        if (task.name.contains('uploadArchives') || task.name.contains("signArchives")) {
+            task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
+        }
+    }
+
+    signing {
+        sign configurations.archives
+    }
+
     // gradle clean build uploadArchives -Dun=用户名 -Dps=密码 -x test
     uploadArchives {
         repositories {
             mavenDeployer {
-                def isLocal = Boolean.valueOf(project.properties.get("local"))
-                if(isLocal){
-                    repository(url: uri('../repo'))
-                }else {
-                    signing {
-                        sign configurations.archives
-                    }
-                    beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
-                    def userName = System.getProperty("un")
-                    def passWord = System.getProperty("ps")
-                    pom.version = "$project.version"
-                    pom.artifactId = "$project.name"
-                    pom.groupId = "$project.group"
-                    repository(url: pom.version.endsWith('SNAPSHOT') ? 'https://oss.sonatype.org/content/repositories/snapshots/'
-                        :'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
-                        //noinspection GroovyAssignabilityCheck
-                        authentication(userName: userName, password: passWord)
-                    }
+                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
+                def userName = System.getProperty("un")
+                def passWord = System.getProperty("ps")
+                repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
+                    //noinspection GroovyAssignabilityCheck
+                    authentication(userName: userName, password: passWord)
+                }
+
+                snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
+                    //noinspection GroovyAssignabilityCheck
+                    authentication(userName: userName, password: passWord)
                 }
+
+                pom.version = "$project.version"
+                pom.artifactId = "$project.name"
+                pom.groupId = "$project.group"
                 pom.project {
                     //noinspection GroovyAssignabilityCheck
                     name 'mybatis-plus'

+ 0 - 14
buildSrc/build.gradle

@@ -1,14 +0,0 @@
-apply plugin: "groovy"
-
-/*
-    https://github.com/gradle/gradle/issues/867
-    https://github.com/spring-gradle-plugins/propdeps-plugin/commit/bd14013e6f0adba7908778349bb0a08b50212658
- */
-
-uploadArchives.enabled = false
-
-dependencies {
-    compile gradleApi()
-    compile localGroovy()
-}
-

+ 0 - 41
buildSrc/src/main/groovy/com/baomidou/gradle/MavenDeployPlugin.groovy

@@ -1,41 +0,0 @@
-package com.baomidou.gradle
-
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer
-import org.gradle.api.artifacts.maven.MavenPom
-import org.gradle.api.artifacts.maven.PomFilterContainer
-import org.gradle.api.plugins.MavenPlugin
-import org.gradle.api.tasks.Upload
-
-class MavenDeployPlugin implements Plugin<Project> {
-
-    @Override
-    void apply(Project project) {
-        project.plugins.apply(MavenPlugin)
-        Conf2ScopeMappingContainer scopeMappings = project.conf2ScopeMappings
-        scopeMappings.addMapping(MavenPlugin.COMPILE_PRIORITY + 1,
-            project.configurations.getByName("provided"), Conf2ScopeMappingContainer.PROVIDED)
-        // Add a temporary new optional scope
-        scopeMappings.addMapping(org.gradle.api.plugins.MavenPlugin.COMPILE_PRIORITY + 2,
-            project.configurations.getByName("optional"), "optional")
-        // Add a hook to replace the optional scope
-        project.afterEvaluate {
-            project.tasks.withType(Upload).each { applyToUploadTask(project, it) }
-        }
-    }
-
-    private void applyToUploadTask(Project project, Upload upload) {
-        upload.repositories.withType(PomFilterContainer).each{ applyToPom(project, it) }
-    }
-
-    private void applyToPom(Project project, PomFilterContainer pomContainer) {
-        pomContainer.pom.whenConfigured { MavenPom pom ->
-            pom.dependencies.findAll{ it.scope == "optional" }.each {
-                it.scope = "compile"
-                it.optional = true
-            }
-        }
-    }
-
-}

+ 0 - 1
buildSrc/src/main/resources/META-INF/gradle-plugins/maven-deploy.properties

@@ -1 +0,0 @@
-implementation-class=com.baomidou.gradle.MavenDeployPlugin

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AutoSqlInjector.java

@@ -66,7 +66,7 @@ public class AutoSqlInjector implements ISqlInjector {
      * @param builderAssistant
      * @param mapperClass
      */
-    @Override
+//    @Override
     public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) {
         String className = mapperClass.toString();
         Set<String> mapperRegistryCache = GlobalConfigUtils.getMapperRegistryCache(builderAssistant.getConfiguration());

+ 9 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/ISqlInjector.java

@@ -30,15 +30,15 @@ import com.baomidou.mybatisplus.core.assist.ISqlRunner;
  */
 public interface ISqlInjector {
 
-    /**
-     * <p>
-     * 根据 mapperClass 注入SQL
-     * </p>
-     *
-     * @param builderAssistant
-     * @param mapperClass
-     */
-    void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass);
+//    /**
+//     * <p>
+//     * 根据 mapperClass 注入SQL
+//     * </p>
+//     *
+//     * @param builderAssistant
+//     * @param mapperClass
+//     */
+//    void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass);
 
     /**
      * <p>

+ 279 - 277
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/LogicSqlInjector.java

@@ -15,17 +15,19 @@
  */
 package com.baomidou.mybatisplus.extension.injector;
 
-import java.util.List;
-import java.util.Map;
+//import java.util.List;
+//import java.util.Map;
+//
+//import org.apache.ibatis.mapping.SqlSource;
+//import org.apache.ibatis.scripting.defaults.RawSqlSource;
+//
+//import com.baomidou.mybatisplus.core.enums.SqlMethod;
+//import com.baomidou.mybatisplus.core.injector.AutoSqlInjector;
+//import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
+//import com.baomidou.mybatisplus.core.metadata.TableInfo;
+//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 
-import org.apache.ibatis.mapping.SqlSource;
-import org.apache.ibatis.scripting.defaults.RawSqlSource;
-
-import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.core.injector.AutoSqlInjector;
-import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
-import com.baomidou.mybatisplus.core.metadata.TableInfo;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 
 /**
  * <p>
@@ -37,272 +39,272 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  * @Date 2017-09-09
  */
 public class LogicSqlInjector extends AutoSqlInjector {
-
-    /**
-     * 根据 ID 删除
-     */
-    @Override
-    protected void injectDeleteByIdSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-        if (table.isLogicDelete()) {
-            // 逻辑删除注入
-            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;
-            SqlSource sqlSource;
-            String idStr = table.getKeyProperty();
-            if (batch) {
-                sqlMethod = SqlMethod.LOGIC_DELETE_BATCH_BY_IDS;
-                StringBuilder ids = new StringBuilder();
-                ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"coll\" separator=\",\">");
-                ids.append("#{item}");
-                ids.append("\n</foreach>");
-                idStr = ids.toString();
-            }
-            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
-                table.getKeyColumn(), idStr);
-            sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
-        } else {
-            // 正常删除
-            super.injectDeleteByIdSql(batch, mapperClass, modelClass, table);
-        }
-    }
-
-    /**
-     * 根据 SQL 删除
-     */
-    @Override
-    protected void injectDeleteSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-        if (table.isLogicDelete()) {
-            // 逻辑删除注入
-            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE;
-            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
-                sqlWhereEntityWrapper(table));
-            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
-        } else {
-            // 正常删除
-            super.injectDeleteSql(mapperClass, modelClass, table);
-        }
-    }
-
-    /**
-     * 根据 MAP 删除
-     */
-    @Override
-    protected void injectDeleteByMapSql(Class<?> mapperClass, TableInfo table) {
-        if (table.isLogicDelete()) {
-            // 逻辑删除注入
-            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_MAP;
-            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
-                sqlWhereByMap(table));
-            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
-            this.addUpdateMappedStatement(mapperClass, Map.class, sqlMethod.getMethod(), sqlSource);
-        } else {
-            // 正常删除
-            super.injectDeleteByMapSql(mapperClass, table);
-        }
-    }
-
-    /**
-     * <p>
-     * 注入查询 SQL 语句
-     * </p>
-     *
-     * @param batch       是否为批量插入
-     * @param mapperClass
-     * @param modelClass
-     * @param table
-     */
-    @Override
-    protected void injectSelectByIdSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-        if (table.isLogicDelete()) {
-            SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BY_ID;
-            SqlSource sqlSource;
-            if (batch) {
-                sqlMethod = SqlMethod.LOGIC_SELECT_BATCH_BY_IDS;
-                StringBuilder ids = new StringBuilder();
-                ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"coll\" separator=\",\">");
-                ids.append("#{item}");
-                ids.append("\n</foreach>");
-                sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(), sqlSelectColumns(table, false),
-                    table.getTableName(), table.getKeyColumn(), ids.toString(), getLogicDeleteSql(table)), modelClass);
-            } else {
-                sqlSource = new RawSqlSource(configuration, String.format(sqlMethod.getSql(), sqlSelectColumns(table, false), table.getTableName(),
-                    table.getKeyColumn(), table.getKeyProperty(), getLogicDeleteSql(table)), Object.class);
-            }
-            this.addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, table);
-        } else {
-            // 正常查询
-            super.injectSelectByIdSql(batch, mapperClass, modelClass, table);
-        }
-    }
-
-    /**
-     * <p>
-     * 注入更新 SQL 语句
-     * </p>
-     *
-     * @param mapperClass
-     * @param modelClass
-     * @param table
-     */
-    @Override
-    protected void injectUpdateByIdSql(boolean selective, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-        if (table.isLogicDelete()) {
-            SqlMethod sqlMethod = selective ? SqlMethod.LOGIC_UPDATE_BY_ID : SqlMethod.LOGIC_UPDATE_ALL_COLUMN_BY_ID;
-            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(selective, table, "et."),
-                table.getKeyColumn(),
-                "et." + table.getKeyProperty(),
-                "<if test=\"et instanceof java.util.Map\">" +
-                    "<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">"
-                    + "and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}"
-                    + "</if>"
-                    + "</if>" +
-                    getLogicDeleteSql(table)
-            );
-            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
-        } else {
-            super.injectUpdateByIdSql(selective, mapperClass, modelClass, table);
-        }
-    }
-
-    /**
-     * <p>
-     * SQL 更新 set 语句
-     * </p>
-     *
-     * @param table 表信息
-     * @return sql and 片段
-     */
-    public String getLogicDeleteSql(TableInfo table) {
-        StringBuilder sql = new StringBuilder();
-        List<TableFieldInfo> fieldList = table.getFieldList();
-        for (TableFieldInfo fieldInfo : fieldList) {
-            if (fieldInfo.isLogicDelete()) {
-                sql.append(" AND ").append(fieldInfo.getColumn());
-                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
-                    sql.append("='").append(fieldInfo.getLogicNotDeleteValue()).append("'");
-                } else {
-                    sql.append("=").append(fieldInfo.getLogicNotDeleteValue());
-                }
-            }
-        }
-        return sql.toString();
-    }
-
-    /**
-     * <p>
-     * SQL 更新 set 语句
-     * </p>
-     *
-     * @param table 表信息
-     * @return sql set 片段
-     */
-    protected String sqlLogicSet(TableInfo table) {
-        List<TableFieldInfo> fieldList = table.getFieldList();
-        StringBuilder set = new StringBuilder("SET ");
-        int i = 0;
-        for (TableFieldInfo fieldInfo : fieldList) {
-            if (fieldInfo.isLogicDelete()) {
-                if (++i > 1) {
-                    set.append(",");
-                }
-                set.append(fieldInfo.getColumn()).append("=");
-                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
-                    set.append("'").append(fieldInfo.getLogicDeleteValue()).append("'");
-                } else {
-                    set.append(fieldInfo.getLogicDeleteValue());
-                }
-            }
-        }
-        return set.toString();
-    }
-
-    // ------------ 处理逻辑删除条件过滤 ------------
-
-    @Override
-    protected String sqlWhere(TableInfo table) {
-        if (table.isLogicDelete()) {
-            StringBuilder where = new StringBuilder("\n<where>");
-            // 过滤逻辑
-            List<TableFieldInfo> fieldList = table.getFieldList();
-            // EW 逻辑
-            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
-                where.append("\n<if test=\"ew.").append(table.getKeyProperty()).append("!=null\">");
-                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.");
-                where.append(table.getKeyProperty()).append("}");
-                where.append("</if>");
-            }
-            for (TableFieldInfo fieldInfo : fieldList) {
-                where.append(convertIfTag(fieldInfo, "ew.", false));
-                where.append(" AND ").append(this.sqlCondition(fieldInfo.getCondition(),
-                    fieldInfo.getColumn(), "ew." + fieldInfo.getEl()));
-                where.append(convertIfTag(fieldInfo, true));
-            }
-            // 过滤逻辑
-            where.append("\n").append(getLogicDeleteSql(table));
-            where.append("\n</where>");
-            return where.toString();
-        }
-        // 正常逻辑
-        return super.sqlWhere(table);
-    }
-
-    @Override
-    protected String sqlWhereEntityWrapper(TableInfo table) {
-        if (table.isLogicDelete()) {
-            StringBuilder where = new StringBuilder(128);
-            where.append("\n<where>");
-            where.append("\n<choose><when test=\"ew!=null\">");
-            where.append("\n<if test=\"ew.entity!=null\">");
-            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
-                where.append("\n<if test=\"ew.entity.").append(table.getKeyProperty()).append("!=null\">");
-                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.entity.");
-                where.append(table.getKeyProperty()).append("}");
-                where.append("</if>");
-            }
-            List<TableFieldInfo> fieldList = table.getFieldList();
-            for (TableFieldInfo fieldInfo : fieldList) {
-                where.append(convertIfTag(fieldInfo, "ew.entity.", false));
-                where.append(" AND ").append(this.sqlCondition(fieldInfo.getCondition(),
-                    fieldInfo.getColumn(), "ew.entity." + fieldInfo.getEl()));
-                where.append(convertIfTag(fieldInfo, true));
-            }
-            where.append("\n</if>");
-            where.append("\n").append(getLogicDeleteSql(table));
-            where.append("\n<if test=\"ew.sqlSegment!=null\">${ew.sqlSegment}\n</if>");
-            where.append("\n</when><otherwise>");
-            where.append("\n").append(getLogicDeleteSql(table));
-            where.append("\n</otherwise></choose>");
-            where.append("\n</where>");
-            return where.toString();
-        }
-        // 正常逻辑
-        return super.sqlWhereEntityWrapper(table);
-    }
-
-    @Override
-    protected String sqlWhereByMap(TableInfo table) {
-        if (table.isLogicDelete()) {
-            StringBuilder where = new StringBuilder();
-            where.append("\n<where>");
-            // MAP 逻辑
-            where.append("\n<if test=\"cm!=null and !cm.isEmpty\">");
-            where.append("\n<foreach collection=\"cm.keys\" item=\"k\" separator=\"AND\">");
-            where.append("\n<if test=\"cm[k] != null\">");
-//            where.append(SqlReservedWords.convert(getGlobalConfig(), "\n${k}")).append(" = #{cm[${k}]}");
-            //TODO: 3.0
-            where.append(getGlobalConfig().getReservedWordsHandler().convert(getGlobalConfig(), "\n${k}")).append(" = #{cm[${k}]}");
-            where.append("</if>");
-            where.append("\n</foreach>");
-            where.append("\n</if>");
-            // 过滤逻辑
-            where.append("\n").append(getLogicDeleteSql(table));
-            where.append("\n</where>");
-            return where.toString();
-        }
-        // 正常逻辑
-        return super.sqlWhereByMap(table);
-    }
-
+//
+//    /**
+//     * 根据 ID 删除
+//     */
+//    @Override
+//    protected void injectDeleteByIdSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            // 逻辑删除注入
+//            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;
+//            SqlSource sqlSource;
+//            String idStr = table.getKeyProperty();
+//            if (batch) {
+//                sqlMethod = SqlMethod.LOGIC_DELETE_BATCH_BY_IDS;
+//                StringBuilder ids = new StringBuilder();
+//                ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"coll\" separator=\",\">");
+//                ids.append("#{item}");
+//                ids.append("\n</foreach>");
+//                idStr = ids.toString();
+//            }
+//            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
+//                table.getKeyColumn(), idStr);
+//            sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+//            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+//        } else {
+//            // 正常删除
+//            super.injectDeleteByIdSql(batch, mapperClass, modelClass, table);
+//        }
+//    }
+//
+//    /**
+//     * 根据 SQL 删除
+//     */
+//    @Override
+//    protected void injectDeleteSql(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            // 逻辑删除注入
+//            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE;
+//            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
+//                sqlWhereEntityWrapper(table));
+//            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+//            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+//        } else {
+//            // 正常删除
+//            super.injectDeleteSql(mapperClass, modelClass, table);
+//        }
+//    }
+//
+//    /**
+//     * 根据 MAP 删除
+//     */
+//    @Override
+//    protected void injectDeleteByMapSql(Class<?> mapperClass, TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            // 逻辑删除注入
+//            SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_MAP;
+//            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlLogicSet(table),
+//                sqlWhereByMap(table));
+//            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
+//            this.addUpdateMappedStatement(mapperClass, Map.class, sqlMethod.getMethod(), sqlSource);
+//        } else {
+//            // 正常删除
+//            super.injectDeleteByMapSql(mapperClass, table);
+//        }
+//    }
+//
+//    /**
+//     * <p>
+//     * 注入查询 SQL 语句
+//     * </p>
+//     *
+//     * @param batch       是否为批量插入
+//     * @param mapperClass
+//     * @param modelClass
+//     * @param table
+//     */
+//    @Override
+//    protected void injectSelectByIdSql(boolean batch, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BY_ID;
+//            SqlSource sqlSource;
+//            if (batch) {
+//                sqlMethod = SqlMethod.LOGIC_SELECT_BATCH_BY_IDS;
+//                StringBuilder ids = new StringBuilder();
+//                ids.append("\n<foreach item=\"item\" index=\"index\" collection=\"coll\" separator=\",\">");
+//                ids.append("#{item}");
+//                ids.append("\n</foreach>");
+//                sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(), sqlSelectColumns(table, false),
+//                    table.getTableName(), table.getKeyColumn(), ids.toString(), getLogicDeleteSql(table)), modelClass);
+//            } else {
+//                sqlSource = new RawSqlSource(configuration, String.format(sqlMethod.getSql(), sqlSelectColumns(table, false), table.getTableName(),
+//                    table.getKeyColumn(), table.getKeyProperty(), getLogicDeleteSql(table)), Object.class);
+//            }
+//            this.addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, table);
+//        } else {
+//            // 正常查询
+//            super.injectSelectByIdSql(batch, mapperClass, modelClass, table);
+//        }
+//    }
+//
+//    /**
+//     * <p>
+//     * 注入更新 SQL 语句
+//     * </p>
+//     *
+//     * @param mapperClass
+//     * @param modelClass
+//     * @param table
+//     */
+//    @Override
+//    protected void injectUpdateByIdSql(boolean selective, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            SqlMethod sqlMethod = selective ? SqlMethod.LOGIC_UPDATE_BY_ID : SqlMethod.LOGIC_UPDATE_ALL_COLUMN_BY_ID;
+//            String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlSet(selective, table, "et."),
+//                table.getKeyColumn(),
+//                "et." + table.getKeyProperty(),
+//                "<if test=\"et instanceof java.util.Map\">" +
+//                    "<if test=\"et.MP_OPTLOCK_VERSION_ORIGINAL!=null\">"
+//                    + "and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}"
+//                    + "</if>"
+//                    + "</if>" +
+//                    getLogicDeleteSql(table)
+//            );
+//            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+//            this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+//        } else {
+//            super.injectUpdateByIdSql(selective, mapperClass, modelClass, table);
+//        }
+//    }
+//
+//    /**
+//     * <p>
+//     * SQL 更新 set 语句
+//     * </p>
+//     *
+//     * @param table 表信息
+//     * @return sql and 片段
+//     */
+//    public String getLogicDeleteSql(TableInfo table) {
+//        StringBuilder sql = new StringBuilder();
+//        List<TableFieldInfo> fieldList = table.getFieldList();
+//        for (TableFieldInfo fieldInfo : fieldList) {
+//            if (fieldInfo.isLogicDelete()) {
+//                sql.append(" AND ").append(fieldInfo.getColumn());
+//                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
+//                    sql.append("='").append(fieldInfo.getLogicNotDeleteValue()).append("'");
+//                } else {
+//                    sql.append("=").append(fieldInfo.getLogicNotDeleteValue());
+//                }
+//            }
+//        }
+//        return sql.toString();
+//    }
+//
+//    /**
+//     * <p>
+//     * SQL 更新 set 语句
+//     * </p>
+//     *
+//     * @param table 表信息
+//     * @return sql set 片段
+//     */
+//    protected String sqlLogicSet(TableInfo table) {
+//        List<TableFieldInfo> fieldList = table.getFieldList();
+//        StringBuilder set = new StringBuilder("SET ");
+//        int i = 0;
+//        for (TableFieldInfo fieldInfo : fieldList) {
+//            if (fieldInfo.isLogicDelete()) {
+//                if (++i > 1) {
+//                    set.append(",");
+//                }
+//                set.append(fieldInfo.getColumn()).append("=");
+//                if (StringUtils.isCharSequence(fieldInfo.getPropertyType())) {
+//                    set.append("'").append(fieldInfo.getLogicDeleteValue()).append("'");
+//                } else {
+//                    set.append(fieldInfo.getLogicDeleteValue());
+//                }
+//            }
+//        }
+//        return set.toString();
+//    }
+//
+//    // ------------ 处理逻辑删除条件过滤 ------------
+//
+//    @Override
+//    protected String sqlWhere(TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            StringBuilder where = new StringBuilder("\n<where>");
+//            // 过滤逻辑
+//            List<TableFieldInfo> fieldList = table.getFieldList();
+//            // EW 逻辑
+//            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
+//                where.append("\n<if test=\"ew.").append(table.getKeyProperty()).append("!=null\">");
+//                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.");
+//                where.append(table.getKeyProperty()).append("}");
+//                where.append("</if>");
+//            }
+//            for (TableFieldInfo fieldInfo : fieldList) {
+//                where.append(convertIfTag(fieldInfo, "ew.", false));
+//                where.append(" AND ").append(this.sqlCondition(fieldInfo.getCondition(),
+//                    fieldInfo.getColumn(), "ew." + fieldInfo.getEl()));
+//                where.append(convertIfTag(fieldInfo, true));
+//            }
+//            // 过滤逻辑
+//            where.append("\n").append(getLogicDeleteSql(table));
+//            where.append("\n</where>");
+//            return where.toString();
+//        }
+//        // 正常逻辑
+//        return super.sqlWhere(table);
+//    }
+//
+//    @Override
+//    protected String sqlWhereEntityWrapper(TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            StringBuilder where = new StringBuilder(128);
+//            where.append("\n<where>");
+//            where.append("\n<choose><when test=\"ew!=null\">");
+//            where.append("\n<if test=\"ew.entity!=null\">");
+//            if (StringUtils.isNotEmpty(table.getKeyProperty())) {
+//                where.append("\n<if test=\"ew.entity.").append(table.getKeyProperty()).append("!=null\">");
+//                where.append(" AND ").append(table.getKeyColumn()).append("=#{ew.entity.");
+//                where.append(table.getKeyProperty()).append("}");
+//                where.append("</if>");
+//            }
+//            List<TableFieldInfo> fieldList = table.getFieldList();
+//            for (TableFieldInfo fieldInfo : fieldList) {
+//                where.append(convertIfTag(fieldInfo, "ew.entity.", false));
+//                where.append(" AND ").append(this.sqlCondition(fieldInfo.getCondition(),
+//                    fieldInfo.getColumn(), "ew.entity." + fieldInfo.getEl()));
+//                where.append(convertIfTag(fieldInfo, true));
+//            }
+//            where.append("\n</if>");
+//            where.append("\n").append(getLogicDeleteSql(table));
+//            where.append("\n<if test=\"ew.sqlSegment!=null\">${ew.sqlSegment}\n</if>");
+//            where.append("\n</when><otherwise>");
+//            where.append("\n").append(getLogicDeleteSql(table));
+//            where.append("\n</otherwise></choose>");
+//            where.append("\n</where>");
+//            return where.toString();
+//        }
+//        // 正常逻辑
+//        return super.sqlWhereEntityWrapper(table);
+//    }
+//
+//    @Override
+//    protected String sqlWhereByMap(TableInfo table) {
+//        if (table.isLogicDelete()) {
+//            StringBuilder where = new StringBuilder();
+//            where.append("\n<where>");
+//            // MAP 逻辑
+//            where.append("\n<if test=\"cm!=null and !cm.isEmpty\">");
+//            where.append("\n<foreach collection=\"cm.keys\" item=\"k\" separator=\"AND\">");
+//            where.append("\n<if test=\"cm[k] != null\">");
+////            where.append(SqlReservedWords.convert(getGlobalConfig(), "\n${k}")).append(" = #{cm[${k}]}");
+//            //TODO: 3.0
+//            where.append(getGlobalConfig().getReservedWordsHandler().convert(getGlobalConfig(), "\n${k}")).append(" = #{cm[${k}]}");
+//            where.append("</if>");
+//            where.append("\n</foreach>");
+//            where.append("\n</if>");
+//            // 过滤逻辑
+//            where.append("\n").append(getLogicDeleteSql(table));
+//            where.append("\n</where>");
+//            return where.toString();
+//        }
+//        // 正常逻辑
+//        return super.sqlWhereByMap(table);
+//    }
+//
 }

+ 32 - 32
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/test/mysql/MySqlInjector.java

@@ -33,36 +33,36 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
  */
 public class MySqlInjector extends AutoSqlInjector {
 
-    @Override
-    public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
-                       Class<?> modelClass, TableInfo table) {
-        /* 添加一个自定义方法 */
-        deleteAllUser(mapperClass, modelClass, table);
-        // 测试 com.baomidou.mybatisplus.extension.test.mysql.MetaObjectHandlerTest
-        deleteLogicById(mapperClass, modelClass, table);
-    }
-
-    public void deleteAllUser(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-
-        /* 执行 SQL ,动态 SQL 参考类 SqlMethod */
-        String sql = "delete from " + table.getTableName();
-
-        /* mapper 接口方法名一致 */
-        String method = "deleteAll";
-        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-        this.addDeleteMappedStatement(mapperClass, method, sqlSource);
-    }
-
-    public void deleteLogicById(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-
-        /* 执行 SQL ,动态 SQL 参考类 SqlMethod */
-        String sql = String.format("UPDATE %s SET test_type=-1 WHERE test_id=#{id}", table.getTableName());
-
-        /* mapper 接口方法名一致 */
-        String method = "deleteLogicById";
-        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
-
-        // 注意!! 这里是更新、删除、插入、调用方法注入不一样!!
-        this.addUpdateMappedStatement(mapperClass, modelClass, method, sqlSource);
-    }
+//    @Override
+//    public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
+//                       Class<?> modelClass, TableInfo table) {
+//        /* 添加一个自定义方法 */
+//        deleteAllUser(mapperClass, modelClass, table);
+//        // 测试 com.baomidou.mybatisplus.extension.test.mysql.MetaObjectHandlerTest
+//        deleteLogicById(mapperClass, modelClass, table);
+//    }
+//
+//    public void deleteAllUser(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//
+//        /* 执行 SQL ,动态 SQL 参考类 SqlMethod */
+//        String sql = "delete from " + table.getTableName();
+//
+//        /* mapper 接口方法名一致 */
+//        String method = "deleteAll";
+//        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+//        this.addDeleteMappedStatement(mapperClass, method, sqlSource);
+//    }
+//
+//    public void deleteLogicById(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
+//
+//        /* 执行 SQL ,动态 SQL 参考类 SqlMethod */
+//        String sql = String.format("UPDATE %s SET test_type=-1 WHERE test_id=#{id}", table.getTableName());
+//
+//        /* mapper 接口方法名一致 */
+//        String method = "deleteLogicById";
+//        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+//
+//        // 注意!! 这里是更新、删除、插入、调用方法注入不一样!!
+//        this.addUpdateMappedStatement(mapperClass, modelClass, method, sqlSource);
+//    }
 }

+ 0 - 1
settings.gradle

@@ -4,6 +4,5 @@ include 'mybatis-plus-core'
 include 'mybatis-plus-annotation'
 include 'mybatis-plus-extension'
 include 'mybatis-plus-generator'
-include 'buildSrc'