refactor: optimize IService.java

This commit is contained in:
Michael Yang 2024-08-21 16:44:36 +08:00
parent a9c8638eac
commit fb7d13f4b9

View File

@ -269,6 +269,7 @@ public interface IService<T> {
return updateBatch(entities, DEFAULT_BATCH_SIZE); return updateBatch(entities, DEFAULT_BATCH_SIZE);
} }
/** /**
* <p>根据数据主键批量更新数据 * <p>根据数据主键批量更新数据
* *
@ -279,8 +280,8 @@ public interface IService<T> {
* @return boolean {@code true} 更新成功{@code false} 更新失败 * @return boolean {@code true} 更新成功{@code false} 更新失败
* @apiNote {@code ignoreNulls} {@code true}实体类中为 {@code null} 的属性不会更新到数据库 * @apiNote {@code ignoreNulls} {@code true}实体类中为 {@code null} 的属性不会更新到数据库
*/ */
default boolean updateBatchWithIgnoreNulls(Collection<T> entities, boolean ignoreNulls) { default boolean updateBatch(Collection<T> entities, boolean ignoreNulls) {
return updateBatchWithIgnoreNulls(entities, DEFAULT_BATCH_SIZE, ignoreNulls); return updateBatch(entities, DEFAULT_BATCH_SIZE, ignoreNulls);
} }
/** /**
@ -296,6 +297,7 @@ public interface IService<T> {
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::update)); return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::update));
} }
/** /**
* <p>根据数据主键批量更新数据 * <p>根据数据主键批量更新数据
* *
@ -307,7 +309,7 @@ public interface IService<T> {
* @return {@code true} 更新成功{@code false} 更新失败 * @return {@code true} 更新成功{@code false} 更新失败
* @apiNote {@code ignoreNulls} {@code true}实体类中为 {@code null} 的属性不会更新到数据库 * @apiNote {@code ignoreNulls} {@code true}实体类中为 {@code null} 的属性不会更新到数据库
*/ */
default boolean updateBatchWithIgnoreNulls(Collection<T> entities, int batchSize, boolean ignoreNulls) { default boolean updateBatch(Collection<T> entities, int batchSize, boolean ignoreNulls) {
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass()); Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls))); return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls)));
} }
@ -344,6 +346,7 @@ public interface IService<T> {
default Optional<T> getByEntityIdOpt(T entity) { default Optional<T> getByEntityIdOpt(T entity) {
return Optional.ofNullable(getOneByEntityId(entity)); return Optional.ofNullable(getOneByEntityId(entity));
} }
/** /**
* <p>根据数据主键查询一条数据 * <p>根据数据主键查询一条数据
* *