Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
59ce0ba1
Commit
59ce0ba1
authored
May 08, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
829ef31e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
9 deletions
+40
-9
DataDaoKeyConvert.java
.../main/java/com/yanzuoguang/util/vo/DataDaoKeyConvert.java
+5
-2
DataDaoVo.java
...base/src/main/java/com/yanzuoguang/util/vo/DataDaoVo.java
+35
-7
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/DataDaoKeyConvert.java
View file @
59ce0ba1
package
com
.
yanzuoguang
.
util
.
vo
;
import
java.util.Map
;
/**
* 获取关键字
*
...
...
@@ -10,8 +12,9 @@ public interface DataDaoKeyConvert<T, M> extends DataDaoKey<T> {
/**
* 获取关键字
*
* @param from 来源对象
* @param mapHistory 映射的历史数据
* @param from 来源对象
* @return
*/
T
convert
(
M
from
);
T
convert
(
M
ap
<
String
,
T
>
mapHistory
,
M
from
);
}
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/DataDaoVo.java
View file @
59ce0ba1
...
...
@@ -18,13 +18,14 @@ public class DataDaoVo<T> {
private
Map
<
String
,
T
>
mapNow
=
new
HashMap
<>();
/**
*
初始话对象
*
将历史数据映射为HashMap
*
* @param hisitories
* @param nows
* @param keyFunc
* @param hisitories 历史数据
* @param keyFunc 获取主键函数
* @param <T>
* @return
*/
p
ublic
static
<
T
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
T
>
now
s
,
DataDaoKey
<
T
>
keyFunc
)
{
p
rivate
static
<
T
>
Map
<
String
,
T
>
getMapHistory
(
List
<
T
>
hisitorie
s
,
DataDaoKey
<
T
>
keyFunc
)
{
// 定义缓存集合
Map
<
String
,
T
>
mapHistory
=
new
HashMap
<>(
10
);
// 历史数据处理
...
...
@@ -34,6 +35,19 @@ public class DataDaoVo<T> {
mapHistory
.
put
(
key
,
his
);
}
}
return
mapHistory
;
}
/**
* 获取结果
*
* @param mapHistory 历史数据映射
* @param nows 当前数据
* @param keyFunc 获取主键函数
* @param <T>
* @return
*/
private
static
<
T
>
DataDaoVo
<
T
>
getResult
(
Map
<
String
,
T
>
mapHistory
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
DataDaoVo
<
T
>
res
=
new
DataDaoVo
<
T
>();
// 返回集
if
(
nows
!=
null
)
{
...
...
@@ -52,7 +66,19 @@ public class DataDaoVo<T> {
}
}
res
.
removes
.
addAll
(
mapHistory
.
values
());
return
res
;
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public
static
<
T
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
Map
<
String
,
T
>
mapHistory
=
getMapHistory
(
hisitories
,
keyFunc
);
DataDaoVo
<
T
>
res
=
getResult
(
mapHistory
,
nows
,
keyFunc
);
return
res
;
}
...
...
@@ -65,14 +91,16 @@ public class DataDaoVo<T> {
* @param keyFunc
*/
public
static
<
T
,
M
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
M
>
nows
,
DataDaoKeyConvert
<
T
,
M
>
keyFunc
)
{
Map
<
String
,
T
>
mapHistory
=
getMapHistory
(
hisitories
,
keyFunc
);
List
<
T
>
toNows
=
new
ArrayList
<>(
10
);
if
(
nows
!=
null
)
{
for
(
M
m
:
nows
)
{
T
t
=
keyFunc
.
convert
(
m
);
T
t
=
keyFunc
.
convert
(
m
apHistory
,
m
);
toNows
.
add
(
t
);
}
}
return
init
(
hisitories
,
toNows
,
keyFunc
);
DataDaoVo
<
T
>
res
=
getResult
(
mapHistory
,
toNows
,
keyFunc
);
return
res
;
}
/**
...
...
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