Commit e1f5d54c authored by liaozan's avatar liaozan 🏀

Fix AlwaysUpdateSomeColumnById

parent 7d30e603
...@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.core.injector.methods.*; ...@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById; import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.schbrain.framework.autoconfigure.mybatis.constant.MybatisConstants;
import com.schbrain.framework.autoconfigure.mybatis.sql.method.Delete; import com.schbrain.framework.autoconfigure.mybatis.sql.method.Delete;
import com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteBatchByIds; import com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteBatchByIds;
import com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteById;
import com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteByMap; import com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteByMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.List; import java.util.List;
import java.util.Set;
import static com.schbrain.framework.autoconfigure.mybatis.constant.MybatisConstants.*;
/** /**
* @author liaozan * @author liaozan
...@@ -22,13 +25,10 @@ import java.util.List; ...@@ -22,13 +25,10 @@ import java.util.List;
public class DefaultMethodSqlInjector extends AbstractSqlInjector { public class DefaultMethodSqlInjector extends AbstractSqlInjector {
/** /**
* <ul> * 更新时忽略的字段
* <li>replace {@link com.baomidou.mybatisplus.core.injector.methods.Delete} to {@link Delete}</li>
* <li>replace {@link com.baomidou.mybatisplus.core.injector.methods.DeleteById} to {@link com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteById}</li>
* <li>replace {@link com.baomidou.mybatisplus.core.injector.methods.DeleteByMap} to {@link DeleteByMap}</li>
* <li>replace {@link com.baomidou.mybatisplus.core.injector.methods.DeleteBatchByIds} to {@link DeleteBatchByIds}</li>
* </ul>
*/ */
private static final Set<String> FIELDS_TO_IGNORE_WHEN_UPDATE = Set.of(CREATE_TIME, MODIFY_TIME, DELETE_VERSION);
@Override @Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
List<AbstractMethod> methodList = Lists.newArrayListWithExpectedSize(20); List<AbstractMethod> methodList = Lists.newArrayListWithExpectedSize(20);
...@@ -44,16 +44,16 @@ public class DefaultMethodSqlInjector extends AbstractSqlInjector { ...@@ -44,16 +44,16 @@ public class DefaultMethodSqlInjector extends AbstractSqlInjector {
methodList.add(new SelectList()); methodList.add(new SelectList());
methodList.add(new SelectPage()); methodList.add(new SelectPage());
if (tableInfo.havePK()) { if (tableInfo.havePK()) {
methodList.add(new com.schbrain.framework.autoconfigure.mybatis.sql.method.DeleteById()); methodList.add(new DeleteById());
methodList.add(new DeleteBatchByIds()); methodList.add(new DeleteBatchByIds());
methodList.add(new UpdateById()); methodList.add(new UpdateById());
methodList.add(new AlwaysUpdateSomeColumnById(field -> !field.getColumn().equals(MybatisConstants.DELETE_VERSION))); methodList.add(new AlwaysUpdateSomeColumnById(field -> !FIELDS_TO_IGNORE_WHEN_UPDATE.contains(field.getColumn())));
methodList.add(new SelectById()); methodList.add(new SelectById());
methodList.add(new SelectBatchByIds()); methodList.add(new SelectBatchByIds());
} else { } else {
log.warn("{} ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.", tableInfo.getEntityType()); log.warn("{} Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.", tableInfo.getEntityType());
} }
return methodList; return methodList;
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment