fix 回滚代码生成器 批处理优化(字段内容不一致, 不适合批处理)

This commit is contained in:
疯狂的狮子li 2021-07-19 14:18:38 +08:00
parent 1891dbc566
commit 3aaf4e2384
5 changed files with 14 additions and 20 deletions

View File

@ -13,6 +13,10 @@ import java.util.Collection;
*/
public interface BaseMapperPlus<T> extends BaseMapper<T> {
/**
* 单sql批量插入( 全量填充 无视数据库默认值 )
* 适用于无脑插入
*/
int insertAll(@Param("list") Collection<T> batchList);
}

View File

@ -51,11 +51,8 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T> extends ServiceImpl
}
/**
* 单条执行性能差
*
* {@link #saveAll(Collection)}
* 单条执行性能差 适用于列表对象内容不确定
*/
@Deprecated
@Override
public boolean saveBatch(Collection<T> entityList, int batchSize) {
return super.saveBatch(entityList, batchSize);
@ -67,11 +64,8 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T> extends ServiceImpl
}
/**
* 单条执行性能差
*
* {@link #saveAll(Collection)}
* 单条执行性能差 适用于列表对象内容不确定
*/
@Deprecated
@Override
public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
return super.saveOrUpdateBatch(entityList, batchSize);
@ -82,6 +76,10 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T> extends ServiceImpl
return super.updateBatchById(entityList, batchSize);
}
/**
* 单sql批量插入( 全量填充 无视数据库默认值 )
* 适用于无脑插入
*/
@Override
public boolean saveAll(Collection<T> entityList) {
return baseMapper.insertAll(entityList) == entityList.size();

View File

@ -13,7 +13,7 @@ import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
/**
* 单sql批量插入
* 单sql批量插入( 全量填充 无视数据库默认值 )
*
* @author Lion Li
*/

View File

@ -29,7 +29,7 @@ public class TestBatchController extends BaseController {
private final ITestDemoService iTestDemoService;
/**
* 新增批量方法
* 新增批量方法 ( 全量覆盖填充 )
*/
@PostMapping()
public AjaxResult<Void> add() {

View File

@ -179,13 +179,9 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
if (row > 0) {
// 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
List<GenTableColumn> saveColumns = new ArrayList<>();
for (GenTableColumn column : genTableColumns) {
GenUtils.initColumnField(column, table);
saveColumns.add(column);
}
if (CollUtil.isNotEmpty(saveColumns)) {
genTableColumnMapper.insertAll(saveColumns);
genTableColumnMapper.insert(column);
}
}
}
@ -290,16 +286,12 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
}
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
List<GenTableColumn> saveColumns = new ArrayList<>();
dbTableColumns.forEach(column -> {
if (!tableColumnNames.contains(column.getColumnName())) {
GenUtils.initColumnField(column, table);
saveColumns.add(column);
genTableColumnMapper.insert(column);
}
});
if (CollUtil.isNotEmpty(saveColumns)) {
genTableColumnMapper.insertAll(saveColumns);
}
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(delColumns)) {