Commit 74a6cbd5 authored by liaozan's avatar liaozan 🏀

Release 3.0.5.1

parent 95ccac18
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
</distributionManagement> </distributionManagement>
<properties> <properties>
<revision>3.0.5</revision> <revision>3.0.5.1</revision>
<java.version>11</java.version> <java.version>11</java.version>
<!-- 2th part versions --> <!-- 2th part versions -->
<schbrain-apollo.version>${revision}</schbrain-apollo.version> <schbrain-apollo.version>${revision}</schbrain-apollo.version>
......
...@@ -9,6 +9,8 @@ import lombok.Data; ...@@ -9,6 +9,8 @@ import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
* 基础实体类, 此类属性不需要显式设置, 框架会自动处理
*
* @author liaozan * @author liaozan
* @since 2021/10/14 * @since 2021/10/14
*/ */
...@@ -17,20 +19,26 @@ public class BaseEntity { ...@@ -17,20 +19,26 @@ public class BaseEntity {
/** /**
* 主键 id * 主键 id
* <p>
* 数据库中需设置为自增主键
*/ */
@TableId(value = MybatisConstants.ID, type = IdType.AUTO) @TableId(value = MybatisConstants.ID, type = IdType.AUTO)
protected Long id; protected Long id;
/** /**
* 创建时间 * 创建时间
* <p>
* 数据库中需设置默认值为 current_timestamp
*/ */
@TableField(value = MybatisConstants.CREATE_TIME) @TableField(value = MybatisConstants.CREATE_TIME)
protected LocalDateTime createTime; protected LocalDateTime createTime;
/** /**
* 修改时间 * 修改时间
* <p>
* 数据库中需设置默认值为 current_timestamp, on update current_timestamp
*/ */
@TableField(value = MybatisConstants.MODIFY_TIME) @TableField(value = MybatisConstants.MODIFY_TIME)
protected LocalDateTime modifyTime; protected LocalDateTime modifyTime;
} }
\ No newline at end of file
...@@ -7,6 +7,8 @@ import lombok.Data; ...@@ -7,6 +7,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
/** /**
* 带逻辑删除的基础实体类, 此类属性不需要显式设置, 框架会自动处理
*
* @author liaozan * @author liaozan
* @since 2021/11/25 * @since 2021/11/25
*/ */
...@@ -16,7 +18,8 @@ public class BaseEntityWithLogicDelete extends BaseEntity { ...@@ -16,7 +18,8 @@ public class BaseEntityWithLogicDelete extends BaseEntity {
/** /**
* 逻辑删除 * 逻辑删除
* 注意:只有写 sql 明确指定查询此字段的时候才有值, update 时,无法修改此字段 * <p>
* 注意:默认不参与查询, 只有写 sql 明确指定查询此字段的时候才有值
*/ */
@TableLogic @TableLogic
@TableField(value = MybatisConstants.DELETED, select = false) @TableField(value = MybatisConstants.DELETED, select = false)
...@@ -24,7 +27,10 @@ public class BaseEntityWithLogicDelete extends BaseEntity { ...@@ -24,7 +27,10 @@ public class BaseEntityWithLogicDelete extends BaseEntity {
/** /**
* 逻辑删除版本 * 逻辑删除版本
* 注意:只有写 sql 明确指定查询此字段的时候才有值 * <p>
* 注意:默认不参与查询, 只有写 sql 明确指定查询此字段的时候才有值
*
* @see com.schbrain.framework.autoconfigure.mybatis.core.LogicDeleteSupportSqlSource
*/ */
@TableField(value = MybatisConstants.DELETE_VERSION, select = false) @TableField(value = MybatisConstants.DELETE_VERSION, select = false)
protected Long deleteVersion; protected Long deleteVersion;
......
...@@ -20,11 +20,13 @@ import org.springframework.util.ReflectionUtils; ...@@ -20,11 +20,13 @@ import org.springframework.util.ReflectionUtils;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
/** /**
* @author liaozan * @author liaozan
* @since 2021/10/14 * @since 2021/10/14
...@@ -34,10 +36,6 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte ...@@ -34,10 +36,6 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
@Nullable @Nullable
private BizIdColumnField bizIdColumnField; private BizIdColumnField bizIdColumnField;
private static <T> SFunction<T, T> identity() {
return any -> any;
}
@Override @Override
public T getById(Serializable id) { public T getById(Serializable id) {
return getById((Long) id, false); return getById((Long) id, false);
...@@ -63,13 +61,17 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte ...@@ -63,13 +61,17 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
@Override @Override
public Map<Long, T> getMapByIds(Collection<Long> ids) { public Map<Long, T> getMapByIds(Collection<Long> 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 @Override
public <V> Map<Long, V> getMapByIds(Collection<Long> ids, SFunction<T, V> mapper) { public <V> Map<Long, V> getMapByIds(Collection<Long> ids, SFunction<T, V> mapper) {
if (isEmpty(ids)) { if (isEmpty(ids)) {
return Collections.emptyMap(); return emptyMap();
} }
// noinspection unchecked // noinspection unchecked
List<T> dataList = lambdaQuery().select(T::getId, mapper).in(T::getId, ids).list(); List<T> dataList = lambdaQuery().select(T::getId, mapper).in(T::getId, ids).list();
...@@ -102,22 +104,26 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte ...@@ -102,22 +104,26 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
@Override @Override
public <K> List<T> listByBizIds(Collection<K> bizIds) { public <K> List<T> listByBizIds(Collection<K> bizIds) {
if (isEmpty(bizIds)) { if (isEmpty(bizIds)) {
return Collections.emptyList(); return emptyList();
} }
return query().in(getBidColumnField().getColumnName(), bizIds).list(); return query().in(getBidColumnField().getColumnName(), bizIds).list();
} }
@Override @Override
public <K> Map<K, T> getMapByBizIds(Collection<K> bizIds) { public <K> Map<K, T> getMapByBizIds(Collection<K> 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 @Override
public <K, V> Map<K, V> getMapByBizIds(Collection<K> bizIds, SFunction<T, V> mapper) { public <K, V> Map<K, V> getMapByBizIds(Collection<K> bizIds, SFunction<T, V> mapper) {
if (isEmpty(bizIds)) { 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); return StreamUtils.toMap(listByBizIds(bizIds), entity -> getBidColumnField().getValue(entity), mapper);
} }
......
...@@ -12,17 +12,17 @@ import java.util.List; ...@@ -12,17 +12,17 @@ import java.util.List;
*/ */
public class LogicDeleteSupportSqlSource implements SqlSource { 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) { public LogicDeleteSupportSqlSource(SqlSource delegate) {
this.sqlSource = sqlSource; this.delegate = delegate;
} }
@Override @Override
public BoundSql getBoundSql(Object parameterObject) { public BoundSql getBoundSql(Object parameterObject) {
BoundSql boundSql = sqlSource.getBoundSql(parameterObject); BoundSql boundSql = delegate.getBoundSql(parameterObject);
if (hasDeleteVersionProperty(boundSql.getParameterMappings())) { if (hasDeleteVersionProperty(boundSql.getParameterMappings())) {
boundSql.setAdditionalParameter(DELETE_VERSION, System.currentTimeMillis()); boundSql.setAdditionalParameter(DELETE_VERSION, System.currentTimeMillis());
} }
...@@ -35,4 +35,4 @@ public class LogicDeleteSupportSqlSource implements SqlSource { ...@@ -35,4 +35,4 @@ public class LogicDeleteSupportSqlSource implements SqlSource {
.anyMatch(property -> property.equals(DELETE_VERSION)); .anyMatch(property -> property.equals(DELETE_VERSION));
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment