From 00b3fb584f7f03744382e856a0c2c122b05b0180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B5=E6=9F=B3=E5=8D=8E?= <290631660@qq.com> Date: Sat, 6 May 2023 16:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E5=8D=83=E4=B8=80?= =?UTF-8?q?=E6=89=B9=E6=AC=A1=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E8=AF=B7=E6=B1=82=E6=97=B6=E9=97=B4=E8=BF=87?= =?UTF-8?q?=E9=95=BF=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/core/BaseMapper.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java index 3e067bfa..797635dc 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java @@ -141,6 +141,28 @@ public interface BaseMapper { @DeleteProvider(type = EntitySqlProvider.class, method = "deleteBatchByIds") int deleteBatchByIds(@Param(FlexConsts.PRIMARY_VALUE) Collection 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 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 list = ids.subList(i * size, Math.min(i * size + size, entitiesSize)); + sum += deleteBatchByIds(list); + } + return sum; + } + /** * 根据 map 构建的条件来删除数据