fix 回滚代码生成器 批处理优化(字段内容不一致, 不适合批处理)
This commit is contained in:
parent
1891dbc566
commit
3aaf4e2384
|
@ -13,6 +13,10 @@ import java.util.Collection;
|
||||||
*/
|
*/
|
||||||
public interface BaseMapperPlus<T> extends BaseMapper<T> {
|
public interface BaseMapperPlus<T> extends BaseMapper<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单sql批量插入( 全量填充 无视数据库默认值 )
|
||||||
|
* 适用于无脑插入
|
||||||
|
*/
|
||||||
int insertAll(@Param("list") Collection<T> batchList);
|
int insertAll(@Param("list") Collection<T> batchList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,8 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T> extends ServiceImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单条执行性能差
|
* 单条执行性能差 适用于列表对象内容不确定
|
||||||
*
|
|
||||||
* {@link #saveAll(Collection)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@Override
|
@Override
|
||||||
public boolean saveBatch(Collection<T> entityList, int batchSize) {
|
public boolean saveBatch(Collection<T> entityList, int batchSize) {
|
||||||
return super.saveBatch(entityList, 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
|
@Override
|
||||||
public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
|
public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
|
||||||
return super.saveOrUpdateBatch(entityList, 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);
|
return super.updateBatchById(entityList, batchSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单sql批量插入( 全量填充 无视数据库默认值 )
|
||||||
|
* 适用于无脑插入
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean saveAll(Collection<T> entityList) {
|
public boolean saveAll(Collection<T> entityList) {
|
||||||
return baseMapper.insertAll(entityList) == entityList.size();
|
return baseMapper.insertAll(entityList) == entityList.size();
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.apache.ibatis.mapping.MappedStatement;
|
||||||
import org.apache.ibatis.mapping.SqlSource;
|
import org.apache.ibatis.mapping.SqlSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单sql批量插入
|
* 单sql批量插入( 全量填充 无视数据库默认值 )
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class TestBatchController extends BaseController {
|
||||||
private final ITestDemoService iTestDemoService;
|
private final ITestDemoService iTestDemoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增批量方法
|
* 新增批量方法 ( 全量覆盖填充 )
|
||||||
*/
|
*/
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public AjaxResult<Void> add() {
|
public AjaxResult<Void> add() {
|
||||||
|
|
|
@ -179,14 +179,10 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||||
if (row > 0) {
|
if (row > 0) {
|
||||||
// 保存列信息
|
// 保存列信息
|
||||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||||
List<GenTableColumn> saveColumns = new ArrayList<>();
|
|
||||||
for (GenTableColumn column : genTableColumns) {
|
for (GenTableColumn column : genTableColumns) {
|
||||||
GenUtils.initColumnField(column, table);
|
GenUtils.initColumnField(column, table);
|
||||||
saveColumns.add(column);
|
genTableColumnMapper.insert(column);
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(saveColumns)) {
|
|
||||||
genTableColumnMapper.insertAll(saveColumns);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -290,16 +286,12 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||||
}
|
}
|
||||||
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||||
|
|
||||||
List<GenTableColumn> saveColumns = new ArrayList<>();
|
|
||||||
dbTableColumns.forEach(column -> {
|
dbTableColumns.forEach(column -> {
|
||||||
if (!tableColumnNames.contains(column.getColumnName())) {
|
if (!tableColumnNames.contains(column.getColumnName())) {
|
||||||
GenUtils.initColumnField(column, table);
|
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());
|
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(delColumns)) {
|
if (CollUtil.isNotEmpty(delColumns)) {
|
||||||
|
|
Loading…
Reference in New Issue