From 74a6cbd5978ac77d3de18f75d846e0083e330a9d Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Thu, 24 Aug 2023 12:37:16 +0800 Subject: [PATCH] Release 3.0.5.1 --- pom.xml | 2 +- .../mybatis/base/BaseEntity.java | 10 ++++++- .../base/BaseEntityWithLogicDelete.java | 10 +++++-- .../mybatis/base/BaseServiceImpl.java | 28 +++++++++++-------- .../core/LogicDeleteSupportSqlSource.java | 12 ++++---- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index b4ac6df..a5b187c 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ - 3.0.5 + 3.0.5.1 11 ${revision} diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java index bbee30f..004884d 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java @@ -9,6 +9,8 @@ import lombok.Data; import java.time.LocalDateTime; /** + * 基础实体类, 此类属性不需要显式设置, 框架会自动处理 + * * @author liaozan * @since 2021/10/14 */ @@ -17,20 +19,26 @@ public class BaseEntity { /** * 主键 id + *

+ * 数据库中需设置为自增主键 */ @TableId(value = MybatisConstants.ID, type = IdType.AUTO) protected Long id; /** * 创建时间 + *

+ * 数据库中需设置默认值为 current_timestamp */ @TableField(value = MybatisConstants.CREATE_TIME) protected LocalDateTime createTime; /** * 修改时间 + *

+ * 数据库中需设置默认值为 current_timestamp, on update current_timestamp */ @TableField(value = MybatisConstants.MODIFY_TIME) protected LocalDateTime modifyTime; -} \ No newline at end of file +} diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java index e0afb10..f3fa742 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java @@ -7,6 +7,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; /** + * 带逻辑删除的基础实体类, 此类属性不需要显式设置, 框架会自动处理 + * * @author liaozan * @since 2021/11/25 */ @@ -16,7 +18,8 @@ public class BaseEntityWithLogicDelete extends BaseEntity { /** * 逻辑删除 - * 注意:只有写 sql 明确指定查询此字段的时候才有值, update 时,无法修改此字段 + *

+ * 注意:默认不参与查询, 只有写 sql 明确指定查询此字段的时候才有值 */ @TableLogic @TableField(value = MybatisConstants.DELETED, select = false) @@ -24,7 +27,10 @@ public class BaseEntityWithLogicDelete extends BaseEntity { /** * 逻辑删除版本 - * 注意:只有写 sql 明确指定查询此字段的时候才有值 + *

+ * 注意:默认不参与查询, 只有写 sql 明确指定查询此字段的时候才有值 + * + * @see com.schbrain.framework.autoconfigure.mybatis.core.LogicDeleteSupportSqlSource */ @TableField(value = MybatisConstants.DELETE_VERSION, select = false) protected Long deleteVersion; diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java index e51aa16..b4a2cb4 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java @@ -20,11 +20,13 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Nullable; import java.io.Serializable; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Supplier; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; + /** * @author liaozan * @since 2021/10/14 @@ -34,10 +36,6 @@ public class BaseServiceImpl, T extends BaseEntity> exte @Nullable private BizIdColumnField bizIdColumnField; - private static SFunction identity() { - return any -> any; - } - @Override public T getById(Serializable id) { return getById((Long) id, false); @@ -63,13 +61,17 @@ public class BaseServiceImpl, T extends BaseEntity> exte @Override public Map getMapByIds(Collection ids) { - return getMapByIds(ids, identity()); + // Cannot call the override method here, because override method use mapper to judge the fields to select + if (isEmpty(ids)) { + return emptyMap(); + } + return StreamUtils.toMap(listByIds(ids), T::getId); } @Override public Map getMapByIds(Collection ids, SFunction mapper) { if (isEmpty(ids)) { - return Collections.emptyMap(); + return emptyMap(); } // noinspection unchecked List dataList = lambdaQuery().select(T::getId, mapper).in(T::getId, ids).list(); @@ -102,22 +104,26 @@ public class BaseServiceImpl, T extends BaseEntity> exte @Override public List listByBizIds(Collection bizIds) { if (isEmpty(bizIds)) { - return Collections.emptyList(); + return emptyList(); } return query().in(getBidColumnField().getColumnName(), bizIds).list(); } @Override public Map getMapByBizIds(Collection bizIds) { - return getMapByBizIds(bizIds, identity()); + // Cannot call the override method here, because override method use mapper to judge the fields to select + if (isEmpty(bizIds)) { + return emptyMap(); + } + return StreamUtils.toMap(listByBizIds(bizIds), entity -> getBidColumnField().getValue(entity)); } @Override public Map getMapByBizIds(Collection bizIds, SFunction mapper) { if (isEmpty(bizIds)) { - return Collections.emptyMap(); + return emptyMap(); } - // How to get the mapper fieldName ? + // How to get the mapper column ? return StreamUtils.toMap(listByBizIds(bizIds), entity -> getBidColumnField().getValue(entity), mapper); } diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java index fd33198..e791095 100644 --- a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java @@ -12,17 +12,17 @@ import java.util.List; */ public class LogicDeleteSupportSqlSource implements SqlSource { - public static final String DELETE_VERSION = "deleteVersion"; + private static final String DELETE_VERSION = "deleteVersion"; - private final SqlSource sqlSource; + private final SqlSource delegate; - public LogicDeleteSupportSqlSource(SqlSource sqlSource) { - this.sqlSource = sqlSource; + public LogicDeleteSupportSqlSource(SqlSource delegate) { + this.delegate = delegate; } @Override public BoundSql getBoundSql(Object parameterObject) { - BoundSql boundSql = sqlSource.getBoundSql(parameterObject); + BoundSql boundSql = delegate.getBoundSql(parameterObject); if (hasDeleteVersionProperty(boundSql.getParameterMappings())) { boundSql.setAdditionalParameter(DELETE_VERSION, System.currentTimeMillis()); } @@ -35,4 +35,4 @@ public class LogicDeleteSupportSqlSource implements SqlSource { .anyMatch(property -> property.equals(DELETE_VERSION)); } -} \ No newline at end of file +} -- GitLab