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
bd3cfec0
Commit
bd3cfec0
authored
Apr 03, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码,减少不必要的网络微信请求
parent
5bf6b90f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
49 deletions
+18
-49
UserQueryLogController.java
.../controller/external/queryLog/UserQueryLogController.java
+0
-29
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+15
-16
UserDetailServiceImpl.java
...ntgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
+3
-4
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/queryLog/UserQueryLogController.java
View file @
bd3cfec0
...
@@ -110,7 +110,6 @@ public class UserQueryLogController {
...
@@ -110,7 +110,6 @@ public class UserQueryLogController {
}
else
if
(
pageSize
>
200
){
}
else
if
(
pageSize
>
200
){
pageSize
=
200
;
pageSize
=
200
;
}
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
try
{
try
{
for
(
UserQueryLog
ll:
userQueryLogs
){
for
(
UserQueryLog
ll:
userQueryLogs
){
...
@@ -120,26 +119,20 @@ public class UserQueryLogController {
...
@@ -120,26 +119,20 @@ public class UserQueryLogController {
LOGGER
.
info
(
"日期时间转换异常"
);
LOGGER
.
info
(
"日期时间转换异常"
);
return
JsonResult
.
buildErrorStateResult
(
"日期时间转换异常"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"日期时间转换异常"
,
null
);
}
}
uqp
.
setPageSize
(
pageSize
);
uqp
.
setPageSize
(
pageSize
);
uqp
.
setPageId
(
pageId
);
uqp
.
setPageId
(
pageId
);
uqp
.
setPageList
(
userQueryLogs
);
uqp
.
setPageList
(
userQueryLogs
);
int
yu
=
total
.
intValue
()%
pageSize
;
int
yu
=
total
.
intValue
()%
pageSize
;
Double
d
=
Math
.
ceil
(
total
/
pageSize
);
Double
d
=
Math
.
ceil
(
total
/
pageSize
);
uqp
.
setPages
(
yu
>
0
?
d
.
intValue
()+
1
:
d
.
intValue
());
uqp
.
setPages
(
yu
>
0
?
d
.
intValue
()+
1
:
d
.
intValue
());
return
JsonResult
.
buildSuccessResult
(
"查询成功"
,
uqp
);
return
JsonResult
.
buildSuccessResult
(
"查询成功"
,
uqp
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
return
JsonResult
.
buildErrorStateResult
(
"查询失败"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"查询失败"
,
null
);
}
}
}
}
@RequestMapping
(
"/queryUserInfo"
)
@RequestMapping
(
"/queryUserInfo"
)
public
JsonResult
queryForResult
(
HttpServletRequest
request
,
String
key
,
String
keyValues
,
String
columns
,
Integer
pageId
,
Integer
pageSize
)
{
public
JsonResult
queryForResult
(
HttpServletRequest
request
,
String
key
,
String
keyValues
,
String
columns
,
Integer
pageId
,
Integer
pageSize
)
{
LOGGER
.
info
(
"查询条件:key{},columns{}"
,
key
,
columns
);
LOGGER
.
info
(
"查询条件:key{},columns{}"
,
key
,
columns
);
String
token
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
String
token
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
if
(
StringUtils
.
isEmpty
(
token
)){
if
(
StringUtils
.
isEmpty
(
token
)){
...
@@ -162,45 +155,36 @@ public class UserQueryLogController {
...
@@ -162,45 +155,36 @@ public class UserQueryLogController {
}
}
String
[]
values
=
keyValues
.
split
(
"\\n"
);
String
[]
values
=
keyValues
.
split
(
"\\n"
);
List
<
String
>
queryV
=
Arrays
.
asList
(
values
);
List
<
String
>
queryV
=
Arrays
.
asList
(
values
);
if
(
queryV
!=
null
&&
queryV
.
size
()>
50000
){
if
(
queryV
!=
null
&&
queryV
.
size
()>
50000
){
return
JsonResult
.
buildErrorStateResult
(
"查询记录数是"
+
queryV
.
size
()+
",超过50000条限制"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"查询记录数是"
+
queryV
.
size
()+
",超过50000条限制"
,
null
);
}
}
List
<
UserQueryInfo
>
userQueryInfos
=
new
ArrayList
<
UserQueryInfo
>();
List
<
UserQueryInfo
>
userQueryInfos
=
new
ArrayList
<
UserQueryInfo
>();
List
<
UserDetail
>
userDetails
=
new
ArrayList
<
UserDetail
>();
List
<
UserDetail
>
userDetails
=
new
ArrayList
<
UserDetail
>();
Page
<
UserDetail
>
userDetailPage
=
null
;
Page
<
UserDetail
>
userDetailPage
=
null
;
List
<
Address
>
addresslist
=
new
ArrayList
<
Address
>();
List
<
Address
>
addresslist
=
new
ArrayList
<
Address
>();
HashMap
<
String
,
String
>
phonesCards
=
new
HashMap
<
String
,
String
>();
HashMap
<
String
,
String
>
phonesCards
=
new
HashMap
<
String
,
String
>();
if
(
pageSize
==
0
||
pageSize
<
0
){
if
(
pageSize
==
0
||
pageSize
<
0
){
pageSize
=
30
;
pageSize
=
30
;
}
else
if
(
pageSize
>
200
){
}
else
if
(
pageSize
>
200
){
pageSize
=
200
;
pageSize
=
200
;
}
}
//如果维度里面没有保护查询条件则加入条件
//如果维度里面没有保护查询条件则加入条件
if
(!
columns
.
contains
(
key
)){
if
(!
columns
.
contains
(
key
)){
columns
=
columns
+
","
+
key
;
columns
=
columns
+
","
+
key
;
}
}
if
(
Objects
.
equals
(
key
,
"userId"
)){
if
(
Objects
.
equals
(
key
,
"userId"
)){
List
<
Long
>
userIds
=
new
ArrayList
<
Long
>();
List
<
Long
>
userIds
=
new
ArrayList
<
Long
>();
try
{
try
{
for
(
String
s:
queryV
){
for
(
String
s:
queryV
){
if
(
s
.
length
()>
8
){
if
(
s
.
length
()>
8
){
return
JsonResult
.
buildErrorStateResult
(
"查询的userId"
+
s
+
"长度超过8位"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"查询的userId"
+
s
+
"长度超过8位"
,
null
);
}
}
long
uid
=
Long
.
valueOf
(
s
);
long
uid
=
Long
.
valueOf
(
s
);
userIds
.
add
(
uid
);
userIds
.
add
(
uid
);
}
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
return
JsonResult
.
buildErrorStateResult
(
"查询的userId有误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"查询的userId有误"
,
null
);
}
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
userIds
,
null
,
null
,
pageId
,
pageSize
,
"auto"
);
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
userIds
,
null
,
null
,
pageId
,
pageSize
,
"auto"
);
}
else
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
)){
}
else
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
)){
for
(
String
pn:
queryV
){
for
(
String
pn:
queryV
){
...
@@ -208,7 +192,6 @@ public class UserQueryLogController {
...
@@ -208,7 +192,6 @@ public class UserQueryLogController {
return
JsonResult
.
buildErrorStateResult
(
"查询的手机号码"
+
pn
+
"格式有误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"查询的手机号码"
+
pn
+
"格式有误"
,
null
);
}
}
}
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
queryV
,
null
,
pageId
,
pageSize
,
"auto"
);
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
queryV
,
null
,
pageId
,
pageSize
,
"auto"
);
}
else
if
(
Objects
.
equals
(
key
,
"idNo"
)){
}
else
if
(
Objects
.
equals
(
key
,
"idNo"
)){
IdcardValidator
iv
=
new
IdcardValidator
();
IdcardValidator
iv
=
new
IdcardValidator
();
...
@@ -219,14 +202,11 @@ public class UserQueryLogController {
...
@@ -219,14 +202,11 @@ public class UserQueryLogController {
}
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
null
,
queryV
,
pageId
,
pageSize
,
"auto"
);
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
null
,
queryV
,
pageId
,
pageSize
,
"auto"
);
}
}
if
(
userDetailPage
!=
null
){
if
(
userDetailPage
!=
null
){
userDetails
=
userDetailPage
.
getContent
();
userDetails
=
userDetailPage
.
getContent
();
}
}
if
(
columns
.
contains
(
"bankCard"
)){
if
(
columns
.
contains
(
"bankCard"
)){
//需加银行卡信息
//需加银行卡信息
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
)){
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
)){
phonesCards
=
getBankCardsByPhoneNos
(
queryV
);
phonesCards
=
getBankCardsByPhoneNos
(
queryV
);
if
(
phonesCards
!=
null
&&
phonesCards
.
get
(
"errorMsg"
)!=
null
&&!
StringUtils
.
isEmpty
(
phonesCards
.
get
(
"errorMsg"
))){
if
(
phonesCards
!=
null
&&
phonesCards
.
get
(
"errorMsg"
)!=
null
&&!
StringUtils
.
isEmpty
(
phonesCards
.
get
(
"errorMsg"
))){
...
@@ -242,9 +222,7 @@ public class UserQueryLogController {
...
@@ -242,9 +222,7 @@ public class UserQueryLogController {
return
JsonResult
.
buildErrorStateResult
(
phonesCards
.
get
(
"errorMsg"
),
null
);
return
JsonResult
.
buildErrorStateResult
(
phonesCards
.
get
(
"errorMsg"
),
null
);
}
}
}
}
}
}
if
(
columns
.
contains
(
"address"
)){
if
(
columns
.
contains
(
"address"
)){
List
<
Long
>
uidss
=
new
ArrayList
<
Long
>();
List
<
Long
>
uidss
=
new
ArrayList
<
Long
>();
//加地址信息
//加地址信息
...
@@ -254,9 +232,7 @@ public class UserQueryLogController {
...
@@ -254,9 +232,7 @@ public class UserQueryLogController {
if
(
uidss
!=
null
&&
uidss
.
size
()>
0
){
if
(
uidss
!=
null
&&
uidss
.
size
()>
0
){
addresslist
=
addressService
.
findByUserIds
(
uidss
);
addresslist
=
addressService
.
findByUserIds
(
uidss
);
}
}
}
}
for
(
UserDetail
ud:
userDetails
){
for
(
UserDetail
ud:
userDetails
){
UserQueryInfo
uqi
=
new
UserQueryInfo
();
UserQueryInfo
uqi
=
new
UserQueryInfo
();
if
(
columns
.
contains
(
"idNo"
)){
if
(
columns
.
contains
(
"idNo"
)){
...
@@ -280,11 +256,8 @@ public class UserQueryLogController {
...
@@ -280,11 +256,8 @@ public class UserQueryLogController {
if
(
columns
.
contains
(
"bankCard"
)&&
phonesCards
!=
null
){
if
(
columns
.
contains
(
"bankCard"
)&&
phonesCards
!=
null
){
uqi
.
setBankCards
(
phonesCards
.
get
(
ud
.
getPhoneNo
()));
uqi
.
setBankCards
(
phonesCards
.
get
(
ud
.
getPhoneNo
()));
}
}
userQueryInfos
.
add
(
uqi
);
userQueryInfos
.
add
(
uqi
);
}
}
//保存记录
//保存记录
UserQueryLog
log
=
new
UserQueryLog
();
UserQueryLog
log
=
new
UserQueryLog
();
log
.
setQueryItems
(
columns
.
replace
(
"userId"
,
"用户ID"
).
replace
(
Constants
.
PHONE_NO
,
"手机号"
).
replace
(
"name"
,
"姓名"
).
replace
(
"idNo"
,
"身份证号"
).
replace
(
"bankCard"
,
"银行卡号"
).
replace
(
"address"
,
"地址"
));
log
.
setQueryItems
(
columns
.
replace
(
"userId"
,
"用户ID"
).
replace
(
Constants
.
PHONE_NO
,
"手机号"
).
replace
(
"name"
,
"姓名"
).
replace
(
"idNo"
,
"身份证号"
).
replace
(
"bankCard"
,
"银行卡号"
).
replace
(
"address"
,
"地址"
));
...
@@ -294,14 +267,12 @@ public class UserQueryLogController {
...
@@ -294,14 +267,12 @@ public class UserQueryLogController {
log
.
setQueryDetail
(
keyValues
.
replace
(
"\n"
,
";"
));
log
.
setQueryDetail
(
keyValues
.
replace
(
"\n"
,
";"
));
log
.
setLoginUserName
(
userName
);
log
.
setLoginUserName
(
userName
);
userQueryLogService
.
save
(
log
);
userQueryLogService
.
save
(
log
);
PageModel
<
UserQueryInfo
>
uqi
=
new
PageModel
<
UserQueryInfo
>();
PageModel
<
UserQueryInfo
>
uqi
=
new
PageModel
<
UserQueryInfo
>();
uqi
.
setPageId
(
pageId
);
uqi
.
setPageId
(
pageId
);
uqi
.
setPageList
(
userQueryInfos
);
uqi
.
setPageList
(
userQueryInfos
);
uqi
.
setPageSize
(
pageSize
);
uqi
.
setPageSize
(
pageSize
);
uqi
.
setPages
(
userDetailPage
.
getTotalPages
());
uqi
.
setPages
(
userDetailPage
.
getTotalPages
());
uqi
.
setTotal
(
userDetailPage
.
getTotalElements
());
uqi
.
setTotal
(
userDetailPage
.
getTotalElements
());
return
JsonResult
.
buildSuccessResult
(
"查询成功"
,
uqi
);
return
JsonResult
.
buildSuccessResult
(
"查询成功"
,
uqi
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
bd3cfec0
...
@@ -221,29 +221,27 @@ public class WeChatController implements IBaseController {
...
@@ -221,29 +221,27 @@ public class WeChatController implements IBaseController {
if
(
Objects
.
equals
(
schema
,
"https:"
)){
if
(
Objects
.
equals
(
schema
,
"https:"
)){
domain
=
userUiDomainS
;
domain
=
userUiDomainS
;
}
}
// 从code获取token
// 从code获取token
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
systemKey
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
AccessTokenResponse
token
=
wechatService
.
getToken
(
code
);
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:merchant:{},token:{}"
,
merchant
,
token
);
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:merchant:{},token:{}"
,
merchant
,
token
);
if
(
token
==
null
)
{
if
(
Objects
.
isNull
(
token
)
||
StringUtils
.
isBlank
(
token
.
getOpenId
())
)
{
// 让用户登录,不关联微信, 构造不关联微信的url
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
return
;
}
}
WechatUserInfo
userInfo
=
// 获取已授权信息 - db
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
token
.
getOpenId
());
token
.
getOpenId
());
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:WechatUserInfo - from DB:{}"
,
userInfoInDb
);
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:WechatUserInfo - from wechat api:{}"
,
userInfo
);
if
(
userInfo
==
null
||
StringUtils
.
isEmpty
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
}
WechatUserInfo
userInfoInDb
=
wechatService
.
findWechatUserInfoFromDb
(
userInfo
.
getOpenId
());
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:WechatUserInfo - from DB:{}"
,
userInfo
);
// welcome 首次登录
// welcome 首次登录
if
(
userInfoInDb
==
null
)
{
if
(
Objects
.
isNull
(
userInfoInDb
))
{
WechatUserInfo
userInfo
=
wechatService
.
getWechatUserInfoFromWechatServer
(
token
.
getAccessToken
(),
token
.
getOpenId
());
LOGGER
.
info
(
"[WeChatController][receiveCodeWithDefault]微信授权及跳转:WechatUserInfo - from wechat api:{}"
,
userInfo
);
if
(
Objects
.
isNull
(
userInfo
)
||
StringUtils
.
isBlank
(
userInfo
.
getOpenId
()))
{
// 让用户登录,不关联微信, 构造不关联微信的url
redirectNormalUrl
(
response
,
merchant
,
registerFrom
,
domain
);
return
;
}
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
// 微信用户首次登录界面, 首先保存userInfo, 跳入到微信注册登录界面
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
if
(
StringUtils
.
isNotBlank
(
userInfo
.
getNickName
()))
{
// 替换所有,UTF-8编码时4字节的Emoji表情字符
// 替换所有,UTF-8编码时4字节的Emoji表情字符
...
@@ -260,13 +258,14 @@ public class WeChatController implements IBaseController {
...
@@ -260,13 +258,14 @@ public class WeChatController implements IBaseController {
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
domain
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfo
,
registerFrom
,
domain
);
return
;
return
;
}
}
if
(
userInfoInDb
.
getUserId
()
==
null
)
{
if
(
Objects
.
isNull
(
userInfoInDb
.
getUserId
())
)
{
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
// 用户已经微信登录了,但是没有关联信用钱包,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
return
;
return
;
}
}
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
User
user
=
userService
.
findById
(
userInfoInDb
.
getUserId
());
if
(
user
==
null
)
{
if
(
Objects
.
isNull
(
user
))
{
// 用户已经微信登录了,但是关联信用钱包用户信息无效,跳转到注册页面
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
redirectWechatLoginUrlWithoutLogin
(
response
,
merchant
,
userInfoInDb
,
registerFrom
,
domain
);
return
;
return
;
}
}
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
View file @
bd3cfec0
...
@@ -174,12 +174,11 @@ public class UserDetailServiceImpl implements IUserDetailService {
...
@@ -174,12 +174,11 @@ public class UserDetailServiceImpl implements IUserDetailService {
return
new
PageRequest
(
pageNumber
-
1
,
pagzSize
,
sort
);
return
new
PageRequest
(
pageNumber
-
1
,
pagzSize
,
sort
);
}
}
@Override
public
Page
<
UserDetail
>
getUserDetailsPage
(
List
<
Long
>
userId
,
List
<
String
>
phoneNos
,
List
<
String
>
idNos
,
int
pageNumber
,
int
pageSize
,
public
Page
<
UserDetail
>
getUserDetailsPage
(
List
<
Long
>
userId
,
List
<
String
>
phoneNos
,
List
<
String
>
idNos
,
int
pageNumber
,
int
pageSize
,
String
sortType
)
{
String
sortType
)
{
PageRequest
pageRequest
=
buildPageRequest
(
pageNumber
,
pageSize
,
sortType
);
PageRequest
pageRequest
=
buildPageRequest
(
pageNumber
,
pageSize
,
sortType
);
Specification
<
UserDetail
>
spec
=
valueInSpecification
(
userId
,
phoneNos
,
idNos
);
Specification
<
UserDetail
>
spec
=
valueInSpecification
(
userId
,
phoneNos
,
idNos
);
return
userDetailRepository
.
findAll
(
spec
,
pageRequest
);
return
userDetailRepository
.
findAll
(
spec
,
pageRequest
);
}
}
...
...
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