package com.baomidou.mybatisplus.extension.injector.methods;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.AbstractLogicMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * <p>
 * 根据 id 逻辑删除数据,并带字段填充功能
 * 注意入参是 entity !!! , 非逻辑删除勿用 !!!
 * </p>
 *
 * @author miemie
 * @since 2018-09-13
 */
public class LogicDeleteByIdWithFill extends AbstractLogicMethod {
    /**
     * mapper 对应的方法名
     */
    private static final String MAPPER_METHOD = "logicDeleteByIdWithFill";

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sqlMethod = "<script>\nUPDATE %s %s WHERE %s=#{%s} %s\n</script>";
        // todo 没写完
        String sql = String.format(sqlMethod, tableInfo.getTableName(), sqlLogicSet(tableInfo),
            tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
            tableInfo.getLogicDeleteSql(true, false));
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addUpdateMappedStatement(mapperClass, modelClass, MAPPER_METHOD, sqlSource);
    }
}

@@ -55,16 +55,124 @@
 thods;%0A%0A
+import com.baomidou.mybatisplus.annotation.FieldFill;%0Aimport com.baomidou.mybatisplus.core.enums.SqlMethod;%0A
 import c
@@ -218,14 +218,195 @@
 able
+Field
 Info;%0A
+import com.baomidou.mybatisplus.core.metadata.TableInfo;%0Aimport com.baomidou.mybatisplus.core.toolkit.CollectionUtils;%0Aimport com.baomidou.mybatisplus.core.toolkit.StringPool;%0A
 impo
@@ -568,16 +568,142 @@
 ource;%0A%0A
+import java.util.List;%0A%0Aimport static java.util.stream.Collectors.joining;%0Aimport static java.util.stream.Collectors.toList;%0A%0A
 /**%0A * %3C
@@ -755,20 +755,29 @@
 !! ,
- %E9%9D%9E%E9%80%BB%E8%BE%91%E5%88%A0%E9%99%A4%E5%8B%BF%E7%94%A8 !!!
+%E5%A6%82%E6%9E%9C%E5%AD%97%E6%AE%B5%E6%B2%A1%E6%9C%89%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85,%E5%B0%B1%E5%8F%AA%E6%98%AF%E5%8D%95%E7%BA%AF%E7%9A%84%E9%80%BB%E8%BE%91%E5%88%A0%E9%99%A4
 %0A * 
@@ -1158,106 +1158,820 @@
  sql
-Method = %22%3Cscript%3E%5CnUPDATE %25s %25s WHERE %25s=#%7B%25s%7D %25s%5Cn%3C/script%3E%22;%0A        // todo %E6%B2%A1%E5%86%99%E5%AE%8C%0A        String
+;%0A        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;%0A        if (tableInfo.isLogicDelete()) %7B%0A            List%3CTableFieldInfo%3E fieldInfos = tableInfo.getFieldList().stream()%0A                .filter(i -%3E i.getFieldFill() == FieldFill.UPDATE %7C%7C i.getFieldFill() == FieldFill.INSERT_UPDATE)%0A                .collect(toList());%0A            if (CollectionUtils.isNotEmpty(fieldInfos)) %7B%0A                String sqlSet = %22SET %22 + fieldInfos.stream().map(i -%3E i.getSqlSet(StringPool.EMPTY))%0A                    .collect(joining(StringPool.COMMA));%0A                sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet,%0A                    tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),%0A                    tableInfo.getLogicDeleteSql(true, false));%0A            %7D else %7B%0A               
  sql
@@ -1996,16 +1996,25 @@
 qlMethod
+.getSql()
 , tableI
@@ -2061,32 +2061,40 @@
 o),%0A            
+        
 tableInfo.getKey
@@ -2135,32 +2135,40 @@
 (),%0A            
+        
 tableInfo.getLog
@@ -2186,32 +2186,270 @@
 (true, false));%0A
+            %7D%0A        %7D else %7B%0A            sqlMethod = SqlMethod.DELETE_BY_ID;%0A            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),%0A                tableInfo.getKeyProperty());%0A        %7D%0A
         SqlSourc

提供功能,搞定