|
|
@ -18,10 +18,7 @@ import org.apache.ibatis.logging.Log;
|
|
|
|
import org.apache.ibatis.logging.LogFactory;
|
|
|
|
import org.apache.ibatis.logging.LogFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 自定义 Mapper 接口, 实现 自定义扩展
|
|
|
|
* 自定义 Mapper 接口, 实现 自定义扩展
|
|
|
@ -242,8 +239,39 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
|
|
|
* @param entityList 实体类列表
|
|
|
|
* @param entityList 实体类列表
|
|
|
|
* @return 影响条数
|
|
|
|
* @return 影响条数
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
default boolean insertIgnoreBatchs(List<T> entityList) {
|
|
|
|
|
|
|
|
return insertIgnoreBatchs(entityList, DEFAULT_BATCH_SIZE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default boolean insertIgnoreBatchs(List<T> entityList, int batchSize) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
int size = entityList.size();
|
|
|
|
|
|
|
|
int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size);
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
//保存单批提交的数据集合
|
|
|
|
|
|
|
|
List<T> oneBatchList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Iterator<T> var7 = entityList.iterator(); var7.hasNext(); ++i) {
|
|
|
|
|
|
|
|
T element = var7.next();
|
|
|
|
|
|
|
|
oneBatchList.add(element);
|
|
|
|
|
|
|
|
if (i == idxLimit) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.insertIgnoreBatch(oneBatchList);
|
|
|
|
|
|
|
|
//每次提交后需要清空集合数据
|
|
|
|
|
|
|
|
oneBatchList.clear();
|
|
|
|
|
|
|
|
idxLimit = Math.min(idxLimit + batchSize, size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.error("insertIgnoreBatch fail", e);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int insertIgnoreBatch(List<T> entityList);
|
|
|
|
int insertIgnoreBatch(List<T> entityList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 替换数据
|
|
|
|
* 替换数据
|
|
|
|
* replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样;
|
|
|
|
* replace into表示插入替换数据,需求表中有PrimaryKey,或者unique索引,如果数据库已经存在数据,则用新数据替换,如果没有数据效果则和insert into一样;
|
|
|
@ -262,5 +290,36 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
|
|
|
* @param entityList 实体类列表
|
|
|
|
* @param entityList 实体类列表
|
|
|
|
* @return 影响条数
|
|
|
|
* @return 影响条数
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
default boolean replaceBatchs(List<T> entityList) {
|
|
|
|
|
|
|
|
return this.replaceBatchs(entityList, DEFAULT_BATCH_SIZE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default boolean replaceBatchs(List<T> entityList, int batchSize) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
int size = entityList.size();
|
|
|
|
|
|
|
|
int idxLimit = Math.min(DEFAULT_BATCH_SIZE, size);
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
//保存单批提交的数据集合
|
|
|
|
|
|
|
|
List<T> oneBatchList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Iterator<T> var7 = entityList.iterator(); var7.hasNext(); ++i) {
|
|
|
|
|
|
|
|
T element = var7.next();
|
|
|
|
|
|
|
|
oneBatchList.add(element);
|
|
|
|
|
|
|
|
if (i == idxLimit) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.replaceBatch(oneBatchList);
|
|
|
|
|
|
|
|
//每次提交后需要清空集合数据
|
|
|
|
|
|
|
|
oneBatchList.clear();
|
|
|
|
|
|
|
|
idxLimit = Math.min(idxLimit + batchSize, size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.error("insertIgnoreBatch fail", e);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int replaceBatch(List<T> entityList);
|
|
|
|
int replaceBatch(List<T> entityList);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|