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
423b1579
Commit
423b1579
authored
Jun 28, 2023
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify user detail.
parent
3fca5558
Changes
39
Show whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
473 additions
and
958 deletions
+473
-958
update-20230621.sql
doc/sql/update-20230621.sql
+26
-0
UserConstant.java
src/main/java/cn/quantgroup/xyqb/constant/UserConstant.java
+3
-0
UserController.java
...n/quantgroup/xyqb/controller/external/UserController.java
+21
-15
PlatformApiController.java
...b/controller/external/platform/PlatformApiController.java
+2
-2
UserQueryLogController.java
.../controller/internal/querylog/UserQueryLogController.java
+5
-201
InnerController.java
...tgroup/xyqb/controller/internal/user/InnerController.java
+50
-181
SyncUserController.java
...oup/xyqb/controller/internal/user/SyncUserController.java
+21
-17
UserCenterController.java
...controller/internal/user/center/UserCenterController.java
+6
-10
UserDetailController.java
...troller/middleoffice/userdetail/UserDetailController.java
+16
-15
UserExtController.java
...qb/controller/middleoffice/userext/UserExtController.java
+6
-9
ModifyPhoneNoResp.java
...xyqb/controller/modifyphoneno/resp/ModifyPhoneNoResp.java
+3
-2
UserModifyPhoneRecordResp.java
...troller/modifyphoneno/resp/UserModifyPhoneRecordResp.java
+4
-3
BaseEntity.java
src/main/java/cn/quantgroup/xyqb/entity/BaseEntity.java
+9
-8
User.java
src/main/java/cn/quantgroup/xyqb/entity/User.java
+3
-0
UserInfoEntity.java
src/main/java/cn/quantgroup/xyqb/entity/UserInfoEntity.java
+50
-0
LocalDateAttributeConverter.java
...up/xyqb/entity/converter/LocalDateAttributeConverter.java
+19
-0
LocalDateTimeAttributeConverter.java
...yqb/entity/converter/LocalDateTimeAttributeConverter.java
+19
-0
DetailRegisteredEventListener.java
.../quantgroup/xyqb/event/DetailRegisteredEventListener.java
+5
-7
UserDetailUpdateEvent.java
.../java/cn/quantgroup/xyqb/event/UserDetailUpdateEvent.java
+0
-24
UserDisableRecordModel.java
...java/cn/quantgroup/xyqb/model/UserDisableRecordModel.java
+32
-30
UserFullInfo.java
src/main/java/cn/quantgroup/xyqb/model/UserFullInfo.java
+5
-5
UserInfo.java
src/main/java/cn/quantgroup/xyqb/model/UserInfo.java
+4
-4
UserInfoRet.java
src/main/java/cn/quantgroup/xyqb/model/UserInfoRet.java
+74
-0
UserModel.java
src/main/java/cn/quantgroup/xyqb/model/UserModel.java
+2
-2
UserRegisterMqMessage.java
.../java/cn/quantgroup/xyqb/model/UserRegisterMqMessage.java
+4
-3
UserRet.java
src/main/java/cn/quantgroup/xyqb/model/UserRet.java
+3
-2
IUserDetailRepository.java
.../cn/quantgroup/xyqb/repository/IUserDetailRepository.java
+0
-59
IUserInfoRepository.java
...va/cn/quantgroup/xyqb/repository/IUserInfoRepository.java
+38
-0
UserApiServiceImpl.java
.../quantgroup/xyqb/service/api/impl/UserApiServiceImpl.java
+6
-5
PageServiceImpl.java
...cn/quantgroup/xyqb/service/page/impl/PageServiceImpl.java
+5
-4
IUserDetailService.java
...a/cn/quantgroup/xyqb/service/user/IUserDetailService.java
+0
-54
IUserService.java
...in/java/cn/quantgroup/xyqb/service/user/IUserService.java
+3
-3
ModifyPhoneNoServiceImpl.java
...roup/xyqb/service/user/impl/ModifyPhoneNoServiceImpl.java
+4
-9
UserDetailServiceImpl.java
...ntgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
+0
-253
UserServiceImpl.java
...cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
+10
-12
JsonTest.java
src/test/java/common/JsonTest.java
+8
-9
RepsitoryJpaTest.java
src/test/java/demo/RepsitoryJpaTest.java
+2
-3
RepsitoryTest.java
src/test/java/demo/RepsitoryTest.java
+3
-4
ServiceTest.java
src/test/java/demo/ServiceTest.java
+2
-3
No files found.
doc/sql/update-20230621.sql
View file @
423b1579
----新增用户资料表
CREATE
TABLE
`xyqb_user`
.
`user_info`
(
`id`
BIGINT
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`user_id`
BIGINT
(
20
)
NOT
NULL
COMMENT
'用户表id'
,
`phone_no`
VARCHAR
(
20
)
NULL
COMMENT
'手机号码'
,
`gender`
TINYINT
(
3
)
NULL
COMMENT
'性别'
,
`email`
VARCHAR
(
45
)
NULL
COMMENT
'邮箱'
,
`qq`
VARCHAR
(
20
)
NULL
COMMENT
'腾讯qq'
,
`nick_name`
VARCHAR
(
45
)
NULL
COMMENT
'昵称'
,
`photo`
VARCHAR
(
255
)
NULL
COMMENT
'头像地址'
,
`birthday`
DATE
NULL
COMMENT
'生日'
,
`province_id`
INT
NULL
COMMENT
'地址省份id'
,
`city_id`
INT
NULL
COMMENT
'地址市id'
,
`address`
VARCHAR
(
255
)
NULL
COMMENT
'详细地址'
,
`tenant_id`
INT
NOT
NULL
COMMENT
'租户id'
,
`created_at`
TIMESTAMP
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_at`
TIMESTAMP
NULL
DEFAULT
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
`id`
),
INDEX
`idx_user_id`
(
`user_id`
ASC
),
INDEX
`idx_user_phone`
(
`phone_no`
ASC
)
);
ALTER
TABLE
`xyqb_user`
.
`user`
ADD
COLUMN
`tenant_id`
INT
NULL
COMMENT
'租户id'
AFTER
`cipher_password`
;
src/main/java/cn/quantgroup/xyqb/constant/UserConstant.java
View file @
423b1579
...
...
@@ -6,4 +6,7 @@ public class UserConstant {
public
static
final
String
USER_ERROR_OR_ENABLE_ERROR
=
"账号异常,请联系平台客服。"
;
public
static
final
String
USER_FREEZE_ERROR
=
"账号异常,已冻结。"
;
public
static
final
Integer
defaultTenantId
=
1028
;
public
static
final
String
defaultTenantIdString
=
"1028"
;
}
src/main/java/cn/quantgroup/xyqb/controller/external/UserController.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
;
import
cn.quantgroup.xyqb.constant.enums.LoginType
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.accessable.IpValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaFiniteValidator
;
...
...
@@ -8,6 +7,8 @@ import cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator;
import
cn.quantgroup.xyqb.aspect.forbidden.AccessForbiddenValidator
;
import
cn.quantgroup.xyqb.aspect.limit.PasswordFreeAccessValidator
;
import
cn.quantgroup.xyqb.aspect.lock.PasswordErrorFiniteValidator
;
import
cn.quantgroup.xyqb.constant.UserConstant
;
import
cn.quantgroup.xyqb.constant.enums.LoginType
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.entity.*
;
import
cn.quantgroup.xyqb.exception.UserNotExistException
;
...
...
@@ -15,13 +16,17 @@ import cn.quantgroup.xyqb.exception.VerificationCodeErrorException;
import
cn.quantgroup.xyqb.model.*
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionValue
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestLogService
;
import
cn.quantgroup.xyqb.service.http.IHttpService
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.register.IUserRegisterService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.service.user.*
;
import
cn.quantgroup.xyqb.service.user.ILockIpv4Service
;
import
cn.quantgroup.xyqb.service.user.ILoginRecordService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.UserCenterService
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.session.XyqbSessionContextHolder
;
import
cn.quantgroup.xyqb.util.*
;
...
...
@@ -73,7 +78,7 @@ public class UserController implements IBaseController {
private
ISessionService
sessionService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Autowired
private
IMerchantService
merchantService
;
@Autowired
...
...
@@ -450,7 +455,7 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
// 优先校验新的密码
if
(
StringUtils
.
isNotBlank
(
user
.
getCipherPassword
())
)
{
if
(
StringUtils
.
isNotBlank
(
user
.
getCipherPassword
()))
{
if
(!
BctyptPasswordUtil
.
BCryptCheckPw
(
password
,
user
.
getCipherPassword
()))
{
return
JsonResult
.
buildErrorStateResult
(
"修改密码失败"
,
null
);
}
...
...
@@ -537,7 +542,6 @@ public class UserController implements IBaseController {
/**
* token 交换
*
*/
@RequestMapping
(
"/tokenExchange"
)
public
JsonResult
tokenExchange
(
@RequestParam
String
token
,
@RequestParam
(
required
=
false
)
Integer
tenantId
)
{
...
...
@@ -565,6 +569,7 @@ public class UserController implements IBaseController {
/**
* 交换token
*
* @param token
* @return
*/
...
...
@@ -580,7 +585,8 @@ public class UserController implements IBaseController {
try
{
String
resultStr
=
httpService
.
post
(
userHost
+
"/api/finance-gateway/finance-user/finance/tokenExchange"
,
headers
,
parameters
);
JsonResult
<
TokenExchange
>
tokenExchangeResult
=
JSONObject
.
parseObject
(
resultStr
,
new
TypeReference
<
JsonResult
<
TokenExchange
>>(){});
JsonResult
<
TokenExchange
>
tokenExchangeResult
=
JSONObject
.
parseObject
(
resultStr
,
new
TypeReference
<
JsonResult
<
TokenExchange
>>()
{
});
// 如果有返回值
TokenExchange
tokenExchange
=
tokenExchangeResult
.
getData
();
if
(
tokenExchange
!=
null
)
{
...
...
@@ -610,7 +616,8 @@ public class UserController implements IBaseController {
@AccessForbiddenValidator
@PasswordFreeAccessValidator
@RequestMapping
(
"/center/index"
)
public
JsonResult
userCenterIndex
()
{
public
JsonResult
userCenterIndex
(
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
UserBrief
brief
=
new
UserBrief
();
//TODO:he 返回"",待解决
...
...
@@ -620,7 +627,7 @@ public class UserController implements IBaseController {
brief
.
setAvatar
(
userAttached
.
getAvatar
());
brief
.
setNick
(
userAttached
.
getNick
());
}
User
Detail
userDetail
=
userDetailService
.
findSlaveByUserId
(
user
Id
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
if
(
userDetail
!=
null
)
{
brief
.
setName
(
userDetail
.
getName
());
brief
.
setSex
(
Optional
.
ofNullable
(
userDetail
.
getGender
()).
orElse
(
cn
.
quantgroup
.
xyqb
.
model
.
Gender
.
UNKNOWN
).
ordinal
()
+
""
);
...
...
@@ -638,13 +645,12 @@ public class UserController implements IBaseController {
*/
@Deprecated
@RequestMapping
(
"/syncUserInfo"
)
public
JsonResult
syncUserInfo
(
HttpServletRequest
request
)
{
log
.
error
(
"[监控][UserController][syncUserInfo] request-Header:{}"
,
JSON
.
toJSONString
(
getRequestHeaderMap
(
request
)));
public
JsonResult
syncUserInfo
()
{
User
user
=
getCurrentUserFromRedis
();
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
User
Detail
detail
=
userDetailService
.
findByUserId
(
user
.
ge
tId
());
User
InfoEntity
detail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
user
.
getTenan
tId
());
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
"token校验成功"
,
userModel
);
}
...
...
@@ -683,8 +689,8 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"登录时微信关联失败"
,
null
);
}
LoginProperties
loginProperties
=
new
LoginProperties
(
""
,
1
,
channelId
,
createdFrom
,
appChannel
,
merchant
.
getId
(),
merchant
.
getName
(),
null
);
AuthBean
authBean
=
sessionService
.
createSession
(
user
,
loginProperties
,
LoginType
.
ACCOUNTPASSWORD
.
ordinal
());
if
(
authBean
!=
null
)
{
AuthBean
authBean
=
sessionService
.
createSession
(
user
,
loginProperties
,
LoginType
.
ACCOUNTPASSWORD
.
ordinal
());
if
(
authBean
!=
null
)
{
authBean
.
setRegister
(
false
);
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/platform/PlatformApiController.java
View file @
423b1579
...
...
@@ -7,9 +7,9 @@ import cn.quantgroup.xyqb.entity.MerchantConfig;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.Tuple
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.page.IPageService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
com.google.common.collect.ImmutableMap
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -29,7 +29,7 @@ public class PlatformApiController implements IBaseController {
@Autowired
private
IMerchantService
merchantService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@RequestMapping
(
"/page/return_url"
)
public
JsonResult
returnUrl
(
String
key
)
{
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/querylog/UserQueryLogController.java
View file @
423b1579
...
...
@@ -2,14 +2,14 @@ package cn.quantgroup.xyqb.controller.internal.querylog;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.forbidden.AccessForbiddenValidator
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.entity.UserQueryLog
;
import
cn.quantgroup.xyqb.exception.UserQueryLogException
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.PageModel
;
import
cn.quantgroup.xyqb.model.UserQueryInfo
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.http.IHttpService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserQueryLogService
;
import
cn.quantgroup.xyqb.util.IdcardValidator
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
...
...
@@ -45,8 +45,9 @@ public class UserQueryLogController {
@Autowired
private
IUserQueryLogService
userQueryLogService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Value
(
"${payapi.http}"
)
...
...
@@ -119,90 +120,6 @@ public class UserQueryLogController {
}
}
/**
* @yapi http://yapi.quantgroups.com/project/17/interface/api/261
*/
@AccessForbiddenValidator
@RequestMapping
(
"/queryUserInfo"
)
public
JsonResult
queryForResult
(
HttpServletRequest
request
,
String
key
,
String
keyValues
,
String
columns
,
Integer
pageId
,
Integer
pageSize
)
{
String
token
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
String
userName
=
checkUserToken
(
token
);
if
(
StringUtils
.
isEmpty
(
keyValues
))
{
return
JsonResult
.
buildErrorStateResult
(
"请输入查询条件"
,
null
);
}
// 支持
String
[]
values
=
keyValues
.
split
(
";|,|\\n"
);
List
<
String
>
queryV
=
Arrays
.
asList
(
values
);
log
.
info
(
"[UserQueryLogController][exportExcel]运营系统导出用户信息开始 size:{}, key:{}, keyValues:{}, columns:{}"
,
queryV
.
size
(),
key
,
keyValues
,
columns
);
if
(
queryV
!=
null
&&
queryV
.
size
()
>
Constants
.
USER_QUERY_INFO_BATCH_SIZE
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询记录数是"
+
queryV
.
size
()
+
",超过"
+
Constants
.
USER_QUERY_INFO_BATCH_SIZE
+
"条限制"
,
null
);
}
List
<
UserDetail
>
userDetails
=
new
ArrayList
<>();
Page
<
UserDetail
>
userDetailPage
=
null
;
if
(
pageSize
==
0
||
pageSize
<
0
)
{
pageSize
=
Constants
.
PAGE_SIZE_DEFAULT
;
}
else
if
(
pageSize
>
Constants
.
PAGE_SIZE_MAX
)
{
pageSize
=
Constants
.
PAGE_SIZE_MAX
;
}
//如果维度里面没有保护查询条件则加入条件
if
(!
columns
.
contains
(
key
))
{
columns
=
columns
+
","
+
key
;
}
if
(
Objects
.
equals
(
key
,
Constants
.
USER_ID
))
{
List
<
Long
>
userIds
=
new
ArrayList
<>();
try
{
for
(
String
s
:
queryV
)
{
if
(
s
.
length
()
>
8
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询的userId"
+
s
+
"长度超过8位"
,
null
);
}
long
uid
=
Long
.
valueOf
(
s
);
userIds
.
add
(
uid
);
}
}
catch
(
Exception
e
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询的userId有误"
,
null
);
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
userIds
,
null
,
null
,
pageId
,
pageSize
,
"auto"
);
}
else
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
))
{
for
(
String
pn
:
queryV
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
pn
))
{
return
JsonResult
.
buildErrorStateResult
(
"查询的手机号码"
+
pn
+
"格式有误"
,
null
);
}
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
queryV
,
null
,
pageId
,
pageSize
,
"auto"
);
}
else
if
(
Objects
.
equals
(
key
,
Constants
.
ID_NO
))
{
for
(
String
idno
:
queryV
)
{
if
(!
IdcardValidator
.
is18Idcard
(
idno
)
&&
!
IdcardValidator
.
is15Idcard
(
idno
))
{
return
JsonResult
.
buildErrorStateResult
(
"查询的身份证号"
+
idno
+
"格式有误"
,
null
);
}
}
userDetailPage
=
userDetailService
.
getUserDetailsPage
(
null
,
null
,
queryV
,
pageId
,
pageSize
,
"auto"
);
}
if
(
userDetailPage
!=
null
)
{
userDetails
=
userDetailPage
.
getContent
();
}
List
<
UserQueryInfo
>
userQueryInfos
=
toUserQueryInfo
(
key
,
columns
,
queryV
,
userDetails
);
//保存记录
UserQueryLog
log
=
new
UserQueryLog
();
log
.
setQueryItems
(
columns
.
replace
(
Constants
.
USER_ID
,
"用户ID"
).
replace
(
Constants
.
PHONE_NO
,
"手机号"
).
replace
(
Constants
.
USER_NAME
,
"姓名"
).
replace
(
Constants
.
ID_NO
,
"身份证号"
).
replace
(
Constants
.
BANK_CARD
,
"银行卡号"
).
replace
(
Constants
.
ADDRESS
,
"地址"
));
if
(
userDetailPage
!=
null
){
log
.
setResultAmount
(
userDetailPage
.
getTotalElements
());
}
//转换存储
log
.
setQueryCondition
(
key
.
replace
(
Constants
.
USER_ID
,
"用户ID"
).
replace
(
Constants
.
PHONE_NO
,
"手机号"
).
replace
(
Constants
.
USER_NAME
,
"姓名"
).
replace
(
Constants
.
ID_NO
,
"身份证号"
));
log
.
setQueryDetail
(
keyValues
.
replace
(
"\n"
,
";"
));
log
.
setLoginUserName
(
userName
);
userQueryLogService
.
save
(
log
);
PageModel
<
UserQueryInfo
>
uqi
=
new
PageModel
<>();
uqi
.
setPageId
(
pageId
);
uqi
.
setPageList
(
userQueryInfos
);
uqi
.
setPageSize
(
pageSize
);
if
(
userDetailPage
!=
null
){
uqi
.
setPages
(
userDetailPage
.
getTotalPages
());
uqi
.
setTotal
(
userDetailPage
.
getTotalElements
());
}
return
JsonResult
.
buildSuccessResult
(
"查询成功"
,
uqi
);
}
private
HashMap
<
String
,
String
>
getBankCardsByPhoneNos
(
List
<
String
>
phoneNos
)
{
HashMap
<
String
,
Object
>
ha
=
new
HashMap
<>();
ha
.
put
(
"type"
,
"1"
);
...
...
@@ -260,119 +177,6 @@ public class UserQueryLogController {
return
phonesMap
;
}
/**
* @yapi http://yapi.quantgroups.com/project/17/interface/api/257
*/
@RequestMapping
(
"/exportUserInfo"
)
public
JsonResult
exportExcel
(
final
HttpServletResponse
response
,
HttpServletRequest
request
,
String
key
,
String
keyValues
,
String
columns
)
{
String
token
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
checkUserToken
(
token
);
if
(
StringUtils
.
isEmpty
(
keyValues
))
{
return
JsonResult
.
buildErrorStateResult
(
"请输入查询条件"
,
null
);
}
String
[]
values
=
keyValues
.
split
(
";"
);
List
<
String
>
queryV
=
Arrays
.
asList
(
values
);
log
.
info
(
"[UserQueryLogController][exportExcel]运营系统导出用户信息开始 size:{}, key:{}, keyValues:{}, columns:{}"
,
queryV
.
size
(),
key
,
keyValues
,
columns
);
if
(
queryV
!=
null
&&
queryV
.
size
()
>
Constants
.
USER_QUERY_INFO_BATCH_SIZE
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询记录数是"
+
queryV
.
size
()
+
",超过"
+
Constants
.
USER_QUERY_INFO_BATCH_SIZE
+
"条限制"
,
null
);
}
//如果维度里面没有保护查询条件则加入条件
if
(!
columns
.
contains
(
key
))
{
columns
=
columns
+
","
+
key
;
}
List
<
UserDetail
>
userDetails
=
new
ArrayList
<>();
if
(
Objects
.
equals
(
key
,
Constants
.
USER_ID
))
{
List
<
Long
>
userIds
=
new
ArrayList
<>();
try
{
for
(
String
s
:
queryV
)
{
if
(
s
.
length
()
>
8
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询的userId"
+
s
+
"长度超过8位"
,
s
);
}
long
uid
=
Long
.
valueOf
(
s
);
userIds
.
add
(
uid
);
}
}
catch
(
Exception
e
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询的userId有误"
,
null
);
}
userDetails
=
userDetailService
.
findByUserIdIn
(
userIds
);
}
else
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
))
{
for
(
String
pn
:
queryV
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
pn
))
{
return
JsonResult
.
buildErrorStateResult
(
"查询的手机号码"
+
pn
+
"格式有误"
,
pn
);
}
}
userDetails
=
userDetailService
.
findByPhoneNos
(
queryV
);
}
List
<
UserQueryInfo
>
userQueryInfos
=
toUserQueryInfo
(
key
,
columns
,
queryV
,
userDetails
);
/*
* 将文件存到指定位置
* 采用时间戳命名方式,避免同主机出现并发同名文件冲突引起的文件流被动关闭现象
*/
try
(
OutputStream
output
=
response
.
getOutputStream
()){
String
filename
=
"users-"
.
concat
(
LocalDateTime
.
now
().
toString
()).
concat
(
".xlsx"
);
response
.
reset
();
response
.
setHeader
(
"Content-disposition"
,
"attachment; filename="
.
concat
(
filename
));
response
.
setContentType
(
"application/vnd.ms-excel;charset=utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
HSSFWorkbook
wb
=
getHssfWorkbook
(
userQueryInfos
);
wb
.
write
(
output
);
log
.
info
(
"[UserQueryLogController][exportExcel]运营系统导出用户信息完成 filename:{}, size:{}, key:{}, keyValues:{}, columns:{}"
,
filename
,
queryV
.
size
(),
key
,
keyValues
,
columns
);
}
catch
(
Exception
e
)
{
log
.
error
(
"解析运营系统用户token返回结果resultStr异常"
,
e
);
}
return
JsonResult
.
buildSuccessResult
(
"导出成功"
,
null
);
}
/**
* 数据类型转换
*
* @param key
* @param columns
* @param queryV
* @param userDetails
* @return
*/
private
List
<
UserQueryInfo
>
toUserQueryInfo
(
String
key
,
String
columns
,
List
<
String
>
queryV
,
List
<
UserDetail
>
userDetails
)
{
HashMap
<
String
,
String
>
phonesCards
=
new
HashMap
<>();
if
(
columns
.
contains
(
Constants
.
BANK_CARD
))
{
//需加银行卡信息
if
(
Objects
.
equals
(
key
,
Constants
.
PHONE_NO
))
{
phonesCards
=
getBankCardsByPhoneNos
(
queryV
);
}
else
{
List
<
String
>
phones
=
new
ArrayList
<>();
for
(
UserDetail
uda
:
userDetails
)
{
phones
.
add
(
uda
.
getPhoneNo
());
}
phonesCards
=
getBankCardsByPhoneNos
(
phones
);
}
}
if
(
columns
.
contains
(
Constants
.
ADDRESS
))
{
List
<
Long
>
uidss
=
new
ArrayList
<>();
//加地址信息
for
(
UserDetail
ud
:
userDetails
)
{
uidss
.
add
(
ud
.
getUserId
());
}
}
List
<
UserQueryInfo
>
userQueryInfos
=
new
ArrayList
<>();
for
(
UserDetail
ud
:
userDetails
)
{
UserQueryInfo
uqi
=
new
UserQueryInfo
();
if
(
columns
.
contains
(
Constants
.
PHONE_NO
))
{
uqi
.
setPhoneNo
(
ud
.
getPhoneNo
());
}
if
(
columns
.
contains
(
Constants
.
USER_NAME
))
{
uqi
.
setName
(
ud
.
getName
());
}
if
(
columns
.
contains
(
Constants
.
USER_ID
))
{
uqi
.
setUserId
(
ud
.
getUserId
());
}
if
(
columns
.
contains
(
Constants
.
BANK_CARD
)
&&
phonesCards
!=
null
)
{
uqi
.
setBankCards
(
phonesCards
.
get
(
ud
.
getPhoneNo
()));
}
userQueryInfos
.
add
(
uqi
);
}
return
userQueryInfos
;
}
/**
* 生成Excel
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/InnerController.java
View file @
423b1579
...
...
@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.controller.internal.user;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.accessable.IpValidator
;
import
cn.quantgroup.xyqb.aspect.forbidden.AccessForbiddenValidator
;
import
cn.quantgroup.xyqb.constant.UserConstant
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.controller.internal.user.resp.UserFullResp
;
import
cn.quantgroup.xyqb.entity.*
;
...
...
@@ -12,6 +13,7 @@ import cn.quantgroup.xyqb.exception.UserNotExistException;
import
cn.quantgroup.xyqb.model.*
;
import
cn.quantgroup.xyqb.remote.StmsRemoteService
;
import
cn.quantgroup.xyqb.repository.IUserDisableRecordRepository
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.api.IUserApiService
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.register.IUserDeregisterService
;
...
...
@@ -19,9 +21,7 @@ import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.service.user.IUserBtRegisterService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.vo.UserDetailVO
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.util.*
;
import
cn.quantgroup.xyqb.util.encrypt.Md5Util
;
...
...
@@ -68,7 +68,7 @@ public class InnerController implements IBaseController {
@Autowired
private
IUserService
userService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Autowired
private
IUserBtRegisterService
userBtRegisterService
;
...
...
@@ -147,7 +147,7 @@ public class InnerController implements IBaseController {
* @yapi http://yapi.quantgroups.com/project/17/interface/api/229
*/
@RequestMapping
(
"/userInfo/search/uuid"
)
public
JsonResult
findUserInfoByUuid
(
@RequestParam
(
value
=
"uuid"
)
String
uuid
)
{
public
JsonResult
findUserInfoByUuid
(
@RequestParam
(
value
=
"uuid"
)
String
uuid
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
log
.
info
(
"需要查询的用户uuidid, uuid:"
+
uuid
);
if
(
StringUtils
.
isBlank
(
uuid
))
{
...
...
@@ -158,7 +158,7 @@ public class InnerController implements IBaseController {
if
(!
user
.
getEnable
())
{
return
JsonResult
.
buildSuccessResult
(
USER_ERROR_OR_ENABLE_ERROR
,
null
);
}
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
UserInfo
info
=
new
UserInfo
(
user
,
userDetail
);
return
JsonResult
.
buildSuccessResult
(
""
,
info
);
}
...
...
@@ -170,7 +170,7 @@ public class InnerController implements IBaseController {
*/
@AccessForbiddenValidator
@RequestMapping
(
"/userInfo/search/phone"
)
public
JsonResult
findUserInfoByPhone
(
@RequestParam
(
value
=
"phone"
)
String
phone
)
{
public
JsonResult
findUserInfoByPhone
(
@RequestParam
(
value
=
"phone"
)
String
phone
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
log
.
info
(
"需要查询的用户phone, phone:"
+
phone
);
if
(
StringUtils
.
isBlank
(
phone
))
{
...
...
@@ -181,7 +181,7 @@ public class InnerController implements IBaseController {
if
(!
user
.
getEnable
())
{
return
JsonResult
.
buildSuccessResult
(
USER_ERROR_OR_ENABLE_ERROR
,
null
);
}
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
UserInfo
info
=
new
UserInfo
(
user
,
userDetail
);
return
JsonResult
.
buildSuccessResult
(
""
,
info
);
}
...
...
@@ -257,7 +257,8 @@ public class InnerController implements IBaseController {
String
phoneNo
,
@ChineseName
@RequestParam
String
name
,
String
idNo
,
String
email
,
String
qq
)
{
String
email
,
String
qq
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
log
.
info
(
"保存用户详细信息,[saveUserDetail] userId:{},phoneNo:{},name:{},idNo:{},email:{},qq:{}"
,
userId
,
phoneNo
,
name
,
idNo
,
email
,
qq
);
...
...
@@ -288,27 +289,27 @@ public class InnerController implements IBaseController {
/*
* 如果已存在记录,则更新
*/
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
user
DetailService
.
findByPhoneNo
(
phoneNo
);
userDetail
=
user
InfoRepository
.
findByPhoneNoAndTenantId
(
phoneNo
,
tenantId
);
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if
(
Objects
.
nonNull
(
userDetail
)
&&
Objects
.
nonNull
(
userDetail
.
getUserId
()))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号已使用."
,
null
);
}
}
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
User
Detail
();
userDetail
=
new
User
InfoEntity
();
}
userDetail
.
setUserId
(
userId
);
userDetail
.
setName
(
name
);
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setEmail
(
email
);
userDetail
.
setQq
(
qq
);
userDetail
=
user
DetailService
.
saveUserDetail
(
userDetail
);
userDetail
=
user
InfoRepository
.
save
(
userDetail
);
log
.
info
(
"InnerController saveUserDetail, userId:{}, phoneNo:{}, name:{}"
,
user
.
getId
(),
phoneNo
,
name
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
User
Detail
Ret
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
null
,
User
Info
Ret
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
...
...
@@ -321,16 +322,16 @@ public class InnerController implements IBaseController {
@AccessForbiddenValidator
@RequestMapping
(
"/user_detail/search/userId"
)
public
JsonResult
findUserDetailByUserId
(
Long
userId
,
Integer
tenantId
)
{
User
Detail
userDetail
=
null
;
User
InfoEntity
userDetail
=
null
;
// 增加容错性,防备DB中存在的脏数据触发异常
if
(
userId
!=
null
&&
userId
>
0
)
{
userDetail
=
user
DetailService
.
findByUserId
(
user
Id
);
userDetail
=
user
InfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
}
if
(
Objects
.
isNull
(
userDetail
))
{
return
JsonResult
.
buildErrorStateResult
(
"该用户无实名信息"
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
"用户实名信息"
,
User
Detail
Ret
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
"用户实名信息"
,
User
Info
Ret
.
getUserDetail
(
userDetail
));
}
/**
...
...
@@ -352,10 +353,9 @@ public class InnerController implements IBaseController {
@AccessForbiddenValidator
@RequestMapping
(
"/user_detail/search/phone"
)
public
JsonResult
findUserDetailByPhone
(
String
phoneNo
,
Integer
tenantId
)
{
UserDetail
userDetail
=
null
;
userDetail
=
userDetailService
.
findSlaveByPhoneNo
(
phoneNo
);
UserInfoEntity
userDetail
=
userInfoRepository
.
findByPhoneNoAndTenantId
(
phoneNo
,
tenantId
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
User
Detail
Ret
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
null
,
User
Info
Ret
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
"该用户详情信息不存在"
,
null
);
...
...
@@ -410,90 +410,29 @@ public class InnerController implements IBaseController {
* @return
*/
@RequestMapping
(
"/user_detail/update"
)
public
JsonResult
updateUserDetail
(
String
qq
,
String
email
,
Long
userId
)
{
public
JsonResult
updateUserDetail
(
String
qq
,
String
email
,
Long
userId
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
Objects
.
isNull
(
userId
)
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId为空"
,
null
);
}
if
(
StringUtils
.
isNotBlank
(
qq
))
{
user
DetailService
.
updateUserQq
(
userId
,
qq
);
user
InfoRepository
.
updateUserQq
(
qq
,
userId
,
tenantId
);
}
if
(
StringUtils
.
isNotBlank
(
email
))
{
user
DetailService
.
updateUserEmail
(
userId
,
email
);
user
InfoRepository
.
updateUserEmail
(
email
,
userId
,
tenantId
);
}
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
@RequestMapping
(
"/user_detail/update/qq"
)
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
)
{
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败,qq或用户id为空"
,
null
);
}
user
DetailService
.
updateUserQq
(
userId
,
qq
);
user
InfoRepository
.
updateUserQq
(
qq
,
userId
,
tenantId
);
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
/**
* 按照姓名、份证号或手机号查询用户实名信息 - 精确查询,供客服用,不限制入参正确性
*
* @param name - 姓名
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @return JsonResult<List < UserDetail>>
*/
@AccessForbiddenValidator
@RequestMapping
(
"/user_detail/search_list"
)
public
JsonResult
<
List
<
UserDetailVO
>>
searchUserDetailList
(
String
name
,
String
phoneNo
,
String
idNo
)
{
log
.
info
(
"searchUserDetailList ,param.name:{},phone:{},idNo:{},ip:{}"
,
name
,
phoneNo
,
idNo
,
getIp
());
if
(
StringUtils
.
isBlank
(
name
)
&&
StringUtils
.
isBlank
(
phoneNo
)
&&
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"至少必须满足一个条件不为空"
,
null
);
}
List
<
UserDetailVO
>
userDetails
=
userDetailService
.
searchUserDetailList
(
name
,
phoneNo
,
idNo
);
return
JsonResult
.
buildSuccessResult
(
"success"
,
userDetails
);
}
/**
* 按照身份证号和手机号查询用户实名信息查询 - 模糊查询
*
* @param phoneNo - 手机号
* @param idNo - 身份证号
* @param userName - 用户姓名
* @return JsonResult<List < UserDetail>>
*/
@RequestMapping
(
"/user_detail/fuzzyQuery"
)
public
JsonResult
<
List
<
UserDetail
>>
fuzzyQueryUserDetailList
(
String
phoneNo
,
String
idNo
,
String
userName
)
{
log
.
info
(
"fuzzyQueryUserDetailList, phone:{},idNo:{},userName:{},ip:{}"
,
phoneNo
,
idNo
,
userName
,
getIp
());
if
(
StringUtils
.
isBlank
(
phoneNo
)
&&
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"查询条件不能为空"
,
null
);
}
//最多掩码四位
int
phoneNoMaskSize
=
7
;
//最多掩码身份证后五位
int
idNoMaskSize
=
13
;
int
idNoFullSize
=
18
;
boolean
phoneNoValid
=
StringUtils
.
isBlank
(
phoneNo
)
?
false
:
(
phoneNo
.
length
()
>=
phoneNoMaskSize
||
ValidationUtil
.
validatePhoneNo
(
phoneNo
));
if
(!
phoneNoValid
)
{
return
JsonResult
.
buildErrorStateResult
(
"查询条件不规范!"
,
null
);
}
List
<
UserDetail
>
userDetailList
=
null
;
userDetailList
=
userDetailService
.
fuzzyQueryByPhoneNo
(
phoneNo
);
// 如果传入姓名,则只过滤匹配项
if
(!
CollectionUtils
.
isEmpty
(
userDetailList
)
&&
StringUtils
.
isNotBlank
(
userName
))
{
userDetailList
=
userDetailList
.
stream
()
.
filter
(
userDetail
->
Objects
.
equals
(
userName
,
userDetail
.
getName
()))
.
collect
(
Collectors
.
toList
());
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
userDetailList
);
}
@RequestMapping
(
"/user/query/openId"
)
public
JsonResult
queryOpenIdByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
...
...
@@ -516,7 +455,7 @@ public class InnerController implements IBaseController {
* @return 详细信息包含: { 账号信息 个人信息 }
*/
@RequestMapping
(
"/user-association/search"
)
public
JsonResult
findUserAssociationModel
(
Long
id
,
String
phoneNo
,
String
uuid
)
{
public
JsonResult
findUserAssociationModel
(
Long
id
,
String
phoneNo
,
String
uuid
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
user
=
null
;
if
(!
Objects
.
isNull
(
id
)
&&
id
>
0
)
{
user
=
userService
.
findById
(
id
);
...
...
@@ -525,9 +464,9 @@ public class InnerController implements IBaseController {
}
else
if
(
StringUtils
.
isNotBlank
(
uuid
))
{
user
=
userService
.
findByUuidWithCache
(
uuid
);
}
User
Detail
userDetail
=
null
;
User
InfoEntity
userDetail
=
null
;
if
(
Objects
.
nonNull
(
user
)
&&
Objects
.
nonNull
(
user
.
getId
())
&&
user
.
getId
()
>
0
)
{
userDetail
=
user
DetailService
.
findByUserId
(
user
.
getId
()
);
userDetail
=
user
InfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
}
if
(
Objects
.
isNull
(
user
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户不存在"
,
""
);
...
...
@@ -542,7 +481,7 @@ public class InnerController implements IBaseController {
* @param user - 用户User
* @return 综合信息模型包含: { 账号信息 个人信息 扩展信息 地址信息 联系人信息 }
*/
private
UserAssociationModel
findUserAssociationModelByUser
(
User
user
)
{
private
UserAssociationModel
findUserAssociationModelByUser
(
User
user
,
Integer
tenantId
)
{
if
(
Objects
.
isNull
(
user
)
||
Objects
.
isNull
(
user
.
getId
())
||
user
.
getId
()
<
1
)
{
return
null
;
}
...
...
@@ -550,7 +489,7 @@ public class InnerController implements IBaseController {
bean
.
setId
(
user
.
getId
());
bean
.
setUuid
(
user
.
getUuid
());
bean
.
setRegisterFrom
(
user
.
getRegisteredFrom
());
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
if
(!
Objects
.
isNull
(
userDetail
))
{
bean
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
bean
.
setName
(
userDetail
.
getName
());
...
...
@@ -569,7 +508,8 @@ public class InnerController implements IBaseController {
RequestMethod
.
POST
})
public
JsonResult
findUserAssociationModelByUserId
(
@RequestParam
(
name
=
"userId"
,
required
=
false
)
Long
userId
,
@RequestParam
(
name
=
"phoneNo"
,
required
=
false
)
String
phoneNo
)
{
@RequestParam
(
name
=
"phoneNo"
,
required
=
false
)
String
phoneNo
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
boolean
userIdOk
=
Objects
.
nonNull
(
userId
)
&&
userId
>
0
;
boolean
phoneNoOk
=
ValidationUtil
.
validatePhoneNo
(
phoneNo
);
if
(!
userIdOk
&&
!
phoneNoOk
)
{
...
...
@@ -579,7 +519,7 @@ public class InnerController implements IBaseController {
UserAssociationModel
bean
=
null
;
User
user
=
userIdOk
?
userService
.
findById
(
userId
)
:
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(!
Objects
.
isNull
(
user
))
{
bean
=
findUserAssociationModelByUser
(
user
);
bean
=
findUserAssociationModelByUser
(
user
,
tenantId
);
}
return
JsonResult
.
buildSuccessResult
(
""
,
bean
);
}
...
...
@@ -591,20 +531,20 @@ public class InnerController implements IBaseController {
* @return
*/
@GetMapping
(
"/user-full/search/userId"
)
public
JsonResult
<
UserFullResp
>
findUserFullSearchByUserId
(
@RequestParam
Long
userId
)
{
return
JsonResult
.
buildSuccessResultGeneric
(
userService
.
findUserFullSearchByUserId
(
userId
));
public
JsonResult
<
UserFullResp
>
findUserFullSearchByUserId
(
@RequestParam
Long
userId
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
return
JsonResult
.
buildSuccessResultGeneric
(
userService
.
findUserFullSearchByUserId
(
userId
,
tenantId
));
}
@RequestMapping
(
"/user-association/search/phone"
)
public
JsonResult
findUserAssociationByPhone
(
String
phoneNo
)
{
User
Detail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
UserAssociation
bean
=
getUserAssociation
(
user
Detail
);
public
JsonResult
findUserAssociationByPhone
(
String
phoneNo
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userInfoEntity
=
userInfoRepository
.
findByPhoneNoAndTenantId
(
phoneNo
,
tenantId
);
UserAssociation
bean
=
getUserAssociation
(
user
InfoEntity
);
return
JsonResult
.
buildSuccessResult
(
""
,
bean
);
}
@RequestMapping
(
"/user-association/search/uid"
)
public
JsonResult
findUserAssociationByUid
(
Long
uid
)
{
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
ui
d
);
public
JsonResult
findUserAssociationByUid
(
Long
uid
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
uid
,
tenantI
d
);
UserAssociation
bean
=
getUserAssociation
(
userDetail
);
return
JsonResult
.
buildSuccessResult
(
""
,
bean
);
}
...
...
@@ -612,17 +552,17 @@ public class InnerController implements IBaseController {
/**
* 获取用户综合信息
*
* @param user
Detail
* @param user
InfoEntity
* @return
*/
private
UserAssociation
getUserAssociation
(
User
Detail
userDetail
)
{
private
UserAssociation
getUserAssociation
(
User
InfoEntity
userInfoEntity
)
{
UserAssociation
bean
=
new
UserAssociation
();
if
(
null
!=
user
Detail
)
{
bean
.
setUserId
(
user
Detail
.
getUserId
());
bean
.
setPhoneNo
(
user
Detail
.
getPhoneNo
());
bean
.
setName
(
user
Detail
.
getName
());
bean
.
setQq
(
user
Detail
.
getQq
());
bean
.
setGender
(
Optional
.
ofNullable
(
user
Detail
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
getName
());
if
(
null
!=
user
InfoEntity
)
{
bean
.
setUserId
(
user
InfoEntity
.
getUserId
());
bean
.
setPhoneNo
(
user
InfoEntity
.
getPhoneNo
());
bean
.
setName
(
user
InfoEntity
.
getName
());
bean
.
setQq
(
user
InfoEntity
.
getQq
());
bean
.
setGender
(
Optional
.
ofNullable
(
user
InfoEntity
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
getName
());
}
return
bean
;
}
...
...
@@ -702,7 +642,7 @@ public class InnerController implements IBaseController {
* @return
*/
@RequestMapping
(
"/uuid/findByPhones"
)
public
JsonResult
getUuidsByPhones
(
@RequestParam
(
"userPhones"
)
String
userPhones
)
{
public
JsonResult
getUuidsByPhones
(
@RequestParam
(
"userPhones"
)
String
userPhones
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
StringUtils
.
isBlank
(
userPhones
))
{
return
JsonResult
.
buildErrorStateResult
(
"传入用户手机号不可为空"
,
null
);
}
...
...
@@ -710,7 +650,7 @@ public class InnerController implements IBaseController {
});
if
(
org
.
apache
.
commons
.
collections
.
CollectionUtils
.
isNotEmpty
(
phones
))
{
if
(
phones
.
size
()
<=
MAX_SIZE
)
{
List
<
UserInfo
>
userInfos
=
userService
.
findUserInfosByPhones
(
phones
);
List
<
UserInfo
>
userInfos
=
userService
.
findUserInfosByPhones
(
phones
,
tenantId
);
if
(
org
.
apache
.
commons
.
collections
.
CollectionUtils
.
isNotEmpty
(
userInfos
))
{
Map
<
String
,
UserInfo
>
userInfoMap
=
Maps
.
newHashMapWithExpectedSize
(
userInfos
.
size
());
...
...
@@ -1005,37 +945,6 @@ public class InnerController implements IBaseController {
return
loginUserContext
;
}
/**
* 重置用户实名信息接口 -- 供内部系统免密调用
*
* @param userId - 用户主键
* @param idNo - 身份证号
* @param name - 姓名
*/
@RequestMapping
(
path
=
"/userDetail/reset/{userId}"
,
method
=
RequestMethod
.
POST
)
public
JsonResult
resetName
(
@PathVariable
(
"userId"
)
Long
userId
,
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
"idNo"
)
String
idNo
)
{
log
.
info
(
"重置用户实名信息 userId:{},name:{},idNo:{}"
,
userId
,
name
,
idNo
);
if
(
Objects
.
nonNull
(
userId
)
&&
ValidationUtil
.
validateChinese
(
name
))
{
try
{
User
user
=
userService
.
findById
(
userId
);
int
rows
=
userDetailService
.
updateName
(
name
,
user
.
getPhoneNo
());
log
.
info
(
"重置用户实名信息,userId:{},name:{},idNo:{},result:[{}]"
,
userId
,
name
,
idNo
,
rows
);
if
(
rows
>
0
)
{
return
JsonResult
.
buildSuccessResult
(
"用户实名信息已重置."
,
name
.
concat
(
","
).
concat
(
idNo
).
concat
(
","
).
concat
(
userId
.
toString
()));
}
}
catch
(
Exception
e
)
{
log
.
error
(
"用户实名信息重置失败,userId[{}],name[{}],err:[{}]"
,
userId
,
name
,
e
);
}
return
JsonResult
.
buildErrorStateResult
(
"用户实名信息重置失败."
,
"Error data"
);
}
else
{
return
JsonResult
.
buildErrorStateResult
(
"用户实名信息重置失败."
,
"Error data"
);
}
}
/**
* 重置密码接口 -- 供内部系统免密调用
*/
...
...
@@ -1062,46 +971,6 @@ public class InnerController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"用户密码重置失败."
,
phone
);
}
/**
* 修改实名信息接口 -- 供内部人员使用(例如绝影)
*/
@RequestMapping
(
"/updateIdCard"
)
public
JsonResult
updateIdCard
(
@RequestParam
(
required
=
false
)
String
name
,
@RequestParam
(
required
=
false
)
String
idNo
,
@RequestParam
String
phoneNo
,
@RequestParam
String
reason
,
@RequestParam
String
content
)
{
//密文
if
(
null
!=
content
)
{
content
=
content
.
replaceAll
(
" "
,
"+"
);
}
String
str
=
AesUtil
.
decryptAfterBase64Decode
(
content
,
Constants
.
AES_KEY
);
if
(
null
==
str
||
!
str
.
equals
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"解密有误"
,
null
);
}
if
(
StringUtils
.
isBlank
(
name
)
&&
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"不能全为空"
,
null
);
}
if
(
StringUtils
.
isBlank
(
phoneNo
)
||
StringUtils
.
isBlank
(
reason
))
{
return
JsonResult
.
buildErrorStateResult
(
"参数有误"
,
null
);
}
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
log
.
info
(
"手机号有误, phoneNo:{}"
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"用户手机号错误"
,
null
);
}
log
.
info
(
"重置用户实名信息 phoneNo:{},name:{},idNo:{}"
,
phoneNo
,
name
,
idNo
);
try
{
int
rows
=
userDetailService
.
updateName
(
name
,
phoneNo
);
log
.
info
(
"重置用户实名信息,phoneNo:{},name:{},idNo:{},result:[{}],操作的理由reason:{}"
,
phoneNo
,
name
,
idNo
,
rows
,
reason
);
if
(
rows
>
0
)
{
return
JsonResult
.
buildSuccessResult
(
"用户实名信息已重置."
,
phoneNo
.
concat
(
","
).
concat
(
name
).
concat
(
","
).
concat
(
idNo
));
}
}
catch
(
Exception
e
)
{
log
.
error
(
"用户实名信息重置失败,phoneNo[{}],name[{}],err:[{}]"
,
phoneNo
,
name
,
e
);
}
return
JsonResult
.
buildErrorStateResult
(
"用户实名信息重置失败."
,
"Error data"
);
}
/**
* 重置密码接口 -- 供内部人员使用(例如绝影)
*/
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/SyncUserController.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
controller
.
internal
.
user
;
import
cn.quantgroup.xyqb.aspect.accessable.IpValidator
;
import
cn.quantgroup.xyqb.constant.UserConstant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.
service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.
repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.validator.ChineseName
;
...
...
@@ -33,13 +34,15 @@ public class SyncUserController {
private
static
final
String
KEY
=
"abc1234"
;
@Autowired
private
IUserService
userService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@RequestMapping
(
"/save_detail"
)
public
JsonResult
saveUserDetail
(
String
key
,
String
phoneNo
,
String
idNo
,
@ChineseName
@RequestParam
String
name
)
{
public
JsonResult
saveUserDetail
(
String
key
,
String
phoneNo
,
@ChineseName
@RequestParam
String
name
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(!
Objects
.
equals
(
KEY
,
key
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
...
...
@@ -58,17 +61,17 @@ public class SyncUserController {
return
JsonResult
.
buildErrorStateResult
(
"用户不存在"
,
phoneNo
);
}
/* 保存或更新 */
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
if
(
Objects
.
isNull
(
userDetail
))
{
userDetail
=
new
User
Detail
();
userDetail
=
new
User
InfoEntity
();
}
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setName
(
name
);
userDetail
.
set
IsAuthenticated
(
false
);
userDetail
.
set
TenantId
(
tenantId
);
log
.
info
(
"SyncUserController saveUserDetail, userId:{}, phoneNo:{}, name:{}"
,
user
.
getId
(),
phoneNo
,
name
);
try
{
user
DetailService
.
saveUserDetail
(
userDetail
);
user
InfoRepository
.
save
(
userDetail
);
}
catch
(
DataIntegrityViolationException
ex
)
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
...
...
@@ -76,18 +79,19 @@ public class SyncUserController {
/*
* 如果已存在记录,则更新
*/
User
Detail
theUserDetail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
theUserDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
if
(
Objects
.
isNull
(
theUserDetail
))
{
userDetail
.
setId
(
null
);
}
else
{
userDetail
.
setId
(
theUserDetail
.
getId
());
}
user
DetailService
.
saveUserDetail
(
userDetail
);
user
InfoRepository
.
save
(
userDetail
);
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
@RequestMapping
(
"/user"
)
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
)
{
public
JsonResult
fetchUser
(
String
key
,
String
phoneNo
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(!
Objects
.
equals
(
KEY
,
key
)
||
!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
...
...
@@ -95,13 +99,13 @@ public class SyncUserController {
if
(
Objects
.
isNull
(
user
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
User
Detail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
detail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
}
@RequestMapping
(
"/user_uuid"
)
public
JsonResult
fetchUserByUuid
(
String
key
,
String
uuid
)
{
public
JsonResult
fetchUserByUuid
(
String
key
,
String
uuid
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
StringUtils
.
isEmpty
(
key
)
||
!
KEY
.
equals
(
key
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
...
...
@@ -112,7 +116,7 @@ public class SyncUserController {
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
User
Detail
detail
=
userDetailService
.
findByUserId
(
user
.
getId
()
);
User
InfoEntity
detail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
tenantId
);
UserModel
userModel
=
new
UserModel
(
user
,
detail
);
return
JsonResult
.
buildSuccessResult
(
null
,
userModel
);
}
...
...
@@ -124,14 +128,14 @@ public class SyncUserController {
*/
@IpValidator
@RequestMapping
(
"/listByUserIds"
)
public
JsonResult
listByUserIds
(
String
userIds
)
{
public
JsonResult
listByUserIds
(
String
userIds
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
// 过滤掉合法的多个数值串间的空白值
userIds
=
ValidationUtil
.
filterNumbers
(
userIds
);
if
(!
ValidationUtil
.
validateNumbers
(
userIds
))
{
return
JsonResult
.
buildErrorStateResult
(
"参数不正确"
,
null
);
}
List
<
Long
>
userIdList
=
Arrays
.
asList
(
userIds
.
split
(
",|;"
)).
stream
().
map
(
userId
->
Long
.
valueOf
(
userId
)).
collect
(
Collectors
.
toList
());
List
<
User
Detail
>
userDetailList
=
userDetailService
.
findByUserIdIn
(
userIdList
);
List
<
User
InfoEntity
>
userDetailList
=
userInfoRepository
.
findByTenantIdAndUserIdIn
(
tenantId
,
userIdList
);
return
JsonResult
.
buildSuccessResult
(
null
,
userDetailList
);
}
}
src/main/java/cn/quantgroup/xyqb/controller/internal/user/center/UserCenterController.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
controller
.
internal
.
user
.
center
;
import
cn.quantgroup.xyqb.constant.enums.EducationEnum
;
import
cn.quantgroup.xyqb.constant.enums.IncomeRangeEnum
;
import
cn.quantgroup.xyqb.constant.enums.MaritalStatus
;
import
cn.quantgroup.xyqb.constant.enums.OccupationEnum
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.forbidden.AccessForbiddenValidator
;
import
cn.quantgroup.xyqb.aspect.limit.PasswordFreeAccessValidator
;
import
cn.quantgroup.xyqb.
aspect.lock.RedisLock
;
import
cn.quantgroup.xyqb.
constant.UserConstant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.UserAttached
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.
service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.
repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
cn.quantgroup.xyqb.service.user.UserCenterService
;
import
cn.quantgroup.xyqb.util.TenantUtil
;
...
...
@@ -38,7 +34,7 @@ public class UserCenterController {
@Autowired
private
UserCenterService
userCenterService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Autowired
private
IUserService
userService
;
...
...
@@ -185,7 +181,7 @@ public class UserCenterController {
* @return
*/
@RequestMapping
(
"/query/verified"
)
public
JsonResult
queryVerified
(
String
phoneNo
)
{
public
JsonResult
queryVerified
(
String
phoneNo
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
StringUtils
.
isEmpty
(
phoneNo
))
{
log
.
error
(
"手机号为空,phoneNo:{}"
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"参数不合法"
,
null
);
...
...
@@ -194,7 +190,7 @@ public class UserCenterController {
if
(
null
==
userId
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"该用户不存在"
,
null
);
}
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
if
(
null
!=
userDetail
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
userDetail
);
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/middleoffice/userdetail/UserDetailController.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
controller
.
middleoffice
.
userdetail
;
import
cn.quantgroup.xyqb.constant.UserConstant
;
import
cn.quantgroup.xyqb.controller.middleoffice.userdetail.req.UserDetailReq
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.
service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.
repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -21,7 +22,7 @@ import javax.validation.Valid;
public
class
UserDetailController
{
@Resource
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Resource
private
IUserService
userService
;
...
...
@@ -36,14 +37,14 @@ public class UserDetailController {
*/
@PutMapping
(
"/{userId}"
)
public
JsonResult
update
(
@PathVariable
Long
userId
,
@Valid
@RequestBody
UserDetailReq
userDetailReq
)
{
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
@Valid
@RequestBody
UserDetailReq
userDetailReq
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
if
(
userDetail
==
null
)
{
return
save
(
userId
,
userDetailReq
);
return
save
(
userId
,
userDetailReq
,
tenantId
);
}
//更新
userDetail
.
setName
(
userDetailReq
.
getName
());
userDetail
=
user
DetailService
.
saveUserDetail
(
userDetail
);
userDetail
=
user
InfoRepository
.
save
(
userDetail
);
log
.
info
(
"UserDetailController update, userId:{}, name:{}"
,
userId
,
userDetailReq
.
getName
());
return
JsonResult
.
buildSuccessResultGeneric
(
userDetail
);
}
...
...
@@ -57,19 +58,19 @@ public class UserDetailController {
*/
@PostMapping
(
"/{userId}"
)
public
JsonResult
save
(
@PathVariable
Long
userId
,
@Valid
@RequestBody
UserDetailReq
userDetailReq
)
{
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
@Valid
@RequestBody
UserDetailReq
userDetailReq
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResultGeneric
(
userDetail
);
}
User
user
=
userService
.
findById
(
userId
);
userDetail
=
new
User
Detail
();
userDetail
=
new
User
InfoEntity
();
userDetail
.
setUserId
(
userId
);
userDetail
.
setName
(
userDetailReq
.
getName
());
userDetail
.
setPhoneNo
(
user
.
getPhoneNo
());
userDetail
.
setGender
(
userDetail
.
getGender
());
userDetail
=
user
DetailService
.
saveUserDetail
(
userDetail
);
userDetail
=
user
InfoRepository
.
save
(
userDetail
);
log
.
info
(
"UserDetailController save, userId:{}, phoneNo:{}, name:{}"
,
user
.
getId
(),
user
.
getPhoneNo
(),
userDetailReq
.
getName
());
return
JsonResult
.
buildSuccessResultGeneric
(
userDetail
);
}
...
...
@@ -81,8 +82,8 @@ public class UserDetailController {
* @return
*/
@GetMapping
(
"/userId/{userId}"
)
public
JsonResult
query
(
@PathVariable
Long
userId
)
{
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
public
JsonResult
query
(
@PathVariable
Long
userId
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
return
JsonResult
.
buildSuccessResultGeneric
(
userDetail
);
}
...
...
@@ -93,8 +94,8 @@ public class UserDetailController {
* @return
*/
@GetMapping
(
"/phoneNo/{phoneNo}"
)
public
JsonResult
query
(
@PathVariable
String
phoneNo
)
{
User
Detail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
public
JsonResult
query
(
@PathVariable
String
phoneNo
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
User
InfoEntity
userDetail
=
userInfoRepository
.
findByPhoneNoAndTenantId
(
phoneNo
,
tenantId
);
return
JsonResult
.
buildSuccessResultGeneric
(
userDetail
);
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/middleoffice/userext/UserExtController.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
controller
.
middleoffice
.
userext
;
import
cn.quantgroup.xyqb.constant.
enums.OccupationEnum
;
import
cn.quantgroup.xyqb.constant.
UserConstant
;
import
cn.quantgroup.xyqb.controller.middleoffice.userext.req.UserExtReq
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.
service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.
repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 用户扩展信息
...
...
@@ -21,7 +18,7 @@ import java.util.Map;
public
class
UserExtController
{
@Resource
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Resource
...
...
@@ -32,12 +29,12 @@ public class UserExtController {
//todo 保存失败的各种场景。
@PutMapping
(
"/{userId}"
)
public
JsonResult
ext
(
@PathVariable
Long
userId
,
@RequestBody
UserExtReq
userExtReq
)
{
public
JsonResult
ext
(
@PathVariable
Long
userId
,
@RequestBody
UserExtReq
userExtReq
,
@RequestParam
(
value
=
"tenantId"
,
defaultValue
=
UserConstant
.
defaultTenantIdString
)
Integer
tenantId
)
{
if
(
userExtReq
.
getEmail
()
!=
null
)
{
user
DetailService
.
updateUserEmail
(
userId
,
userExtReq
.
getEmail
()
);
user
InfoRepository
.
updateUserEmail
(
userExtReq
.
getEmail
(),
userId
,
tenantId
);
}
if
(
userExtReq
.
getQq
()
!=
null
)
{
user
DetailService
.
updateUserQq
(
userId
,
userExtReq
.
getQq
()
);
user
InfoRepository
.
updateUserQq
(
userExtReq
.
getQq
(),
userId
,
tenantId
);
}
return
JsonResult
.
buildSuccessResult
();
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/modifyphoneno/resp/ModifyPhoneNoResp.java
View file @
423b1579
...
...
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.time.LocalDateTime
;
import
java.util.Optional
;
/**
...
...
@@ -22,10 +23,10 @@ public class ModifyPhoneNoResp {
private
Long
id
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Timestamp
createdAt
;
private
LocalDateTime
createdAt
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Timestamp
updatedAt
;
private
LocalDateTime
updatedAt
;
/**
* user.id
...
...
src/main/java/cn/quantgroup/xyqb/controller/modifyphoneno/resp/UserModifyPhoneRecordResp.java
View file @
423b1579
...
...
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.time.LocalDateTime
;
@Data
public
class
UserModifyPhoneRecordResp
{
...
...
@@ -25,13 +26,13 @@ public class UserModifyPhoneRecordResp {
private
String
financialResponse
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Timestamp
createdAt
;
private
LocalDateTime
createdAt
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Timestamp
updatedAt
;
private
LocalDateTime
updatedAt
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Timestamp
operationAt
;
private
LocalDateTime
operationAt
;
private
ApplySource
applySource
;
...
...
src/main/java/cn/quantgroup/xyqb/entity/BaseEntity.java
View file @
423b1579
...
...
@@ -5,6 +5,8 @@ import lombok.Data;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
/**
* 所有数据库实体,都要继承 BaseEntity
...
...
@@ -21,22 +23,21 @@ public abstract class BaseEntity implements Serializable {
@Basic
(
optional
=
false
)
private
Long
id
;
@Column
(
name
=
"created_at"
)
private
Timestamp
createdAt
;
@Column
(
name
=
"created_at"
,
columnDefinition
=
"TIMESTAMP"
)
private
LocalDateTime
createdAt
;
@Column
(
name
=
"updated_at"
)
private
Timestamp
updatedAt
;
@Column
(
name
=
"updated_at"
,
columnDefinition
=
"TIMESTAMP"
)
private
LocalDateTime
updatedAt
;
@PrePersist
public
void
prePersist
()
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
this
.
createdAt
=
now
;
this
.
updatedAt
=
now
;
this
.
createdAt
=
LocalDateTime
.
now
();
this
.
updatedAt
=
LocalDateTime
.
now
();
}
@PreUpdate
public
void
preUpdate
()
{
this
.
updatedAt
=
new
Timestamp
(
System
.
currentTimeMillis
()
);
this
.
updatedAt
=
LocalDateTime
.
now
(
);
}
}
src/main/java/cn/quantgroup/xyqb/entity/User.java
View file @
423b1579
...
...
@@ -48,6 +48,9 @@ public class User extends BaseEntity implements Serializable {
@Column
(
name
=
"cipher_password"
)
private
String
cipherPassword
;
@Column
(
name
=
"tenant_id"
)
private
Integer
tenantId
;
public
String
getEncryptedPhoneNo
()
{
return
StringUtils
.
isBlank
(
encryptedPhoneNo
)
?
phoneNo
:
encryptedPhoneNo
;
}
...
...
src/main/java/cn/quantgroup/xyqb/entity/User
Detail
.java
→
src/main/java/cn/quantgroup/xyqb/entity/User
InfoEntity
.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
entity
;
import
cn.quantgroup.xyqb.model.Gender
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
/**
* Created by FrankChow on 15/7/8.
*/
@Getter
@Setter
@ToString
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Entity
@Table
(
name
=
"user_detail"
,
uniqueConstraints
=
@UniqueConstraint
(
columnNames
=
"user_id"
))
public
class
UserDetail
extends
BaseEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1L
;
@Table
(
name
=
"user_detail"
)
public
class
UserInfoEntity
extends
BaseEntity
implements
Serializable
{
@Column
(
name
=
"user_id"
)
private
Long
userId
;
@Column
(
name
=
"phone_no"
)
private
String
phoneNo
;
@Column
(
name
=
"name"
)
private
String
name
;
//身份证验真 0 未认证 1认证
@Column
(
name
=
"is_authenticated"
)
private
Boolean
isAuthenticated
=
false
;
//0 未知 1 女 2 男
@Column
(
name
=
"gender"
)
private
Gender
gender
;
...
...
@@ -46,4 +30,21 @@ public class UserDetail extends BaseEntity implements Serializable {
@Column
(
name
=
"qq"
)
private
String
qq
;
@Column
(
name
=
"name"
)
private
String
name
;
@Column
(
name
=
"photo"
)
private
String
photo
;
@Column
(
name
=
"birthday"
)
private
LocalDate
birthday
;
@Column
(
name
=
"province_id"
)
private
Integer
provinceId
;
@Column
(
name
=
"city_id"
)
private
Integer
cityId
;
@Column
(
name
=
"address"
)
private
String
address
;
@Column
(
name
=
"tenant_id"
)
private
Integer
tenantId
;
}
src/main/java/cn/quantgroup/xyqb/entity/converter/LocalDateAttributeConverter.java
0 → 100644
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
entity
.
converter
;
import
javax.persistence.AttributeConverter
;
import
javax.persistence.Converter
;
import
java.sql.Date
;
import
java.time.LocalDate
;
@Converter
(
autoApply
=
true
)
public
class
LocalDateAttributeConverter
implements
AttributeConverter
<
LocalDate
,
Date
>
{
@Override
public
Date
convertToDatabaseColumn
(
LocalDate
attribute
)
{
return
attribute
==
null
?
null
:
Date
.
valueOf
(
attribute
);
}
@Override
public
LocalDate
convertToEntityAttribute
(
Date
dbData
)
{
return
dbData
==
null
?
null
:
dbData
.
toLocalDate
();
}
}
src/main/java/cn/quantgroup/xyqb/entity/converter/LocalDateTimeAttributeConverter.java
0 → 100644
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
entity
.
converter
;
import
javax.persistence.AttributeConverter
;
import
javax.persistence.Converter
;
import
java.sql.Timestamp
;
import
java.time.LocalDateTime
;
@Converter
(
autoApply
=
true
)
public
class
LocalDateTimeAttributeConverter
implements
AttributeConverter
<
LocalDateTime
,
Timestamp
>
{
@Override
public
Timestamp
convertToDatabaseColumn
(
LocalDateTime
attribute
)
{
return
attribute
==
null
?
null
:
Timestamp
.
valueOf
(
attribute
);
}
@Override
public
LocalDateTime
convertToEntityAttribute
(
Timestamp
dbData
)
{
return
dbData
==
null
?
null
:
dbData
.
toLocalDateTime
();
}
}
src/main/java/cn/quantgroup/xyqb/event/DetailRegisteredEventListener.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
event
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.UserRegisterParam
;
import
cn.quantgroup.xyqb.
service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.
repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -15,10 +15,8 @@ import javax.annotation.Resource;
@Slf4j
@Component
public
class
DetailRegisteredEventListener
implements
ApplicationListener
<
RegisterEvent
>
{
@Resource
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Override
public
void
onApplicationEvent
(
RegisterEvent
event
)
{
...
...
@@ -31,11 +29,11 @@ public class DetailRegisteredEventListener implements ApplicationListener<Regist
}
String
phoneNo
=
userRegisterParam
.
getPhoneNo
();
String
name
=
userRegisterParam
.
getName
();
User
Detail
userDetail
=
new
UserDetail
();
User
InfoEntity
userDetail
=
new
UserInfoEntity
();
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setName
(
name
);
userDetail
.
setUserId
(
user
.
getId
());
log
.
info
(
"DetailRegisteredEventListener saveUserDetail, userId:{}, phoneNo:{}, name:{}"
,
user
.
getId
(),
phoneNo
,
name
);
user
DetailService
.
saveUserDetail
(
userDetail
);
user
InfoRepository
.
save
(
userDetail
);
}
}
src/main/java/cn/quantgroup/xyqb/event/UserDetailUpdateEvent.java
deleted
100644 → 0
View file @
3fca5558
package
cn
.
quantgroup
.
xyqb
.
event
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
lombok.Getter
;
import
org.springframework.context.ApplicationEvent
;
@Getter
public
class
UserDetailUpdateEvent
extends
ApplicationEvent
{
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
public
UserDetailUpdateEvent
(
Object
source
)
{
super
(
source
);
}
private
UserDetail
userDetail
;
public
UserDetailUpdateEvent
(
Object
source
,
UserDetail
userDetail
)
{
super
(
source
);
this
.
userDetail
=
userDetail
;
}
}
src/main/java/cn/quantgroup/xyqb/model/UserDisableRecordModel.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
model
;
import
cn.quantgroup.xyqb.entity.UserDisableRecord
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.time.
format.DateTimeFormatter
;
import
java.time.
LocalDateTime
;
/**
* 只是为了兼容时间格式化问题,后续用户中心升级后,该model不需要
*/
@Data
public
class
UserDisableRecordModel
{
public
class
UserDisableRecordModel
{
private
Long
id
;
private
Long
userId
;
...
...
@@ -20,20 +21,21 @@ public class UserDisableRecordModel{
private
String
createdBy
;
private
String
updatedBy
;
private
String
createdAt
;
private
String
updatedAt
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
createdAt
;
public
static
UserDisableRecordModel
from
(
UserDisableRecord
userDisableRecord
){
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
updatedAt
;
public
static
UserDisableRecordModel
from
(
UserDisableRecord
userDisableRecord
)
{
UserDisableRecordModel
userDisableRecordModel
=
new
UserDisableRecordModel
();
userDisableRecordModel
.
setUserId
(
userDisableRecord
.
getUserId
());
userDisableRecordModel
.
setId
(
userDisableRecord
.
getId
());
userDisableRecordModel
.
setReason
(
userDisableRecord
.
getReason
());
userDisableRecordModel
.
setOperation_type
(
userDisableRecord
.
getOperation_type
());
userDisableRecordModel
.
setCreatedAt
(
userDisableRecord
.
getCreatedAt
().
toLocalDateTime
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
userDisableRecordModel
.
setUpdatedAt
(
userDisableRecord
.
getUpdatedAt
().
toLocalDateTime
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
userDisableRecordModel
.
setCreatedAt
(
userDisableRecord
.
getCreatedAt
());
userDisableRecordModel
.
setUpdatedAt
(
userDisableRecord
.
getUpdatedAt
());
userDisableRecordModel
.
setCreatedBy
(
userDisableRecord
.
getCreatedBy
());
userDisableRecordModel
.
setUpdatedBy
(
userDisableRecord
.
getUpdatedBy
());
return
userDisableRecordModel
;
...
...
src/main/java/cn/quantgroup/xyqb/model/UserFullInfo.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
model
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
lombok.Data
;
import
java.io.Serializable
;
...
...
@@ -36,7 +36,7 @@ public class UserFullInfo implements Serializable {
public
UserFullInfo
()
{
}
public
UserFullInfo
(
User
user
,
User
Detail
userDetail
)
{
public
UserFullInfo
(
User
user
,
User
InfoEntity
userInfoEntity
)
{
if
(
user
!=
null
)
{
this
.
id
=
user
.
getId
();
this
.
phoneNo
=
user
.
getPhoneNo
();
...
...
@@ -45,9 +45,9 @@ public class UserFullInfo implements Serializable {
this
.
uuid
=
user
.
getUuid
();
this
.
enable
=
user
.
getEnable
();
}
if
(
user
Detail
!=
null
)
{
this
.
name
=
user
Detail
.
getName
();
this
.
gender
=
Optional
.
ofNullable
(
user
Detail
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
getName
();
if
(
user
InfoEntity
!=
null
)
{
this
.
name
=
user
InfoEntity
.
getName
();
this
.
gender
=
Optional
.
ofNullable
(
user
InfoEntity
.
getGender
()).
orElse
(
Gender
.
UNKNOWN
).
getName
();
}
}
...
...
src/main/java/cn/quantgroup/xyqb/model/UserInfo.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
model
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
lombok.Data
;
import
org.springframework.util.Assert
;
...
...
@@ -25,14 +25,14 @@ public class UserInfo implements Serializable {
private
String
uuid
;
private
String
IdNo
;
public
UserInfo
(
User
user
,
User
Detail
userDetail
)
{
public
UserInfo
(
User
user
,
User
InfoEntity
userInfoEntity
)
{
Assert
.
notNull
(
user
,
"User信息无效"
);
this
.
id
=
user
.
getId
();
this
.
phoneNo
=
user
.
getPhoneNo
();
this
.
registerFrom
=
user
.
getRegisteredFrom
();
this
.
uuid
=
user
.
getUuid
();
if
(
user
Detail
!=
null
)
{
this
.
name
=
user
Detail
.
getName
();
if
(
user
InfoEntity
!=
null
)
{
this
.
name
=
user
InfoEntity
.
getName
();
}
}
}
src/main/java/cn/quantgroup/xyqb/model/User
Detail
Ret.java
→
src/main/java/cn/quantgroup/xyqb/model/User
Info
Ret.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
model
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
lombok.Data
;
import
org.apache.commons.lang.StringUtils
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
import
java.time.ZoneOffset
;
/**
* Created by 11 on 2016/12/20.
*/
@Data
public
class
User
Detail
Ret
implements
Serializable
{
public
class
User
Info
Ret
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1L
;
private
Long
id
;
private
Long
userId
;
private
String
phoneNo
;
private
String
name
;
private
String
n
ickN
ame
;
//证件号
private
String
idNo
;
//0 身份证 1 军官证 2 护照
private
IdType
idType
;
//身份证验真 0 未认证 1认证
private
Boolean
isAuthenticated
=
false
;
//0 未知 1 女 2 男
private
Gender
gender
;
...
...
@@ -36,7 +31,13 @@ public class UserDetailRet implements Serializable {
private
String
email
;
private
String
qq
;
private
String
address
;
private
Integer
provinceId
;
private
Integer
cityId
;
private
LocalDate
birthday
;
private
String
photo
;
private
Integer
tenantId
;
//创建时间
private
Long
createdAt
;
...
...
@@ -45,22 +46,26 @@ public class UserDetailRet implements Serializable {
/**
* 转换时间从timestamp到long
*
* @param userDetail
* @return return self
* @param userInfoEntity UserInfoEntity
* @return UserInfoRet
*/
public
static
UserDetailRet
getUserDetail
(
UserDetail
userDetail
)
{
long
createTimeStamp
=
userDetail
.
getCreatedAt
().
getTime
();
long
updateTimeStamp
=
userDetail
.
getUpdatedAt
().
getTime
();
UserDetailRet
userDetailRet
=
new
UserDetailRet
();
userDetailRet
.
setId
(
userDetail
.
getId
());
userDetailRet
.
setName
(
userDetail
.
getName
());
userDetailRet
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
userDetailRet
.
setEmail
(
StringUtils
.
defaultIfEmpty
(
userDetail
.
getEmail
(),
""
));
userDetailRet
.
setGender
(
userDetail
.
getGender
());
userDetailRet
.
setIsAuthenticated
(
userDetail
.
getIsAuthenticated
());
userDetailRet
.
setQq
(
StringUtils
.
defaultIfEmpty
(
userDetail
.
getQq
(),
""
));
userDetailRet
.
setUserId
(
userDetail
.
getUserId
());
public
static
UserInfoRet
getUserDetail
(
UserInfoEntity
userInfoEntity
)
{
long
createTimeStamp
=
userInfoEntity
.
getCreatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
long
updateTimeStamp
=
userInfoEntity
.
getUpdatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
UserInfoRet
userDetailRet
=
new
UserInfoRet
();
userDetailRet
.
setId
(
userInfoEntity
.
getId
());
userDetailRet
.
setUserId
(
userInfoEntity
.
getUserId
());
userDetailRet
.
setPhoneNo
(
userInfoEntity
.
getPhoneNo
());
userDetailRet
.
setNickName
(
userInfoEntity
.
getName
());
userDetailRet
.
setGender
(
userInfoEntity
.
getGender
());
userDetailRet
.
setEmail
(
StringUtils
.
defaultIfEmpty
(
userInfoEntity
.
getEmail
(),
""
));
userDetailRet
.
setQq
(
StringUtils
.
defaultIfEmpty
(
userInfoEntity
.
getQq
(),
""
));
userDetailRet
.
setAddress
(
userInfoEntity
.
getAddress
());
userDetailRet
.
setProvinceId
(
userInfoEntity
.
getProvinceId
());
userDetailRet
.
setCityId
(
userDetailRet
.
getCityId
());
userDetailRet
.
setBirthday
(
userDetailRet
.
getBirthday
());
userDetailRet
.
setPhoto
(
userDetailRet
.
getPhoto
());
userDetailRet
.
setTenantId
(
userInfoEntity
.
getTenantId
());
userDetailRet
.
setCreatedAt
(
createTimeStamp
);
userDetailRet
.
setUpdatedAt
(
updateTimeStamp
);
return
userDetailRet
;
...
...
src/main/java/cn/quantgroup/xyqb/model/UserModel.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
model
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
lombok.Data
;
import
org.springframework.util.Assert
;
...
...
@@ -35,7 +35,7 @@ public class UserModel implements Serializable {
public
UserModel
()
{
}
public
UserModel
(
User
user
,
User
Detail
userDetail
)
{
public
UserModel
(
User
user
,
User
InfoEntity
userDetail
)
{
Assert
.
notNull
(
user
,
"User信息无效"
);
this
.
id
=
user
.
getId
();
this
.
phoneNo
=
user
.
getPhoneNo
();
...
...
src/main/java/cn/quantgroup/xyqb/model/UserRegisterMqMessage.java
View file @
423b1579
...
...
@@ -4,6 +4,8 @@ import cn.quantgroup.xyqb.entity.User;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.time.ZoneOffset
;
/**
* Created by xuran on 2017/9/7.
...
...
@@ -33,8 +35,8 @@ public class UserRegisterMqMessage implements Serializable {
private
Long
updatedAt
;
public
UserRegisterMqMessage
(
User
user
)
{
Long
createTimeStamp
=
user
.
getCreatedAt
().
getTime
();
Long
updateTimeStamp
=
user
.
getUpdatedAt
().
getTime
();
Long
createTimeStamp
=
user
.
getCreatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
Long
updateTimeStamp
=
user
.
getUpdatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
this
.
setId
(
user
.
getId
());
this
.
setPhoneNo
(
user
.
getPhoneNo
());
this
.
setEnable
(
user
.
getEnable
());
...
...
@@ -42,6 +44,5 @@ public class UserRegisterMqMessage implements Serializable {
this
.
setUuid
(
user
.
getUuid
());
this
.
setCreatedAt
(
createTimeStamp
);
this
.
setUpdatedAt
(
updateTimeStamp
);
}
}
src/main/java/cn/quantgroup/xyqb/model/UserRet.java
View file @
423b1579
...
...
@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.User;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.ZoneOffset
;
import
java.util.Objects
;
/**
...
...
@@ -47,8 +48,8 @@ public class UserRet implements Serializable {
if
(
Objects
.
isNull
(
user
)){
return
;
}
Long
createTimeStamp
=
user
.
getCreatedAt
().
getTime
();
Long
updateTimeStamp
=
user
.
getUpdatedAt
().
getTime
();
Long
createTimeStamp
=
user
.
getCreatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
Long
updateTimeStamp
=
user
.
getUpdatedAt
().
toInstant
(
ZoneOffset
.
UTC
).
toEpochMilli
();
this
.
setId
(
user
.
getId
());
this
.
setPhoneNo
(
user
.
getPhoneNo
());
this
.
setEnable
(
user
.
getEnable
());
...
...
src/main/java/cn/quantgroup/xyqb/repository/IUserDetailRepository.java
deleted
100644 → 0
View file @
3fca5558
package
cn
.
quantgroup
.
xyqb
.
repository
;
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
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* @author mengfan.feng
* @time 2015-09-11 11:22
*/
public
interface
IUserDetailRepository
extends
JpaRepository
<
UserDetail
,
Long
>,
JpaSpecificationExecutor
<
UserDetail
>
{
UserDetail
findByUserId
(
Long
userId
);
UserDetail
findByPhoneNo
(
String
phone
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_detail set qq = ?1 where user_id = ?2"
,
nativeQuery
=
true
)
void
updateUserQq
(
String
qq
,
Long
userId
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_detail set email = ?1 where user_id = ?2"
,
nativeQuery
=
true
)
void
updateUserEmail
(
String
email
,
Long
userId
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_detail set gender = ?1 where user_id = ?2"
,
nativeQuery
=
true
)
void
updateGender
(
int
gender
,
Long
userId
);
List
<
UserDetail
>
findAll
(
Specification
<
UserDetail
>
specification
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_detail set name=?1,gender=?2 where phone_no=?3"
,
nativeQuery
=
true
)
int
updateNameAndIdNoByPhoneNo
(
String
name
,
int
gender
,
String
phoneNo
);
/**
* 按照身份证号和手机号 - 模糊查询
*
* @param phoneNo - 手机号
* @return List<UserDetail>
*/
@Query
(
value
=
"select * from user_detail where phone_no like ?1"
,
nativeQuery
=
true
)
List
<
UserDetail
>
fuzzyQueryByPhoneNo
(
String
phoneNo
);
List
<
UserDetail
>
findTop20ByPhoneNoStartingWith
(
String
phoneNo
);
UserDetail
findByUserIdAndPhoneNoAndName
(
Long
userId
,
String
phoneNo
,
String
name
);
}
src/main/java/cn/quantgroup/xyqb/repository/IUserInfoRepository.java
0 → 100644
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
repository
;
import
cn.quantgroup.xyqb.entity.UserInfoEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
public
interface
IUserInfoRepository
extends
JpaRepository
<
UserInfoEntity
,
Long
>
{
UserInfoEntity
findByUserIdAndTenantId
(
Long
userId
,
Integer
tenantId
);
UserInfoEntity
findByPhoneNoAndTenantId
(
String
phoneNo
,
Integer
tenantId
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_info set qq = ?1 where user_id = ?2 and tenant_id = ?3"
,
nativeQuery
=
true
)
void
updateUserQq
(
String
qq
,
Long
userId
,
Integer
tenantId
);
List
<
UserInfoEntity
>
findByTenantIdAndPhoneNoIn
(
Integer
tenantId
,
List
<
String
>
phoneNos
);
List
<
UserInfoEntity
>
findByTenantIdAndUserIdIn
(
Integer
tenantId
,
List
<
Long
>
userIds
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_info set email = ?1 where user_id = ?2 and tenant_id = ?3"
,
nativeQuery
=
true
)
void
updateUserEmail
(
String
email
,
Long
userId
,
Integer
tenantId
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_info set gender = ?1 where user_id = ?2 and tenant_id = ?3"
,
nativeQuery
=
true
)
void
updateGender
(
int
gender
,
Long
userId
,
Integer
tenantId
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Modifying
@Query
(
value
=
"update user_info set name=?1,gender=?2 where phone_no=?3 and tenant_id = ?4"
,
nativeQuery
=
true
)
int
updateNameAndGenderByPhoneNo
(
String
name
,
int
gender
,
String
phoneNo
,
Integer
tenantId
);
}
src/main/java/cn/quantgroup/xyqb/service/api/impl/UserApiServiceImpl.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
service
.
api
.
impl
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.UserFullInfo
;
import
cn.quantgroup.xyqb.model.UserInfoRet
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.api.IUserApiService
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -20,7 +21,7 @@ public class UserApiServiceImpl implements IUserApiService {
@Autowired
private
IUserService
userService
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Override
public
Optional
<
UserFullInfo
>
getUserFullInfoByUuid
(
String
uuid
)
{
...
...
@@ -28,7 +29,7 @@ public class UserApiServiceImpl implements IUserApiService {
if
(
null
==
user
)
{
return
Optional
.
empty
();
}
User
Detail
detail
=
userDetailService
.
findByUserId
(
user
.
ge
tId
());
User
InfoEntity
detail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
user
.
getTenan
tId
());
UserFullInfo
userFullInfo
=
new
UserFullInfo
(
user
,
detail
);
return
Optional
.
of
(
userFullInfo
);
}
...
...
@@ -39,7 +40,7 @@ public class UserApiServiceImpl implements IUserApiService {
if
(
null
==
user
)
{
return
Optional
.
empty
();
}
User
Detail
detail
=
userDetailService
.
findByUserId
(
user
.
ge
tId
());
User
InfoEntity
detail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
user
.
getTenan
tId
());
UserFullInfo
userFullInfo
=
new
UserFullInfo
(
user
,
detail
);
return
Optional
.
of
(
userFullInfo
);
}
...
...
src/main/java/cn/quantgroup/xyqb/service/page/impl/PageServiceImpl.java
View file @
423b1579
package
cn
.
quantgroup
.
xyqb
.
service
.
page
.
impl
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.model.Tuple
;
import
cn.quantgroup.xyqb.repository.IUserInfoRepository
;
import
cn.quantgroup.xyqb.service.page.IPageService
;
import
cn.quantgroup.xyqb.service.page.bean.BasePageType
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -21,11 +21,12 @@ public class PageServiceImpl implements IPageService {
private
Map
<
String
,
BasePageType
[]>
routerDefinetion
;
@Autowired
private
IUserDetailService
userDetailService
;
private
IUserInfoRepository
userInfoRepository
;
private
BasePageType
pageIdNo
=
new
BasePageType
(
"name"
,
false
)
{
@Override
public
boolean
canPass
(
User
user
)
{
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
.
ge
tId
());
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
user
.
getId
(),
user
.
getTenan
tId
());
return
userDetail
!=
null
;
}
};
...
...
src/main/java/cn/quantgroup/xyqb/service/user/IUserDetailService.java
deleted
100644 → 0
View file @
3fca5558
package
cn
.
quantgroup
.
xyqb
.
service
.
user
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.service.user.vo.UserDetailVO
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.data.domain.Page
;
import
java.util.List
;
/**
* Created by 11 on 2016/12/29.
*/
public
interface
IUserDetailService
{
UserDetail
findByUserId
(
Long
userId
);
UserDetail
findSlaveByUserId
(
Long
userId
);
UserDetail
saveUserDetail
(
UserDetail
userDetail
)
throws
DataIntegrityViolationException
;
UserDetail
findByPhoneNo
(
String
phoneNo
);
UserDetail
findSlaveByPhoneNo
(
String
phoneNo
);
void
updateUserQq
(
Long
userId
,
String
qq
);
void
updateUserEmail
(
Long
userId
,
String
email
);
List
<
UserDetailVO
>
searchUserDetailList
(
String
name
,
String
phoneNo
,
String
idNo
);
List
<
UserDetail
>
findByUserIdIn
(
List
<
Long
>
userIds
);
List
<
UserDetail
>
findByPhoneNos
(
List
<
String
>
phoneNos
);
List
<
UserDetail
>
findByPhoneNoStartingWith
(
String
phoneNo
);
Page
<
UserDetail
>
getUserDetailsPage
(
List
<
Long
>
userId
,
List
<
String
>
phoneNos
,
List
<
String
>
idNos
,
int
pageNumber
,
int
pageSize
,
String
sortType
);
/**
* 更新用户的身份证号
*
* @param name name
* @param phoneNo phoneNo
* @return 受影响的行数
*/
int
updateName
(
String
name
,
String
phoneNo
);
List
<
UserDetail
>
findByPhones
(
List
<
String
>
phoneNos
);
/**
* 按照身份证号和手机号 - 模糊查询
* @param phoneNo - 手机号
* @return List<UserDetail>
*/
List
<
UserDetail
>
fuzzyQueryByPhoneNo
(
String
phoneNo
);
}
src/main/java/cn/quantgroup/xyqb/service/user/IUserService.java
View file @
423b1579
...
...
@@ -56,7 +56,7 @@ public interface IUserService {
*/
int
forbiddenUser
(
Boolean
enable
,
String
phoneNo
);
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
);
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
,
Integer
tenantId
);
/**
* 修改手机号码.
...
...
@@ -65,7 +65,7 @@ public interface IUserService {
* @param newPhoneNo 新手机号
* @return 返回用户信息
*/
User
modifyPhoneNo
(
String
oldPhoneNo
,
String
newPhoneNo
);
User
modifyPhoneNo
(
String
oldPhoneNo
,
String
newPhoneNo
,
Integer
tenantId
);
/**
* 删除这个用户相关缓存
...
...
@@ -85,7 +85,7 @@ public interface IUserService {
* @param userId 用户id
* @return
*/
UserFullResp
findUserFullSearchByUserId
(
Long
userId
);
UserFullResp
findUserFullSearchByUserId
(
Long
userId
,
Integer
tenantId
);
/**
* 按照userid 或者 uuid 批量查询
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/ModifyPhoneNoServiceImpl.java
View file @
423b1579
...
...
@@ -17,7 +17,7 @@ import cn.quantgroup.xyqb.model.ModifyPhoneNoApplyStatusEnum;
import
cn.quantgroup.xyqb.model.ModifyPhoneNoProcessingStatusEnum
;
import
cn.quantgroup.xyqb.repository.IModifyPhoneNoRepository
;
import
cn.quantgroup.xyqb.repository.IModifyPhoneRecordRepository
;
import
cn.quantgroup.xyqb.repository.IUser
Detail
Repository
;
import
cn.quantgroup.xyqb.repository.IUser
Info
Repository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.service.http.IHttpService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
...
...
@@ -70,7 +70,7 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
@Resource
private
IModifyPhoneNoRepository
modifyPhoneNoRepository
;
@Resource
private
IUser
DetailRepository
userDetail
Repository
;
private
IUser
InfoRepository
userInfo
Repository
;
@Resource
private
ISmsService
smsService
;
@Resource
...
...
@@ -242,9 +242,6 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
if
(
ModifyPhoneNoApplyStatusEnum
.
DONE
==
auditReq
.
getApplyStatus
())
{
log
.
info
(
"audit userId = 【{}】, name = 【{}】, idCard = 【{}】, prevPhoneNo = 【{}】, "
+
"curPhoneNo = 【{}】"
,
modifyPhoneNo
.
getUserId
(),
modifyPhoneNo
.
getName
(),
modifyPhoneNo
.
getIdCard
(),
modifyPhoneNo
.
getPrevPhoneNo
(),
modifyPhoneNo
.
getCurPhoneNo
());
if
(
userDetailRepository
.
findByUserIdAndPhoneNoAndName
(
modifyPhoneNo
.
getUserId
(),
modifyPhoneNo
.
getPrevPhoneNo
(),
modifyPhoneNo
.
getName
())
==
null
)
{
throw
new
DataException
(
"姓名、身份证、电话号不符。"
);
}
if
(
userRepository
.
findByPhoneNo
(
modifyPhoneNo
.
getCurPhoneNo
())
!=
null
)
{
throw
new
DataException
(
"新手机号已存在,不支持更换。"
);
}
...
...
@@ -262,7 +259,8 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
// 如果有返回值
if
(
"0000"
.
equals
(
resultStrJson
.
getBusinessCode
())
||
"4014"
.
equals
(
resultStrJson
.
getBusinessCode
()))
{
// 同步金融修改电商
userService
.
modifyPhoneNo
(
modifyPhoneNo
.
getPrevPhoneNo
(),
modifyPhoneNo
.
getCurPhoneNo
());
User
user
=
userService
.
findById
(
modifyPhoneNo
.
getUserId
());
userService
.
modifyPhoneNo
(
modifyPhoneNo
.
getPrevPhoneNo
(),
modifyPhoneNo
.
getCurPhoneNo
(),
user
.
getTenantId
());
modifyPhoneNo
.
setApplyStatus
(
ModifyPhoneNoApplyStatusEnum
.
DONE
.
ordinal
());
modifyPhoneNo
.
setProcessingStatus
(
ModifyPhoneNoProcessingStatusEnum
.
WAIT_4_USER_FEEDBACK
.
ordinal
());
}
else
{
...
...
@@ -547,9 +545,6 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
if
(!
smsService
.
verifyPhoneAndCode
(
curPhoneNo
,
smsCode
))
{
throw
new
DataException
(
"验证码不正确。"
);
}
if
(
userDetailRepository
.
findByUserIdAndPhoneNoAndName
(
userId
,
prevPhoneNo
,
name
)
==
null
)
{
throw
new
DataException
(
"信息填写有误,请重新填写。"
);
}
if
(
userService
.
findByPhoneInDb
(
curPhoneNo
)
!=
null
)
{
throw
new
DataException
(
"填写信息有误,新手机号已注册。"
);
...
...
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserDetailServiceImpl.java
deleted
100644 → 0
View file @
3fca5558
package
cn
.
quantgroup
.
xyqb
.
service
.
user
.
impl
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.event.UserDetailUpdateEvent
;
import
cn.quantgroup.xyqb.model.Gender
;
import
cn.quantgroup.xyqb.model.IdType
;
import
cn.quantgroup.xyqb.repository.IUserDetailRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.service.user.IUserDetailService
;
import
cn.quantgroup.xyqb.service.user.vo.UserDetailVO
;
import
cn.quantgroup.xyqb.util.AddressFilter
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.persistence.criteria.Predicate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public
class
UserDetailServiceImpl
implements
IUserDetailService
{
@Autowired
private
IUserDetailRepository
userDetailRepository
;
@Autowired
private
IUserRepository
userRepository
;
@Resource
private
ApplicationEventPublisher
applicationEventPublisher
;
@Resource
private
JdbcTemplate
jdbcTemplate
;
@Override
public
UserDetail
findByUserId
(
Long
userId
)
{
UserDetail
userDetail
=
userDetailRepository
.
findByUserId
(
userId
);
if
(
null
==
userDetail
)
{
return
userDetail
;
}
userDetail
.
setEmail
(
AddressFilter
.
getEmail
(
userDetail
.
getPhoneNo
(),
userDetail
.
getEmail
()));
return
userDetail
;
}
@Override
public
UserDetail
findSlaveByUserId
(
Long
userId
)
{
UserDetail
userDetail
=
userDetailRepository
.
findByUserId
(
userId
);
if
(
null
==
userDetail
)
{
return
userDetail
;
}
userDetail
.
setEmail
(
AddressFilter
.
getEmail
(
userDetail
.
getPhoneNo
(),
userDetail
.
getEmail
()));
return
userDetail
;
}
@Override
public
UserDetail
saveUserDetail
(
UserDetail
userDetail
)
throws
DataIntegrityViolationException
{
UserDetail
userDetail1
=
userDetailRepository
.
save
(
userDetail
);
// 发送实名登记统计消息
applicationEventPublisher
.
publishEvent
(
new
UserDetailUpdateEvent
(
this
,
userDetail1
));
return
userDetail1
;
}
@Override
public
UserDetail
findByPhoneNo
(
String
phoneNo
)
{
return
userDetailRepository
.
findByPhoneNo
(
phoneNo
);
}
@Override
public
UserDetail
findSlaveByPhoneNo
(
String
phoneNo
)
{
return
userDetailRepository
.
findByPhoneNo
(
phoneNo
);
}
@Override
public
void
updateUserQq
(
Long
userId
,
String
qq
)
{
userDetailRepository
.
updateUserQq
(
qq
,
userId
);
}
@Override
public
void
updateUserEmail
(
Long
userId
,
String
email
)
{
userDetailRepository
.
updateUserEmail
(
email
,
userId
);
}
@Override
public
List
<
UserDetailVO
>
searchUserDetailList
(
String
name
,
String
phoneNo
,
String
idNo
)
{
return
jdbcTemplate
.
query
(
buildSearchUserDetailListSql
(
name
,
phoneNo
,
idNo
),
(
resultSet
,
i
)
->
{
UserDetailVO
userDetailVO
=
new
UserDetailVO
();
userDetailVO
.
setId
(
resultSet
.
getLong
(
"id"
));
userDetailVO
.
setUserId
(
resultSet
.
getLong
(
"user_id"
));
userDetailVO
.
setPhoneNo
(
resultSet
.
getString
(
"phone_no"
));
userDetailVO
.
setName
(
resultSet
.
getString
(
"name"
));
userDetailVO
.
setIdNo
(
resultSet
.
getString
(
"id_no"
));
userDetailVO
.
setIdType
(
IdType
.
values
()[
resultSet
.
getInt
(
"id_type"
)]);
userDetailVO
.
setIsAuthenticated
(
resultSet
.
getInt
(
"is_authenticated"
)
==
1
);
userDetailVO
.
setGender
(
Gender
.
values
()[
resultSet
.
getInt
(
"gender"
)]);
userDetailVO
.
setEmail
(
resultSet
.
getString
(
"email"
));
userDetailVO
.
setQq
(
resultSet
.
getString
(
"qq"
));
userDetailVO
.
setEnable
(
resultSet
.
getObject
(
"enable"
)
==
null
?
null
:
resultSet
.
getBoolean
(
"enable"
));
userDetailVO
.
setCreatedAt
(
resultSet
.
getTimestamp
(
"created_at"
).
getTime
());
userDetailVO
.
setUpdatedAt
(
resultSet
.
getTimestamp
(
"updated_at"
).
getTime
());
return
userDetailVO
;
});
}
private
String
buildSearchUserDetailListSql
(
String
name
,
String
phoneNo
,
String
idNo
)
{
/* 优化两次sql查询耗时问题,示例name=王斌*/
// TODO: 2019/12/24 by rui 暂未找到jpa data同时满足join,动态传参方式。若日后发现,应优化该段代码。
/* 高层模块已校验至少必须满足一个条件不为空 */
StringBuilder
sqlBuilder
=
new
StringBuilder
(
"select ud.*, u.enable "
+
" from user_detail ud"
+
" left join user u on (u.id = ud.user_id)"
+
" where"
);
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
(
name
))
{
sqlBuilder
.
append
(
" name = "
).
append
(
"'"
).
append
(
name
).
append
(
"'"
).
append
(
" and"
);
}
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
(
phoneNo
))
{
sqlBuilder
.
append
(
" ud.phone_no = "
).
append
(
"'"
).
append
(
phoneNo
).
append
(
"'"
).
append
(
" and"
);
}
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
(
idNo
))
{
sqlBuilder
.
append
(
" id_no = "
).
append
(
"'"
).
append
(
idNo
).
append
(
"'"
).
append
(
" and"
);
}
String
sql
=
sqlBuilder
.
toString
();
if
(
sql
.
endsWith
(
"and"
))
{
sql
=
sql
.
substring
(
0
,
sql
.
length
()
-
3
);
}
sql
=
sql
+
" limit 500"
;
return
sql
;
}
@Override
public
List
<
UserDetail
>
findByUserIdIn
(
List
<
Long
>
userIds
)
{
return
userDetailRepository
.
findAll
((
root
,
query
,
cb
)
->
{
query
.
where
(
root
.
get
(
"userId"
).
in
(
userIds
));
return
query
.
getRestriction
();
});
}
@Override
public
List
<
UserDetail
>
findByPhoneNos
(
List
<
String
>
phoneNos
)
{
return
userDetailRepository
.
findAll
((
root
,
query
,
cb
)
->
{
query
.
where
(
root
.
get
(
Constants
.
PHONE_NO
).
in
(
phoneNos
));
return
query
.
getRestriction
();
});
}
@Override
public
List
<
UserDetail
>
findByPhoneNoStartingWith
(
String
phoneNo
)
{
return
userDetailRepository
.
findTop20ByPhoneNoStartingWith
(
phoneNo
);
}
private
Specification
<
UserDetail
>
getSpecification
(
String
name
,
String
phoneNo
,
String
idNo
)
{
List
<
Predicate
>
list
=
new
ArrayList
<>();
Specification
<
UserDetail
>
specification
=
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
if
(!
StringUtils
.
isEmpty
(
name
))
{
list
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"name"
).
as
(
String
.
class
),
name
));
}
if
(!
StringUtils
.
isEmpty
(
phoneNo
))
{
list
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
Constants
.
PHONE_NO
).
as
(
String
.
class
),
phoneNo
));
}
if
(!
StringUtils
.
isEmpty
(
idNo
))
{
list
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"idNo"
).
as
(
String
.
class
),
idNo
));
}
Predicate
[]
p
=
new
Predicate
[
list
.
size
()];
return
criteriaBuilder
.
and
(
list
.
toArray
(
p
));
};
return
specification
;
}
private
Specification
<
UserDetail
>
valueInSpecification
(
List
<
Long
>
userId
,
List
<
String
>
phoneNo
,
List
<
String
>
idNo
)
{
List
<
Predicate
>
list
=
new
ArrayList
<>();
Specification
<
UserDetail
>
specification
=
(
root
,
criteriaQuery
,
criteriaBuilder
)
->
{
if
(
userId
!=
null
&&
userId
.
size
()
>
0
)
{
criteriaQuery
.
where
(
root
.
get
(
"userId"
).
in
(
userId
));
list
.
add
(
criteriaQuery
.
getRestriction
());
}
if
(
phoneNo
!=
null
&&
phoneNo
.
size
()
>
0
)
{
criteriaQuery
.
where
(
root
.
get
(
Constants
.
PHONE_NO
).
in
(
phoneNo
));
list
.
add
(
criteriaQuery
.
getRestriction
());
}
if
(
idNo
!=
null
&&
idNo
.
size
()
>
0
)
{
criteriaQuery
.
where
(
root
.
get
(
"idNo"
).
in
(
idNo
));
list
.
add
(
criteriaQuery
.
getRestriction
());
}
Predicate
[]
p
=
new
Predicate
[
list
.
size
()];
return
criteriaBuilder
.
and
(
list
.
toArray
(
p
));
};
return
specification
;
}
private
PageRequest
buildPageRequest
(
int
pageNumber
,
int
pagzSize
,
String
sortType
)
{
Sort
sort
=
null
;
if
(
Constants
.
AUTO_SORT_TYPE
.
equals
(
sortType
))
{
sort
=
new
Sort
(
Sort
.
Direction
.
ASC
,
"userId"
);
}
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
,
String
sortType
)
{
PageRequest
pageRequest
=
buildPageRequest
(
pageNumber
,
pageSize
,
sortType
);
Specification
<
UserDetail
>
spec
=
valueInSpecification
(
userId
,
phoneNos
,
idNos
);
return
userDetailRepository
.
findAll
(
spec
,
pageRequest
);
}
@Override
public
int
updateName
(
String
name
,
String
phoneNo
)
{
UserDetail
userDetail
=
userDetailRepository
.
findByPhoneNo
(
phoneNo
);
if
(
null
!=
userDetail
)
{
String
newName
=
userDetail
.
getName
();
Gender
newGender
=
Gender
.
UNKNOWN
;
if
(
ValidationUtil
.
validateChinese
(
name
))
{
newName
=
name
;
}
if
(!
Objects
.
equals
(
newName
,
userDetail
.
getName
()))
{
return
userDetailRepository
.
updateNameAndIdNoByPhoneNo
(
newName
,
Optional
.
ofNullable
(
newGender
).
orElse
(
Gender
.
UNKNOWN
).
ordinal
(),
phoneNo
);
}
}
return
0
;
}
@Override
public
List
<
UserDetail
>
findByPhones
(
List
<
String
>
phoneNos
)
{
List
<
UserDetail
>
userDetails
=
userDetailRepository
.
findAll
((
root
,
query
,
cb
)
->
{
query
.
where
(
root
.
get
(
"phoneNo"
).
as
(
String
.
class
).
in
(
phoneNos
));
return
query
.
getRestriction
();
});
return
userDetails
;
}
@Override
public
List
<
UserDetail
>
fuzzyQueryByPhoneNo
(
String
phoneNo
)
{
return
userDetailRepository
.
fuzzyQueryByPhoneNo
(
phoneNo
.
concat
(
"%"
));
}
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
View file @
423b1579
...
...
@@ -7,7 +7,7 @@ import cn.quantgroup.xyqb.controller.IBaseController;
import
cn.quantgroup.xyqb.controller.internal.user.resp.UserFullResp
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
Detail
;
import
cn.quantgroup.xyqb.entity.User
InfoEntity
;
import
cn.quantgroup.xyqb.event.PhoneNoUpdateEvent
;
import
cn.quantgroup.xyqb.exception.DataException
;
import
cn.quantgroup.xyqb.exception.UserNotExistException
;
...
...
@@ -67,10 +67,8 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Autowired
private
IUserRepository
userRepository
;
@Autowired
private
IUser
DetailService
userDetailService
;
private
IUser
InfoRepository
userInfoRepository
;
@Autowired
private
ApplicationEventPublisher
applicationEventPublisher
;
...
...
@@ -253,14 +251,14 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Override
public
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
)
{
public
List
<
UserInfo
>
findUserInfosByPhones
(
List
<
String
>
phones
,
Integer
tenantId
)
{
List
<
User
>
users
=
findByPhones
(
phones
);
if
(
CollectionUtils
.
isEmpty
(
phones
))
{
return
Collections
.
emptyList
();
}
List
<
User
Detail
>
userDetails
=
userDetailService
.
findByPhones
(
phones
);
List
<
User
InfoEntity
>
userDetails
=
userInfoRepository
.
findByTenantIdAndPhoneNoIn
(
tenantId
,
phones
);
if
(!
CollectionUtils
.
isEmpty
(
users
))
{
Map
<
Long
,
User
>
userMap
=
Maps
.
newHashMapWithExpectedSize
(
users
.
size
());
...
...
@@ -283,10 +281,10 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
User
modifyPhoneNo
(
String
oldPhoneNo
,
String
newPhoneNo
)
{
public
User
modifyPhoneNo
(
String
oldPhoneNo
,
String
newPhoneNo
,
Integer
tenantId
)
{
//1. 判断新手机号是否存在
User
newPhoneUser
=
userRepository
.
findByPhoneNo
(
newPhoneNo
);
User
Detail
newPhoneUserDetail
=
userDetailService
.
findByPhoneNo
(
newPhoneNo
);
User
InfoEntity
newPhoneUserDetail
=
userInfoRepository
.
findByPhoneNoAndTenantId
(
newPhoneNo
,
tenantId
);
if
(
Objects
.
nonNull
(
newPhoneUser
)
||
Objects
.
nonNull
(
newPhoneUserDetail
))
{
//新手机号已存在
throw
new
DataException
(
"新手机号存在, 用户修改手机号后新手机号注册了。"
);
...
...
@@ -303,9 +301,9 @@ public class UserServiceImpl implements IUserService, IBaseController {
User
user
=
userRepository
.
saveAndFlush
(
oldPhoneUser
);
//2.2 修改 user_detail 表
User
Detail
oldPhoneUserDetail
=
userDetailService
.
findByPhoneNo
(
oldPhoneNo
);
User
InfoEntity
oldPhoneUserDetail
=
userInfoRepository
.
findByPhoneNoAndTenantId
(
oldPhoneNo
,
tenantId
);
oldPhoneUserDetail
.
setPhoneNo
(
newPhoneNo
);
user
DetailService
.
saveUserDetail
(
oldPhoneUserDetail
);
user
InfoRepository
.
save
(
oldPhoneUserDetail
);
//3. 发送事件
PhoneNoUpdateEvent
phoneNoUpdateEvent
=
new
PhoneNoUpdateEvent
(
this
,
user
,
oldPhoneNo
);
...
...
@@ -434,9 +432,9 @@ public class UserServiceImpl implements IUserService, IBaseController {
* @return
*/
@Override
public
UserFullResp
findUserFullSearchByUserId
(
Long
userId
)
{
public
UserFullResp
findUserFullSearchByUserId
(
Long
userId
,
Integer
tenantId
)
{
User
user
=
userRepository
.
findById
(
userId
);
User
Detail
userDetail
=
userDetailService
.
findByUserId
(
user
Id
);
User
InfoEntity
userDetail
=
userInfoRepository
.
findByUserIdAndTenantId
(
userId
,
tenant
Id
);
UserFullResp
userFullResp
=
UserFullResp
.
builder
().
userId
(
userId
).
build
();
if
(
user
!=
null
)
{
...
...
src/test/java/common/JsonTest.java
View file @
423b1579
package
common
;
import
cn.quantgroup.xyqb.entity.UserDetail
;
import
cn.quantgroup.xyqb.model.IdType
;
import
cn.quantgroup.xyqb.entity.UserInfoEntity
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
...
...
@@ -14,7 +13,7 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
java.
sql.Timestamp
;
import
java.
time.LocalDateTime
;
@Slf4j
@RunWith
(
JUnit4
.
class
)
...
...
@@ -28,10 +27,10 @@ public class JsonTest {
@Test
public
void
intFloat
(){
try
{
User
Detail
userData
=
new
UserDetail
();
User
InfoEntity
userData
=
new
UserInfoEntity
();
userData
.
setId
(
131L
);
userData
.
setUserId
(
119L
);
userData
.
setCreatedAt
(
new
Timestamp
(
1
));
userData
.
setCreatedAt
(
LocalDateTime
.
now
(
));
log
.
info
(
"序列化--GSON--成功!data:{}"
,
JSON
.
toJSONString
(
userData
));
log
.
info
(
"序列化--MAPPER--成功!data:{}"
,
MAPPER
.
writeValueAsString
(
userData
));
log
.
info
(
"序列化--JSON--成功!data:{}"
,
JSON
.
toJSONString
(
userData
,
SerializerFeature
.
config
(
JSON
.
DEFAULT_GENERATE_FEATURE
,
SerializerFeature
.
WriteEnumUsingName
,
false
)));
...
...
@@ -44,7 +43,7 @@ public class JsonTest {
@Test
public
void
gsonGson
(){
try
{
User
Detail
userData
=
JSON
.
parseObject
(
body
,
UserDetail
.
class
);
User
InfoEntity
userData
=
JSON
.
parseObject
(
body
,
UserInfoEntity
.
class
);
log
.
info
(
"GSON--成功!data:{}"
,
userData
);
}
catch
(
Exception
e
){
log
.
error
(
"GSON--失败!"
,
e
);
...
...
@@ -54,7 +53,7 @@ public class JsonTest {
@Test
public
void
jacksonObjectMapper
(){
try
{
User
Detail
userData
=
MAPPER
.
readValue
(
body
,
UserDetail
.
class
);
User
InfoEntity
userData
=
MAPPER
.
readValue
(
body
,
UserInfoEntity
.
class
);
log
.
info
(
"MAPPER--成功!data:{}"
,
userData
);
}
catch
(
Exception
e
){
log
.
error
(
"MAPPER--失败!"
,
e
);
...
...
@@ -64,9 +63,9 @@ public class JsonTest {
@Test
public
void
fastjsonJSONObject
(){
try
{
User
Detail
userData
=
JSONObject
.
parseObject
(
body
,
UserDetail
.
class
);
User
InfoEntity
userData
=
JSONObject
.
parseObject
(
body
,
UserInfoEntity
.
class
);
log
.
info
(
"JSONObject--成功!data:{}"
,
userData
);
userData
=
JSON
.
parseObject
(
body
,
User
Detail
.
class
);
userData
=
JSON
.
parseObject
(
body
,
User
InfoEntity
.
class
);
log
.
info
(
"JSONObject--成功!data:{}"
,
userData
);
}
catch
(
Exception
e
){
log
.
error
(
"JSONObject--失败!"
,
e
);
...
...
src/test/java/demo/RepsitoryJpaTest.java
View file @
423b1579
...
...
@@ -18,8 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
javax.persistence.PersistenceException
;
import
java.sql.Timestamp
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
/**
* 持久层测试用例
...
...
@@ -55,7 +54,7 @@ public class RepsitoryJpaTest {
User
user
=
new
User
();
user
.
setPhoneNo
(
phone
);
user
.
setPassword
(
password
);
user
.
setCreatedAt
(
Timestamp
.
from
(
Instant
.
now
()
));
user
.
setCreatedAt
(
LocalDateTime
.
now
(
));
user
.
setUpdatedAt
(
user
.
getCreatedAt
());
user
=
userRepository
.
save
(
user
);
User
userRep
=
userRepository
.
findByPhoneNo
(
phone
);
...
...
src/test/java/demo/RepsitoryTest.java
View file @
423b1579
...
...
@@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.sql.Timestamp
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
/**
...
...
@@ -50,8 +49,8 @@ public class RepsitoryTest extends AbstractTransactionalJUnit4SpringContextTests
User
user
=
new
User
();
user
.
setPhoneNo
(
phone
);
user
.
setPassword
(
password
);
user
.
setCreatedAt
(
Timestamp
.
from
(
Instant
.
now
()
));
user
.
setUpdatedAt
(
user
.
getCreatedAt
());
user
.
setCreatedAt
(
LocalDateTime
.
now
(
));
user
.
setUpdatedAt
(
LocalDateTime
.
now
());
user
=
userRepository
.
save
(
user
);
User
userRep
=
userRepository
.
findByPhoneNo
(
phone
);
Assert
.
assertEquals
(
user
,
userRep
);
...
...
src/test/java/demo/ServiceTest.java
View file @
423b1579
...
...
@@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.sql.Timestamp
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
/**
* 业务层测试用例
...
...
@@ -49,7 +48,7 @@ public class ServiceTest extends AbstractTransactionalJUnit4SpringContextTests {
User
user
=
new
User
();
user
.
setPhoneNo
(
phone
);
user
.
setPassword
(
password
);
user
.
setCreatedAt
(
Timestamp
.
from
(
Instant
.
now
()
));
user
.
setCreatedAt
(
LocalDateTime
.
now
(
));
user
.
setUpdatedAt
(
user
.
getCreatedAt
());
user
=
userService
.
saveUser
(
user
);
User
userRep
=
userService
.
findByPhoneInDb
(
phone
);
...
...
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