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
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
panwangnan
schbrain-parent
Commits
56814af5
Commit
56814af5
authored
Jul 12, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BaseService#getMapBy* support value mapper
parent
6f357f4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseService.java
...ain/framework/autoconfigure/mybatis/base/BaseService.java
+12
-1
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java
...framework/autoconfigure/mybatis/base/BaseServiceImpl.java
+16
-3
No files found.
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseService.java
View file @
56814af5
...
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
...
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
public
interface
BaseService
<
T
extends
BaseEntity
>
extends
IService
<
T
>
{
public
interface
BaseService
<
T
extends
BaseEntity
>
extends
IService
<
T
>
{
...
@@ -28,6 +29,11 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
...
@@ -28,6 +29,11 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
*/
*/
Map
<
Long
,
T
>
getMapByIds
(
Collection
<
Long
>
ids
);
Map
<
Long
,
T
>
getMapByIds
(
Collection
<
Long
>
ids
);
/**
* 根据 id 获取
*/
<
V
>
Map
<
Long
,
V
>
getMapByIds
(
Collection
<
Long
>
ids
,
Function
<
T
,
V
>
mapper
);
/**
/**
* 根据业务主键获取记录
* 根据业务主键获取记录
*/
*/
...
@@ -57,6 +63,11 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
...
@@ -57,6 +63,11 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
*/
*/
<
K
>
Map
<
K
,
T
>
getMapByBizIds
(
Collection
<
K
>
bizIds
);
<
K
>
Map
<
K
,
T
>
getMapByBizIds
(
Collection
<
K
>
bizIds
);
/**
* 根据业务主键获取
*/
<
K
,
V
>
Map
<
K
,
V
>
getMapByBizIds
(
Collection
<
K
>
bizIds
,
Function
<
T
,
V
>
mapper
);
/**
/**
* 根据 id 更新,null 会被更新为 null
* 根据 id 更新,null 会被更新为 null
*/
*/
...
@@ -72,4 +83,4 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
...
@@ -72,4 +83,4 @@ public interface BaseService<T extends BaseEntity> extends IService<T> {
*/
*/
boolean
updateBatchByIdsWithNull
(
Collection
<
T
>
entityList
,
int
batchSize
);
boolean
updateBatchByIdsWithNull
(
Collection
<
T
>
entityList
,
int
batchSize
);
}
}
\ No newline at end of file
starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceImpl.java
View file @
56814af5
...
@@ -16,11 +16,13 @@ import org.springframework.beans.factory.InitializingBean;
...
@@ -16,11 +16,13 @@ import org.springframework.beans.factory.InitializingBean;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils
;
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.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
/**
/**
...
@@ -29,6 +31,7 @@ import java.util.function.Supplier;
...
@@ -29,6 +31,7 @@ import java.util.function.Supplier;
*/
*/
public
class
BaseServiceImpl
<
M
extends
BaseMapper
<
T
>,
T
extends
BaseEntity
>
extends
ServiceImpl
<
M
,
T
>
implements
BaseService
<
T
>,
ValidateSupport
,
InitializingBean
{
public
class
BaseServiceImpl
<
M
extends
BaseMapper
<
T
>,
T
extends
BaseEntity
>
extends
ServiceImpl
<
M
,
T
>
implements
BaseService
<
T
>,
ValidateSupport
,
InitializingBean
{
@Nullable
private
BizIdColumnField
bizIdColumnField
;
private
BizIdColumnField
bizIdColumnField
;
@Override
@Override
...
@@ -56,10 +59,15 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
...
@@ -56,10 +59,15 @@ 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
,
Function
.
identity
());
}
@Override
public
<
V
>
Map
<
Long
,
V
>
getMapByIds
(
Collection
<
Long
>
ids
,
Function
<
T
,
V
>
mapper
)
{
if
(
isEmpty
(
ids
))
{
if
(
isEmpty
(
ids
))
{
return
Collections
.
emptyMap
();
return
Collections
.
emptyMap
();
}
}
return
StreamUtils
.
toMap
(
super
.
listByIds
(
ids
),
T:
:
getId
);
return
StreamUtils
.
toMap
(
listByIds
(
ids
),
T:
:
getId
,
mapper
);
}
}
@Override
@Override
...
@@ -97,11 +105,16 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
...
@@ -97,11 +105,16 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
@Override
@Override
public
<
K
>
Map
<
K
,
T
>
getMapByBizIds
(
Collection
<
K
>
bizIds
)
{
public
<
K
>
Map
<
K
,
T
>
getMapByBizIds
(
Collection
<
K
>
bizIds
)
{
return
getMapByBizIds
(
bizIds
,
Function
.
identity
());
}
@Override
public
<
K
,
V
>
Map
<
K
,
V
>
getMapByBizIds
(
Collection
<
K
>
bizIds
,
Function
<
T
,
V
>
mapper
)
{
assertBidColumnFieldExist
();
assertBidColumnFieldExist
();
if
(
isEmpty
(
bizIds
))
{
if
(
isEmpty
(
bizIds
))
{
return
Collections
.
emptyMap
();
return
Collections
.
emptyMap
();
}
}
return
StreamUtils
.
toMap
(
listByBizIds
(
bizIds
),
entity
->
bizIdColumnField
.
getValue
(
entity
));
return
StreamUtils
.
toMap
(
listByBizIds
(
bizIds
),
entity
->
bizIdColumnField
.
getValue
(
entity
)
,
mapper
);
}
}
@Override
@Override
...
@@ -147,4 +160,4 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
...
@@ -147,4 +160,4 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
return
mapperClass
.
getName
()
+
StringPool
.
DOT
+
"alwaysUpdateSomeColumnById"
;
return
mapperClass
.
getName
()
+
StringPool
.
DOT
+
"alwaysUpdateSomeColumnById"
;
}
}
}
}
\ No newline at end of file
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