暂时不修改方法名,清理removeByIds代码.

This commit is contained in:
nieqiurong 2024-04-10 14:49:32 +08:00
parent f16da35bf6
commit 4b9a42bc8a
4 changed files with 13 additions and 59 deletions

View File

@ -174,23 +174,9 @@ public interface BaseMapper<T> extends Mapper<T> {
* 删除根据ID或实体 批量删除
*
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
* @since 3.5.7
*/
default int deleteByIds(@Param(Constants.COLL) Collection<?> idList) {
return deleteByIds(idList, true);
}
/**
* 删除根据ID或实体 批量删除
*
* @param idList 主键ID列表或实体列表(不能为 null 以及 empty)
* @see #deleteByIds(Collection)
* @deprecated 3.5.7
*/
@Deprecated
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList) {
return deleteByIds(idList, true);
return deleteBatchIds(idList, true);
}
/**
@ -200,7 +186,7 @@ public interface BaseMapper<T> extends Mapper<T> {
* @param useFill 逻辑删除下是否填充
* @since 3.5.7
*/
default int deleteByIds(@Param(Constants.COLL) Collection<?> collections, boolean useFill) {
default int deleteBatchIds(@Param(Constants.COLL) Collection<?> collections, boolean useFill) {
MybatisMapperProxy<?> mybatisMapperProxy = (MybatisMapperProxy<?>) Proxy.getInvocationHandler(this);
Class<?> entityClass = GenericTypeUtils.resolveTypeArguments(getClass(), BaseMapper.class)[0];
SqlSession sqlSession = mybatisMapperProxy.getSqlSession();

View File

@ -155,7 +155,7 @@ public interface IService<T> {
if (CollectionUtils.isEmpty(list)) {
return false;
}
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
}
/**
@ -166,15 +166,11 @@ public interface IService<T> {
* @return 删除结果
* @since 3.5.0
*/
@Transactional(rollbackFor = Exception.class)
default boolean removeByIds(Collection<?> list, boolean useFill) {
if (CollectionUtils.isEmpty(list)) {
return false;
}
if (useFill) {
return removeBatchByIds(list, true);
}
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
}
/**
@ -197,7 +193,6 @@ public interface IService<T> {
* @return 删除结果
* @since 3.5.0
*/
@Transactional(rollbackFor = Exception.class)
default boolean removeBatchByIds(Collection<?> list, boolean useFill) {
return removeBatchByIds(list, DEFAULT_BATCH_SIZE, useFill);
}
@ -208,9 +203,8 @@ public interface IService<T> {
* @param list 主键ID或实体列表
* @param batchSize 批次大小
* @return 删除结果
* @see #removeBatchByIds(Collection, boolean)
* @since 3.5.0
* @deprecated 3.5.7
* @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
*/
@Deprecated
default boolean removeBatchByIds(Collection<?> list, int batchSize) {
@ -224,9 +218,8 @@ public interface IService<T> {
* @param batchSize 批次大小
* @param useFill 是否启用填充(为true的情况,会将入参转换实体进行delete删除)
* @return 删除结果
* @see #removeBatchByIds(Collection, boolean)
* @since 3.5.0
* @deprecated 3.5.7
* @deprecated 3.5.7 {@link #removeBatchByIds(Collection)}
*/
@Deprecated
default boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {

View File

@ -295,45 +295,20 @@ public abstract class ServiceImpl<M extends BaseMapper<T>, T> implements IServic
protected <E> boolean executeBatch(Collection<E> list, BiConsumer<SqlSession, E> consumer) {
return executeBatch(list, DEFAULT_BATCH_SIZE, consumer);
}
@Override
public boolean removeById(Serializable id) {
return SqlHelper.retBool(getBaseMapper().deleteById(id));
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByIds(Collection<?> list) {
if (CollectionUtils.isEmpty(list)) {
return false;
}
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
}
@Override
public boolean removeById(Serializable id, boolean useFill) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
if (useFill && tableInfo.isWithLogicDelete()) {
if (!entityClass.isAssignableFrom(id.getClass())) {
T instance = tableInfo.newInstance();
Object value = tableInfo.getKeyType() != id.getClass() ? conversionService.convert(id, tableInfo.getKeyType()) : id;
tableInfo.setPropertyValue(instance, tableInfo.getKeyProperty(), value);
return removeById(instance);
}
}
return SqlHelper.retBool(getBaseMapper().deleteById(id));
return SqlHelper.retBool(getBaseMapper().deleteById(id, useFill));
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeBatchByIds(Collection<?> list, int batchSize) {
return SqlHelper.retBool(getBaseMapper().deleteByIds(list));
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list));
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
return SqlHelper.retBool(getBaseMapper().deleteByIds(list, useFill));
return SqlHelper.retBool(getBaseMapper().deleteBatchIds(list, useFill));
}
}

View File

@ -315,14 +315,14 @@ class H2UserMapperTest extends BaseTest {
@Test
void testRemoveByIds() {
Assertions.assertEquals(userMapper.deleteByIds(List.of(666666661, "2")), userMapper.deleteByIds(List.of(666666661, "2"), false));
Assertions.assertEquals(userMapper.deleteBatchIds(List.of(666666661, "2")), userMapper.deleteBatchIds(List.of(666666661, "2"), false));
H2User h2User = new H2User("testRemoveByIds");
userMapper.insert(h2User);
userMapper.deleteByIds(List.of(h2User));
userMapper.deleteBatchIds(List.of(h2User));
Assertions.assertNotNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
h2User = new H2User("testRemoveByIds");
userMapper.insert(h2User);
userMapper.deleteByIds(List.of(h2User), false);
userMapper.deleteBatchIds(List.of(h2User), false);
Assertions.assertNull(userMapper.getById(h2User.getTestId()).getLastUpdatedDt());
}