Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
74a6cbd5
Commit
74a6cbd5
authored
Aug 24, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Release 3.0.5.1
parent
95ccac18
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
21 deletions
+41
-21
pom.xml
pom.xml
+1
-1
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java
...rain/framework/autoconfigure/mybatis/base/BaseEntity.java
+9
-1
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java
...autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java
+8
-2
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java
...framework/autoconfigure/mybatis/base/BaseServiceImpl.java
+17
-11
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java
...toconfigure/mybatis/core/LogicDeleteSupportSqlSource.java
+6
-6
No files found.
pom.xml
View file @
74a6cbd5
...
@@ -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>
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntity.java
View file @
74a6cbd5
...
@@ -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,18 +19,24 @@ public class BaseEntity {
...
@@ -17,18 +19,24 @@ 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
;
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseEntityWithLogicDelete.java
View file @
74a6cbd5
...
@@ -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
;
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java
View file @
74a6cbd5
...
@@ -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
);
}
}
...
...
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/core/LogicDeleteSupportSqlSource.java
View file @
74a6cbd5
...
@@ -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
{
p
ublic
static
final
String
DELETE_VERSION
=
"deleteVersion"
;
p
rivate
static
final
String
DELETE_VERSION
=
"deleteVersion"
;
private
final
SqlSource
sqlSourc
e
;
private
final
SqlSource
delegat
e
;
public
LogicDeleteSupportSqlSource
(
SqlSource
sqlSourc
e
)
{
public
LogicDeleteSupportSqlSource
(
SqlSource
delegat
e
)
{
this
.
sqlSource
=
sqlSourc
e
;
this
.
delegate
=
delegat
e
;
}
}
@Override
@Override
public
BoundSql
getBoundSql
(
Object
parameterObject
)
{
public
BoundSql
getBoundSql
(
Object
parameterObject
)
{
BoundSql
boundSql
=
sqlSourc
e
.
getBoundSql
(
parameterObject
);
BoundSql
boundSql
=
delegat
e
.
getBoundSql
(
parameterObject
);
if
(
hasDeleteVersionProperty
(
boundSql
.
getParameterMappings
()))
{
if
(
hasDeleteVersionProperty
(
boundSql
.
getParameterMappings
()))
{
boundSql
.
setAdditionalParameter
(
DELETE_VERSION
,
System
.
currentTimeMillis
());
boundSql
.
setAdditionalParameter
(
DELETE_VERSION
,
System
.
currentTimeMillis
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment