mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
新增一千一批次批量删除,防止请求时间过长异常
This commit is contained in:
parent
1871dc1ca7
commit
00b3fb584f
@ -141,6 +141,28 @@ public interface BaseMapper<T> {
|
|||||||
@DeleteProvider(type = EntitySqlProvider.class, method = "deleteBatchByIds")
|
@DeleteProvider(type = EntitySqlProvider.class, method = "deleteBatchByIds")
|
||||||
int deleteBatchByIds(@Param(FlexConsts.PRIMARY_VALUE) Collection<? extends Serializable> ids);
|
int deleteBatchByIds(@Param(FlexConsts.PRIMARY_VALUE) Collection<? extends Serializable> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据多个 id 批量删除数据
|
||||||
|
*
|
||||||
|
* @param ids ids 列表
|
||||||
|
* @param size 切分大小
|
||||||
|
* @return 返回影响的行数
|
||||||
|
* @see com.mybatisflex.core.provider.EntitySqlProvider#deleteBatchByIds(Map, ProviderContext)
|
||||||
|
*/
|
||||||
|
default int deleteBatchByIds(@Param(FlexConsts.PRIMARY_VALUE) List<? extends Serializable> ids, int size) {
|
||||||
|
if (size <= 0) {
|
||||||
|
size = 1000;//默认1000
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
int entitiesSize = ids.size();
|
||||||
|
int maxIndex = entitiesSize / size + (entitiesSize % size == 0 ? 0 : 1);
|
||||||
|
for (int i = 0; i < maxIndex; i++) {
|
||||||
|
List<? extends Serializable> list = ids.subList(i * size, Math.min(i * size + size, entitiesSize));
|
||||||
|
sum += deleteBatchByIds(list);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 map 构建的条件来删除数据
|
* 根据 map 构建的条件来删除数据
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user