恢复错误修改的deleteBatchIds方法.

This commit is contained in:
nieqiurong 2024-06-08 18:04:15 +08:00
parent c1c31b723c
commit 486e3b84de
3 changed files with 19 additions and 4 deletions

View File

@ -168,6 +168,19 @@ public interface BaseMapper<T> extends Mapper<T> {
* 删除根据ID或实体 批量删除
*
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
* @deprecated 3.5.7 {@link #deleteByIds(Collection)}
*/
@Deprecated
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList) {
return deleteByIds(idList);
}
/**
* 删除根据ID或实体 批量删除
*
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
* @since 3.5.7
*/
default int deleteByIds(@Param(Constants.COLL) Collection<?> idList) {
return deleteByIds(idList, true);
@ -186,16 +199,17 @@ public interface BaseMapper<T> extends Mapper<T> {
SqlSession sqlSession = mybatisMapperProxy.getSqlSession();
Class<?> mapperInterface = mybatisMapperProxy.getMapperInterface();
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
List<Object> ids = new ArrayList<>(collections.size());
if (useFill && tableInfo.isWithLogicDelete() && tableInfo.isWithUpdateFill()) {
List<Object> ids = new ArrayList<>(collections.size());
for (Object obj : collections) {
// TODO 乐观锁待定(感觉都要删除了,可以不用考虑乐观锁的情况了)...
if (entityClass.isAssignableFrom(obj.getClass())) {
ids.add(tableInfo.getPropertyValue(obj, tableInfo.getKeyProperty()));
} else {
ids.add(obj);
}
}
this.update(tableInfo.newInstance(), Wrappers.<T>update().in(tableInfo.getKeyColumn(), ids));
return this.update(tableInfo.newInstance(), Wrappers.<T>update().in(tableInfo.getKeyColumn(), ids));
}
Map<String, Object> params = new HashMap<>();
params.put(Constants.COLL, collections);

View File

@ -74,7 +74,8 @@ public class LogicDelTest extends BaseDbTest<EntityMapper> {
entityList.add(entity2);
assertThat(mapper.deleteByIds(entityList)).isEqualTo(2);
entityList.forEach(entity -> {
Assertions.assertEquals("聂秋秋", entity.getDeleteBy());
//TODO 3.5.7 修改为使用IN的方式删除而不是使用行记录删除.
// Assertions.assertEquals("聂秋秋", entity.getDeleteBy());
});
});

View File

@ -62,7 +62,7 @@ class GeneratePomTest {
Assertions.assertFalse(bom.isOptional());
Assertions.assertEquals(dependenciesMap.get("spring-cloud-commons").getVersion(), "4.1.2");
Assertions.assertEquals(dependenciesMap.get("mybatis-spring").getVersion(), "3.0.3");
Assertions.assertEquals(dependenciesMap.get("spring-boot-dependencies").getVersion(), "3.2.4");
Assertions.assertEquals(dependenciesMap.get("spring-boot-dependencies").getVersion(), "3.2.6");
}
}