Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
f942cc88
Commit
f942cc88
authored
Dec 28, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userDetailHash数据补充
parent
257e66d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
18 deletions
+46
-18
SyncHashController.java
...antgroup/xyqb/controller/external/SyncHashController.java
+42
-15
IUserDetailRepository.java
.../cn/quantgroup/xyqb/repository/IUserDetailRepository.java
+4
-3
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/SyncHashController.java
View file @
f942cc88
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.UserHashMapping
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.repository.IUserDetailRepository
;
import
cn.quantgroup.xyqb.repository.IUserHashMappingRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.BatchPreparedStatementSetter
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
...
...
@@ -25,14 +30,20 @@ public class SyncHashController {
private
Boolean
isContinue
=
false
;
@Autowired
private
IUserRepository
userRepository
;
private
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
@Autowired
private
IUserHashMappingRepository
userHashMappingRepository
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
IUserDetailRepository
userDetailRepository
;
/**
* 发起同步
*
...
...
@@ -49,25 +60,41 @@ public class SyncHashController {
while
(
isContinue
)
{
Stopwatch
started
=
Stopwatch
.
createStarted
();
Long
endPosition
=
startPosition
+
step
;
List
<
User
>
users
=
user
Repository
.
findByIdBetween
(
startPosition
,
endPosition
);
if
(
users
.
isEmpty
())
{
List
<
User
Detail
>
userDetails
=
userDetail
Repository
.
findByIdBetween
(
startPosition
,
endPosition
);
if
(
user
Detail
s
.
isEmpty
())
{
log
.
info
(
"没有数据了. 结束了"
);
return
;
}
log
.
info
(
"查询用户需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
users
.
forEach
(
user
->
{
UserHashMapping
userHashMapping
=
userHashMappingRepository
.
findByUserId
(
user
.
getId
());
if
(
userHashMapping
!=
null
)
{
return
;
List
<
UserHashMapping
>
userHashMappings
=
new
ArrayList
<>();
userDetails
.
forEach
(
userDetail
->
{
UserHashMapping
userHashMapping
=
new
UserHashMapping
();
userHashMapping
.
setUserId
(
userDetail
.
getUserId
());
userHashMapping
.
setIdNoMd5
(
MD5Util
.
build
(
userDetail
.
getIdNo
()));
userHashMappings
.
add
(
userHashMapping
);
});
log
.
info
(
"遍历计算md5&crc32需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
started
=
started
.
reset
().
start
();
String
sql
=
"UPDATE `user_hash_mapping` SET `id_no_md5` = ?, `id_no_md5_short` = ? WHERE `user_id` = ?;"
;
jdbcTemplate
.
batchUpdate
(
sql
,
new
BatchPreparedStatementSetter
()
{
@Override
public
void
setValues
(
PreparedStatement
ps
,
int
i
)
throws
SQLException
{
UserHashMapping
userHashMapping
=
userHashMappings
.
get
(
i
);
ps
.
setString
(
1
,
userHashMapping
.
getIdNoMd5
());
ps
.
setLong
(
2
,
userHashMapping
.
getIdNoMd5Short
());
ps
.
setLong
(
3
,
userHashMapping
.
getUserId
());
}
@Override
public
int
getBatchSize
()
{
return
userHashMappings
.
size
();
}
userHashMapping
=
new
UserHashMapping
();
userHashMapping
.
setUserId
(
user
.
getId
());
userHashMapping
.
setPhoneNoMd5
(
MD5Util
.
build
(
user
.
getPhoneNo
()));
userHashMappingRepository
.
saveAndFlush
(
userHashMapping
);
});
log
.
info
(
"batchUpdate需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
log
.
info
(
"来一波,start:{},end:{}"
,
startPosition
,
endPosition
);
startPosition
=
user
s
.
get
(
user
s
.
size
()
-
1
).
getId
()
+
1
;
startPosition
=
user
Details
.
get
(
userDetail
s
.
size
()
-
1
).
getId
()
+
1
;
try
{
Thread
.
sleep
(
250
);
...
...
src/main/java/cn/quantgroup/xyqb/repository/IUserDetailRepository.java
View file @
f942cc88
package
cn
.
quantgroup
.
xyqb
.
repository
;
import
java.util.List
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
...
...
@@ -9,7 +8,7 @@ import org.springframework.data.jpa.repository.Modifying;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
java.util.List
;
/**
* @author mengfan.feng
...
...
@@ -61,4 +60,6 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>,
@Query
(
value
=
"select * from user_detail where phone_no like ?1 and id_no like ?2"
,
nativeQuery
=
true
)
List
<
UserDetail
>
fuzzyQueryByPhoneNoAndIdNo
(
String
phoneNo
,
String
idNo
);
List
<
UserDetail
>
findByIdBetween
(
Long
id
,
Long
endId
);
}
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