yui.comn.mybatisx.extension.methods.SoftUpdateAllBatchById Maven / Gradle / Ivy
/**
* Project: yui3-common-mybatisx
* Class SoftUpdateBatchById
* Version 1.0
* File Created at 2020年3月19日
* $Id$
* author yuyi
* email [email protected]
*/
package yui.comn.mybatisx.extension.methods;
import java.util.List;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import yui.comn.mybatisx.core.enums.SoftSqlMethod;
import yui.comn.mybatisx.core.toolkit.SoftConstants;
/**
*
* 根据ID 批量修改所有值
*
*
* @author yuyi ([email protected])
*/
public class SoftUpdateAllBatchById extends AbstractSoftMethod {
private static final long serialVersionUID = -421879737030048361L;
@Override
public MappedStatement injectMappedStatement(Class> mapperClass, Class> modelClass, TableInfo tableInfo) {
/*String sql;
boolean logicDelete = tableInfo.isLogicDelete();
SoftSqlMethod sqlMethod = SoftSqlMethod.UPDATE_ALL_BATCH_BY_ID;
StringBuilder append = new StringBuilder("")
.append("")
.append(" AND ${item.").append(OptimisticLockerInterceptor.MP_OPTLOCK_VERSION_COLUMN)
.append("}=#{item.").append(OptimisticLockerInterceptor.MP_OPTLOCK_VERSION_ORIGINAL).append(StringPool.RIGHT_BRACE)
.append(" ");
if (logicDelete) {
append.append(tableInfo.getLogicDeleteSql(true, false));
}
String sqlSetScript = sqlAllSet(logicDelete, false, tableInfo, SoftConstants.ITEM, SoftConstants.ITEM_DOT);
String updateScript = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
sqlSetScript, tableInfo.getKeyColumn(),
SoftConstants.ITEM_DOT + tableInfo.getKeyProperty(), append);
sql = String.format(SoftSqlMethod.EMPTY.getSql(), SqlScriptUtils.convertForeach(updateScript,
SoftConstants.COLL, SoftConstants.INDEX, SoftConstants.ITEM, SEMICOLON));
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return addUpdateMappedStatement(mapperClass, List.class, sqlMethod.getMethod(), sqlSource);*/
SoftSqlMethod sqlMethod = SoftSqlMethod.UPDATE_ALL_BATCH_BY_ID;
final String additional = optlockVersion(tableInfo) + tableInfo.getLogicDeleteSql(true, true);
String sqlSetScript = sqlAllSet(tableInfo.isWithLogicDelete(), false, tableInfo, ENTITY, ENTITY_DOT);
String updateScript = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
sqlSetScript, tableInfo.getKeyColumn(),
SoftConstants.ITEM_DOT + tableInfo.getKeyProperty(), additional);
String sql = String.format(SoftSqlMethod.EMPTY.getSql(), SqlScriptUtils.convertForeach(updateScript,
SoftConstants.COLL, SoftConstants.INDEX, SoftConstants.ITEM, SEMICOLON));
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return addUpdateMappedStatement(mapperClass, List.class, sqlMethod.getMethod(), sqlSource);
}
}