|
@@ -17,10 +17,18 @@ package com.baomidou.mybatisplus.core.injector.methods;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
|
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
import org.apache.ibatis.mapping.SqlSource;
|
|
import org.apache.ibatis.mapping.SqlSource;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import static java.util.stream.Collectors.joining;
|
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据 ID 删除
|
|
* 根据 ID 删除
|
|
*
|
|
*
|
|
@@ -34,9 +42,20 @@ public class DeleteById extends AbstractMethod {
|
|
String sql;
|
|
String sql;
|
|
SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;
|
|
SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;
|
|
if (tableInfo.isWithLogicDelete()) {
|
|
if (tableInfo.isWithLogicDelete()) {
|
|
- sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
|
|
|
|
- tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
|
|
|
|
- tableInfo.getLogicDeleteSql(true, true));
|
|
|
|
|
|
+ List<TableFieldInfo> fieldInfos = tableInfo.getFieldList().stream()
|
|
|
|
+ .filter(TableFieldInfo::isWithUpdateFill)
|
|
|
|
+ .collect(toList());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(fieldInfos)) {
|
|
|
|
+ String sqlSet = "SET " + SqlScriptUtils.convertIf(fieldInfos.stream()
|
|
|
|
+ .map(i -> i.getSqlSet(EMPTY)).collect(joining(EMPTY)), "!@com.baomidou.mybatisplus.core.toolkit.ReflectionKit@isPrimitiveOrWrapper(_parameter.getClass())", true)
|
|
|
|
+ + tableInfo.getLogicDeleteSql(false, false);
|
|
|
|
+ sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet, tableInfo.getKeyColumn(),
|
|
|
|
+ tableInfo.getKeyProperty(), tableInfo.getLogicDeleteSql(true, true));
|
|
|
|
+ } else {
|
|
|
|
+ sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
|
|
|
|
+ tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
|
|
|
|
+ tableInfo.getLogicDeleteSql(true, true));
|
|
|
|
+ }
|
|
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
|
|
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
|
|
return addUpdateMappedStatement(mapperClass, modelClass, getMethod(sqlMethod), sqlSource);
|
|
return addUpdateMappedStatement(mapperClass, modelClass, getMethod(sqlMethod), sqlSource);
|
|
} else {
|
|
} else {
|