Commit 74a6cbd5 authored by liaozan's avatar liaozan 🏀

Release 3.0.5.1

parent 95ccac18
......@@ -43,7 +43,7 @@
</distributionManagement>
<properties>
<revision>3.0.5</revision>
<revision>3.0.5.1</revision>
<java.version>11</java.version>
<!-- 2th part versions -->
<schbrain-apollo.version>${revision}</schbrain-apollo.version>
......
......@@ -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
* <p>
* 数据库中需设置为自增主键
*/
@TableId(value = MybatisConstants.ID, type = IdType.AUTO)
protected Long id;
/**
* 创建时间
* <p>
* 数据库中需设置默认值为 current_timestamp
*/
@TableField(value = MybatisConstants.CREATE_TIME)
protected LocalDateTime createTime;
/**
* 修改时间
* <p>
* 数据库中需设置默认值为 current_timestamp, on update current_timestamp
*/
@TableField(value = MybatisConstants.MODIFY_TIME)
protected LocalDateTime modifyTime;
}
\ No newline at end of file
}
......@@ -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 时,无法修改此字段
* <p>
* 注意:默认不参与查询, 只有写 sql 明确指定查询此字段的时候才有值
*/
@TableLogic
@TableField(value = MybatisConstants.DELETED, select = false)
......@@ -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)
protected Long deleteVersion;
......
......@@ -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<M extends BaseMapper<T>, T extends BaseEntity> exte
@Nullable
private BizIdColumnField bizIdColumnField;
private static <T> SFunction<T, T> identity() {
return any -> any;
}
@Override
public T getById(Serializable id) {
return getById((Long) id, false);
......@@ -63,13 +61,17 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
@Override
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
public <V> Map<Long, V> getMapByIds(Collection<Long> ids, SFunction<T, V> mapper) {
if (isEmpty(ids)) {
return Collections.emptyMap();
return emptyMap();
}
// noinspection unchecked
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
@Override
public <K> List<T> listByBizIds(Collection<K> bizIds) {
if (isEmpty(bizIds)) {
return Collections.emptyList();
return emptyList();
}
return query().in(getBidColumnField().getColumnName(), bizIds).list();
}
@Override
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
public <K, V> Map<K, V> getMapByBizIds(Collection<K> bizIds, SFunction<T, V> 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);
}
......
......@@ -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
}
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