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
b8683339
Commit
b8683339
authored
Nov 15, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开启用户数据生成
parent
f1293501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
33 deletions
+11
-33
SyncHashController.java
...antgroup/xyqb/controller/external/SyncHashController.java
+11
-33
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/SyncHashController.java
View file @
b8683339
...
@@ -3,20 +3,16 @@ package cn.quantgroup.xyqb.controller.external;
...
@@ -3,20 +3,16 @@ package cn.quantgroup.xyqb.controller.external;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.UserHashMapping
;
import
cn.quantgroup.xyqb.entity.UserHashMapping
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.repository.IUserHashMappingRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
com.google.common.base.Stopwatch
;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
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.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
...
@@ -29,15 +25,15 @@ public class SyncHashController {
...
@@ -29,15 +25,15 @@ public class SyncHashController {
private
Boolean
isContinue
=
false
;
private
Boolean
isContinue
=
false
;
public
static
Boolean
fight
=
fals
e
;
public
static
Boolean
fight
=
tru
e
;
@Autowired
@Autowired
private
IUserRepository
userRepository
;
private
IUserRepository
userRepository
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
private
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
private
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
@Autowired
private
IUserHashMappingRepository
userHashMappingRepository
;
/**
/**
* 发起同步
* 发起同步
*
*
...
@@ -60,38 +56,20 @@ public class SyncHashController {
...
@@ -60,38 +56,20 @@ public class SyncHashController {
return
;
return
;
}
}
log
.
info
(
"查询用户需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
log
.
info
(
"查询用户需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
started
=
started
.
reset
().
start
();
List
<
UserHashMapping
>
userHashMappings
=
new
ArrayList
<>();
users
.
forEach
(
user
->
{
users
.
forEach
(
user
->
{
UserHashMapping
userHashMapping
=
new
UserHashMapping
();
UserHashMapping
userHashMapping
=
userHashMappingRepository
.
findByUserId
(
user
.
getId
());
if
(
userHashMapping
!=
null
)
{
return
;
}
userHashMapping
=
new
UserHashMapping
();
userHashMapping
.
setUserId
(
user
.
getId
());
userHashMapping
.
setUserId
(
user
.
getId
());
userHashMapping
.
setPhoneNoMd5
(
MD5Util
.
build
(
user
.
getPhoneNo
()));
userHashMapping
.
setPhoneNoMd5
(
MD5Util
.
build
(
user
.
getPhoneNo
()));
userHashMapping
s
.
add
(
userHashMapping
);
userHashMapping
Repository
.
saveAndFlush
(
userHashMapping
);
});
});
log
.
info
(
"遍历计算md5&crc32需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
started
=
started
.
reset
().
start
();
String
sql
=
"INSERT INTO `user_hash_mapping` ( `user_id`, `phone_no_md5`, `phone_no_md5_short`) VALUES (?,?,?)"
;
jdbcTemplate
.
batchUpdate
(
sql
,
new
BatchPreparedStatementSetter
()
{
@Override
public
void
setValues
(
PreparedStatement
ps
,
int
i
)
throws
SQLException
{
UserHashMapping
userHashMapping
=
userHashMappings
.
get
(
i
);
ps
.
setLong
(
1
,
userHashMapping
.
getUserId
());
ps
.
setString
(
2
,
userHashMapping
.
getPhoneNoMd5
());
ps
.
setLong
(
3
,
userHashMapping
.
getPhoneNoMd5Short
());
}
@Override
public
int
getBatchSize
()
{
return
userHashMappings
.
size
();
}
});
log
.
info
(
"batchUpdate需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
log
.
info
(
"来一波,start:{},end:{}"
,
startPosition
,
endPosition
);
log
.
info
(
"来一波,start:{},end:{}"
,
startPosition
,
endPosition
);
startPosition
=
users
.
get
(
users
.
size
()
-
1
).
getId
()
+
1
;
startPosition
=
users
.
get
(
users
.
size
()
-
1
).
getId
()
+
1
;
try
{
try
{
Thread
.
sleep
(
250
);
Thread
.
sleep
(
250
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
...
...
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