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
a6a1cbec
Commit
a6a1cbec
authored
Apr 27, 2017
by
minminyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构部分代码
parent
77564145
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
503 additions
and
458 deletions
+503
-458
MotanUserServiceImpl.java
.../xyqb/controller/external/motan/MotanUserServiceImpl.java
+503
-458
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/motan/MotanUserServiceImpl.java
View file @
a6a1cbec
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
motan
;
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
motan
;
import
cn.quantgroup.bean.*
;
import
cn.quantgroup.bean.*
;
import
cn.quantgroup.service.*
;
import
cn.quantgroup.service.UserMotanService
;
import
cn.quantgroup.service.UserSysResult
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.entity.*
;
import
cn.quantgroup.xyqb.entity.*
;
import
cn.quantgroup.xyqb.entity.enumerate.*
;
import
cn.quantgroup.xyqb.entity.enumerate.*
;
import
cn.quantgroup.xyqb.model.*
;
import
cn.quantgroup.xyqb.model.IdCardInfo
;
import
cn.quantgroup.xyqb.model.session.*
;
import
cn.quantgroup.xyqb.model.IdType
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.UserRet
;
import
cn.quantgroup.xyqb.model.session.LoginInfo
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
import
cn.quantgroup.xyqb.service.merchant.IMerchantService
;
...
@@ -39,469 +44,509 @@ import java.util.Random;
...
@@ -39,469 +44,509 @@ import java.util.Random;
/**
/**
* Created by 11 on 2017/2/27.
* Created by 11 on 2017/2/27.
*/
*/
@MotanService
(
export
=
"userMotan:8002"
,
registry
=
"registryConfig"
)
@MotanService
(
export
=
"userMotan:8002"
,
registry
=
"registryConfig"
)
public
class
MotanUserServiceImpl
implements
UserMotanService
,
IBaseController
{
public
class
MotanUserServiceImpl
implements
UserMotanService
,
IBaseController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MotanUserServiceImpl
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MotanUserServiceImpl
.
class
);
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
static
{
MAPPER
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
static
{
}
MAPPER
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
}
@Autowired
private
IIdCardService
idCardService
;
@Autowired
@Autowired
private
IIdCardService
idCardService
;
private
IUserService
userService
;
@Autowired
@Autowired
private
IUserService
userService
;
private
IUserDetailService
userDetailService
;
@Autowired
@Autowired
private
IUserDetailService
userDetailService
;
private
IUserRepository
userRepository
;
@Autowired
@Autowired
private
IUserRepository
userRepository
;
private
ISmsService
smsService
;
@Autowired
@Autowired
private
ISmsService
smsService
;
private
ILkbUserService
lkbUserService
;
@Autowired
@Autowired
private
ILkbUserService
lkbUserService
;
private
IMerchantService
merchantService
;
@Autowired
@Autowired
private
IMerchantService
merchantService
;
private
ISessionService
sessionService
;
@Autowired
@Autowired
private
ISessionService
sessionService
;
private
IContactService
contactService
;
@Autowired
@Autowired
private
IContactService
contactService
;
private
IAddressService
addressService
;
@Autowired
@Autowired
private
IAddressService
addressService
;
private
IUserExtInfoService
userExtInfoService
;
@Autowired
@Autowired
private
IUserExtInfoService
userExtInfoService
;
private
IWechatService
wechatService
;
@Autowired
private
final
static
Random
random
=
new
Random
();
private
IWechatService
wechatService
;
private
final
static
Random
random
=
new
Random
();
@Override
public
UserSysResult
<
XUser
>
findUserByPhoneNo
(
String
phoneNo
)
{
@Override
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
public
UserSysResult
<
XUser
>
findUserByPhoneNo
(
String
phoneNo
)
{
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
returnValue
(
xUser
,
""
);
return
returnValue
(
null
,
"手机号格式不正确"
);
}
}
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
@Override
return
returnValue
(
fromUser
(
user
),
""
);
public
UserSysResult
<
XUser
>
findUserByUuid
(
String
uuid
)
{
}
User
user
=
userService
.
findByUuidInDb
(
uuid
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
@Override
return
returnValue
(
xUser
,
""
);
public
UserSysResult
<
XUser
>
findUserByUuid
(
String
uuid
)
{
}
if
(
StringUtils
.
isBlank
(
uuid
))
{
return
returnValue
(
null
,
"参数不能为空"
);
@Override
}
public
UserSysResult
<
XUser
>
saveUser
(
UserBean
userBean
)
{
User
user
=
userService
.
findByUuidInDb
(
uuid
);
UserSysResult
<
XUser
>
result
=
new
UserSysResult
<>();
return
returnValue
(
fromUser
(
user
),
""
);
if
(
null
==
userBean
)
{
}
result
.
setCode
(
"0001"
);
result
.
setBusinessCode
(
"0001"
);
@Override
result
.
setMsg
(
"要保存的用户对象不能为null"
);
public
UserSysResult
<
XUser
>
saveUser
(
UserBean
userBean
)
{
result
.
setData
(
null
);
if
(
null
==
userBean
||
!
ValidationUtil
.
validatePhoneNo
(
userBean
.
getPhoneNo
()))
{
return
result
;
return
returnValue
(
null
,
userBean
==
null
?
"要保存的用户对象不能为null"
:
"手机号不正确"
);
}
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
User
user
=
new
User
();
User
user
=
userService
.
findByPhoneWithCache
(
userBean
.
getPhoneNo
());
user
.
setCreatedAt
(
now
);
if
(
user
==
null
)
{
user
.
setUpdatedAt
(
now
);
user
=
new
User
();
user
.
setUuid
(
userBean
.
getUuid
());
user
.
setCreatedAt
(
now
);
user
.
setPhoneNo
(
userBean
.
getPhoneNo
());
user
.
setPhoneNo
(
userBean
.
getPhoneNo
());
user
.
setEnable
(
true
);
user
.
setEnable
(
true
);
user
.
setPassword
(
userBean
.
getPassword
());
String
password
=
userBean
.
getPassword
();
user
.
setRegisteredFrom
(
userBean
.
getRegisteredFrom
());
if
(
StringUtils
.
isBlank
(
password
))
{
User
saveUser
=
userService
.
saveUser
(
user
);
password
=
String
.
valueOf
(
random
.
nextInt
(
899999
)
+
100000
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
saveUser
),
new
TypeReference
<
XUser
>()
{});
}
return
returnValue
(
xUser
,
""
);
user
.
setPassword
(
PasswordUtil
.
MD5
(
password
+
Constants
.
PASSWORD_SALT
));
}
}
else
{
if
(
StringUtils
.
isNotBlank
(
user
.
getPassword
()))
{
@Override
user
.
setPassword
(
PasswordUtil
.
MD5
(
userBean
.
getPassword
()
+
Constants
.
PASSWORD_SALT
));
public
UserSysResult
<
XUserDetail
>
findUserDetailByUserId
(
Long
userId
)
{
}
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
}
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{});
user
.
setUpdatedAt
(
now
);
return
returnValue
(
xUserDetail
,
""
);
user
.
setUuid
(
userBean
.
getUuid
());
}
user
.
setRegisteredFrom
(
userBean
.
getRegisteredFrom
());
User
saveUser
=
userService
.
saveUser
(
user
);
@Override
return
returnValue
(
fromUser
(
saveUser
),
""
);
public
UserSysResult
<
XUser
>
findUserByUserId
(
Long
id
)
{
}
User
user
=
userService
.
findById
(
id
);
XUser
xUser
=
convertObject
(
JSON
.
toJSONString
(
user
),
new
TypeReference
<
XUser
>()
{});
@Override
return
returnValue
(
xUser
,
""
);
public
UserSysResult
<
XUserDetail
>
findUserDetailByUserId
(
Long
userId
)
{
}
if
(
userId
==
null
||
userId
.
longValue
()
<
1
)
{
return
returnValue
(
null
,
"参数必须是正整数"
);
@Override
public
UserSysResult
<
XUserDetail
>
findUserDetailByPhone
(
String
phoneNo
)
{
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{});
return
returnValue
(
xUserDetail
,
""
);
}
@Override
public
UserSysResult
<
XUserDetail
>
saveUserDetail
(
UserDetailUpdateBean
userDetailUpdateBean
)
{
UserSysResult
<
XUserDetail
>
result
=
new
UserSysResult
<>();
result
.
setCode
(
"0001"
);
result
.
setBusinessCode
(
"0001"
);
if
(
null
==
userDetailUpdateBean
)
{
result
.
setMsg
(
"要保存的用户详情对象不能为null"
);
result
.
setData
(
null
);
return
result
;
}
UserDetail
userDetail
=
new
UserDetail
();
if
(
null
!=
userDetailUpdateBean
.
getId
()
&&
userDetailUpdateBean
.
getId
()
>
0L
)
{
userDetail
.
setId
(
userDetailUpdateBean
.
getId
());
}
userDetail
.
setUserId
(
userDetailUpdateBean
.
getUserId
());
userDetail
.
setName
(
userDetailUpdateBean
.
getName
());
userDetail
.
setPhoneNo
(
userDetailUpdateBean
.
getPhoneNo
());
userDetail
.
setIdNo
(
userDetailUpdateBean
.
getIdNo
());
Timestamp
time
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setCreatedAt
(
time
);
userDetail
.
setUpdatedAt
(
time
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
try
{
userDetail
.
setGender
(
idCardService
.
getIdCardInfo
(
userDetailUpdateBean
.
getIdNo
()).
getGender
());
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"根据身份证获取性别出错,错误信息:"
+
e
);
result
.
setMsg
(
"根据身份证获取性别出错."
);
return
result
;
}
userDetail
.
setEmail
(
userDetailUpdateBean
.
getEmail
());
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
){
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{});
return
returnValue
(
xUserDetail
,
""
);
}
result
.
setMsg
(
""
);
return
result
;
}
@Override
public
UserSysResult
<
XLoginInfo
>
getLoginInfo
(
String
token
)
{
SessionStruct
sessionStruct
=
getSessionStruct
();
LoginInfo
loginInfo
=
new
LoginInfo
();
loginInfo
.
setUser
(
UserRet
.
getUserRet
(
sessionStruct
.
getValues
().
getUser
()));
loginInfo
.
setToken
(
sessionStruct
.
getSid
());
LoginInfo
.
LoginContext
context
=
new
LoginInfo
.
LoginContext
();
context
.
setChannelId
(
sessionStruct
.
getValues
().
getLoginProperties
().
getChannelId
());
context
.
setCreatedFrom
(
sessionStruct
.
getValues
().
getLoginProperties
().
getCreatedFrom
());
context
.
setAppChannel
(
sessionStruct
.
getValues
().
getLoginProperties
().
getAppChannel
());
loginInfo
.
setLoginContext
(
context
);
XLoginInfo
xLoginInfo
=
LoginInfo
.
getXLoginInfo
(
loginInfo
);
return
returnValue
(
xLoginInfo
,
""
);
}
@Override
public
UserSysResult
<
XLoginInfo
>
appLoginAndFetchLoginInfo
(
AppLoginParam
appLoginParam
,
HttpServletRequest
request
)
{
UserSysResult
<
XLoginInfo
>
userSysResult
=
returnValue
(
null
,
""
);
if
(!
ValidationUtil
.
validatePhoneNo
(
appLoginParam
.
getPhoneNo
()))
{
userSysResult
.
setMsg
(
"该用户名不存在,<br/>请重新输入或注册新账号。"
);
return
userSysResult
;
}
String
requestIp
=
IPUtil
.
getRemoteIP
(
request
);
LOGGER
.
info
(
"第三方用户登录, loginFrom:{}, requestIp:{}"
,
appLoginParam
.
getRegisterFrom
(),
requestIp
);
User
user
=
userService
.
findByPhoneInDb
(
appLoginParam
.
getPhoneNo
());
if
(
user
==
null
)
{
user
=
register
(
appLoginParam
.
getRegisterFrom
(),
appLoginParam
.
getPhoneNo
(),
appLoginParam
.
getIdNo
(),
appLoginParam
.
getName
());
}
if
(
user
==
null
)
{
userSysResult
.
setMsg
(
"该用户名不存在,<br/>请重新输入或注册新账号。"
);
return
userSysResult
;
}
Merchant
merchant
=
merchantService
.
findMerchantByName
(
appLoginParam
.
getKey
());
if
(
merchant
==
null
)
{
userSysResult
.
setMsg
(
"无效的商户"
);
return
userSysResult
;
}
LoginProperties
loginProperties
=
new
LoginProperties
();
loginProperties
.
setChannelId
(
appLoginParam
.
getChannelId
());
loginProperties
.
setMerchantName
(
merchant
.
getName
());
loginProperties
.
setCreatedFrom
(
appLoginParam
.
getRegisterFrom
());
loginProperties
.
setAppChannel
(
appLoginParam
.
getAppChannel
());
SessionStruct
sessionStruct
=
sessionService
.
createSessionAndPersist
(
user
,
loginProperties
);
LoginInfo
loginInfo
=
new
LoginInfo
();
loginInfo
.
setUser
(
UserRet
.
getUserRet
(
user
));
loginInfo
.
setToken
(
sessionStruct
.
getSid
());
LoginInfo
.
LoginContext
context
=
new
LoginInfo
.
LoginContext
();
context
.
setChannelId
(
sessionStruct
.
getValues
().
getLoginProperties
().
getChannelId
());
context
.
setCreatedFrom
(
sessionStruct
.
getValues
().
getLoginProperties
().
getCreatedFrom
());
context
.
setAppChannel
(
appLoginParam
.
getAppChannel
());
loginInfo
.
setLoginContext
(
context
);
LOGGER
.
info
(
"第三方用户获取信息登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
appLoginParam
.
getRegisterFrom
(),
appLoginParam
.
getPhoneNo
(),
appLoginParam
.
getAppChannel
());
XLoginInfo
xLoginInfo
=
convertObject
(
JSON
.
toJSONString
(
loginInfo
),
new
TypeReference
<
XLoginInfo
>()
{});
return
returnValue
(
xLoginInfo
,
""
);
}
private
<
T
>
T
convertObject
(
String
json
,
TypeReference
typeReference
)
{
try
{
if
(
StringUtils
.
isEmpty
(
json
))
{
return
null
;
}
return
MAPPER
.
readValue
(
json
,
typeReference
);
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"用户信息转换出错,错误信息{}"
,
ex
);
return
null
;
}
}
@Override
public
void
updateUserQQ
(
String
qq
,
Long
userId
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
0L
){
LOGGER
.
error
(
"QQ或用户id非法,不允许修改:qq{}, userid:{}"
,
qq
,
userId
);
return
;
}
userDetailService
.
updateUserQQ
(
userId
,
qq
);
}
@Override
public
UserSysResult
<
List
<
XContact
>>
findContactsByUserId
(
Long
userId
)
{
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
List
<
XContact
>
xContacts
=
convertObject
(
JSON
.
toJSONString
(
contacts
),
new
TypeReference
<
List
<
XContact
>>()
{});
return
returnValue
(
xContacts
,
""
);
}
@Override
public
UserSysResult
<
List
<
XContact
>>
saveContacts
(
Long
userId
,
List
<
XContact
>
contacts
)
{
UserSysResult
<
List
<
XContact
>>
userSysResult
=
returnValue
(
null
,
null
);
if
(
null
==
userId
||
userId
==
0L
)
{
LOGGER
.
error
(
"保存联系人列表,用户id为空"
);
return
userSysResult
;
}
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
LOGGER
.
error
(
"保存联系人列表,列表为空"
);
return
userSysResult
;
}
//做一次类型转换,
String
jsonContacts
=
JSON
.
toJSONString
(
contacts
);
List
<
Contact
>
contactList
=
null
;
try
{
contactList
=
MAPPER
.
readValue
(
jsonContacts
,
new
TypeReference
<
List
<
Contact
>>()
{});
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"联系人列表转换错误:{}"
,
e
.
getMessage
());
return
userSysResult
;
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
for
(
Contact
c
:
contactList
)
{
c
.
setId
(
null
);
c
.
setUserId
(
userId
);
c
.
setRelation
(
c
.
getRelation
()
==
null
?
Relation
.
OTHER
:
c
.
getRelation
());
c
.
setCreatedAt
(
now
);
c
.
setUpdateAt
(
now
);
}
List
<
Contact
>
result
=
contactService
.
save
(
contactList
);
List
<
XContact
>
xResult
=
convertObject
(
JSON
.
toJSONString
(
result
),
new
TypeReference
<
List
<
XContact
>>()
{});
return
returnValue
(
xResult
,
""
);
}
@Override
public
UserSysResult
<
XAddress
>
findAddressByUserId
(
Long
userId
)
{
UserSysResult
<
XAddress
>
userSysResult
=
returnValue
(
null
,
null
);
Address
address
=
addressService
.
findByUserId
(
userId
);
if
(
null
==
address
)
{
return
userSysResult
;
}
XAddress
xAddress
=
convertObject
(
JSON
.
toJSONString
(
address
),
new
TypeReference
<
XAddress
>()
{});
return
returnValue
(
xAddress
,
""
);
}
@Override
public
UserSysResult
<
XAddress
>
saveAddress
(
XAddress
xAddress
)
{
UserSysResult
<
XAddress
>
userSysResult
=
returnValue
(
null
,
null
);
if
(
null
==
xAddress
)
{
return
userSysResult
;
}
if
(
null
==
xAddress
.
getUserId
()
||
null
==
xAddress
.
getProvinceCode
()
||
null
==
xAddress
.
getCityCode
())
{
return
userSysResult
;
}
Address
addressObj
=
addressService
.
findByUserId
(
xAddress
.
getUserId
());
if
(
addressObj
==
null
)
{
addressObj
=
new
Address
();
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
addressObj
.
setCreatedAt
(
now
);
addressObj
.
setUpdateAt
(
now
);
}
addressObj
.
setUserId
(
xAddress
.
getUserId
());
addressObj
.
setProvinceCode
(
xAddress
.
getProvinceCode
());
addressObj
.
setCityCode
(
xAddress
.
getCityCode
());
addressObj
.
setCity
(
xAddress
.
getCity
());
addressObj
.
setDistrictCode
(
xAddress
.
getDistrictCode
());
addressObj
.
setDistrict
(
xAddress
.
getDistrict
());
addressObj
.
setAddress
(
xAddress
.
getAddress
());
addressObj
.
setProvince
(
xAddress
.
getProvince
());
addressObj
=
addressService
.
save
(
addressObj
);
XAddress
address
=
convertObject
(
JSON
.
toJSONString
(
addressObj
),
new
TypeReference
<
XAddress
>()
{});
return
returnValue
(
address
,
""
);
}
@Override
public
UserSysResult
<
XUserExtInfo
>
updateUserExtInfo
(
XUserExtInfo
xUserExtInfo
)
{
UserSysResult
<
XUserExtInfo
>
userSysResult
=
returnValue
(
null
,
null
);
if
(
null
==
xUserExtInfo
)
{
return
userSysResult
;
}
if
(
null
==
xUserExtInfo
.
getUserId
()
||
0L
==
xUserExtInfo
.
getUserId
())
{
return
userSysResult
;
}
if
(
null
==
xUserExtInfo
.
getUserId
())
{
userSysResult
.
setMsg
(
"用户ID不能为空"
);
return
userSysResult
;
}
UserExtInfo
info
=
userExtInfoService
.
findByUserId
(
xUserExtInfo
.
getUserId
());
if
(
info
==
null
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
info
=
new
UserExtInfo
();
info
.
setUserId
(
xUserExtInfo
.
getUserId
());
info
.
setCreatedAt
(
now
);
info
.
setUpdateAt
(
now
);
}
if
(
xUserExtInfo
.
getIncomeEnum
()
!=
null
)
{
info
.
setIncomeEnum
(
IncomeEnum
.
valueOf
(
xUserExtInfo
.
getIncomeEnum
().
name
()));
}
if
(
xUserExtInfo
.
getIncomeRangeEnum
()
!=
null
)
{
info
.
setIncomeRangeEnum
(
IncomeRangeEnum
.
valueOf
(
xUserExtInfo
.
getIncomeRangeEnum
().
name
()));
}
if
(
xUserExtInfo
.
getOccupationEnum
()
!=
null
)
{
info
.
setOccupationEnum
(
OccupationEnum
.
valueOf
(
xUserExtInfo
.
getOccupationEnum
().
name
()));
}
if
(
xUserExtInfo
.
getEducationEnum
()
!=
null
)
{
info
.
setEducationEnum
(
EducationEnum
.
valueOf
(
xUserExtInfo
.
getEducationEnum
().
name
()));
}
if
(
xUserExtInfo
.
getHasCar
()
!=
null
)
{
info
.
setHasCar
(
xUserExtInfo
.
getHasCar
());
}
if
(
xUserExtInfo
.
getHasCreditCard
()
!=
null
)
{
info
.
setHasCreditCard
(
xUserExtInfo
.
getHasCreditCard
());
}
if
(
xUserExtInfo
.
getHasHouse
()
!=
null
)
{
info
.
setHasHouse
(
xUserExtInfo
.
getHasHouse
());
}
if
(
xUserExtInfo
.
getMarryStatus
()
!=
null
)
{
info
.
setMarryStatus
(
MaritalStatus
.
valueOf
(
xUserExtInfo
.
getMarryStatus
().
name
()));
}
info
=
userExtInfoService
.
save
(
info
);
XUserExtInfo
userExtInfo
=
convertObject
(
JSON
.
toJSONString
(
info
),
new
TypeReference
<
XUserExtInfo
>()
{});
return
returnValue
(
userExtInfo
,
""
);
}
@Override
public
UserSysResult
<
String
>
queryOpenIdByXyqbUserId
(
Long
userId
)
{
UserSysResult
<
String
>
userSysResult
=
returnValue
(
null
,
null
);
if
(
userId
==
null
)
{
userSysResult
.
setMsg
(
"userId不能为空"
);
return
userSysResult
;
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
if
(
wechatUserInfo
==
null
)
{
return
userSysResult
;
}
return
returnValue
(
wechatUserInfo
.
getOpenId
(),
"success"
);
}
@Override
public
UserSysResult
<
Boolean
>
disableUser
(
Long
userId
)
{
return
null
;
}
}
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
XUserDetail
xUserDetail
=
fromUserDetail
(
userDetail
);
return
returnValue
(
xUserDetail
,
""
);
}
private
XUserDetail
fromUserDetail
(
UserDetail
userDetail
)
{
if
(
userDetail
==
null
)
{
return
null
;
}
XUserDetail
xUserDetail
=
new
XUserDetail
();
xUserDetail
.
setId
(
userDetail
.
getId
());
xUserDetail
.
setUserId
(
userDetail
.
getUserId
());
xUserDetail
.
setPhoneNo
(
userDetail
.
getPhoneNo
());
xUserDetail
.
setName
(
userDetail
.
getName
());
xUserDetail
.
setIdNo
(
userDetail
.
getIdNo
());
xUserDetail
.
setIdType
(
cn
.
quantgroup
.
enums
.
IdType
.
valueOf
(
userDetail
.
getIdType
().
getName
()));
xUserDetail
.
setGender
(
cn
.
quantgroup
.
enums
.
Gender
.
valueOf
(
userDetail
.
getGender
().
getName
()));
xUserDetail
.
setEmail
(
userDetail
.
getEmail
());
xUserDetail
.
setQq
(
userDetail
.
getQq
());
xUserDetail
.
setId
(
userDetail
.
getId
());
xUserDetail
.
setCreatedAt
(
userDetail
.
getCreatedAt
());
xUserDetail
.
setUpdatedAt
(
userDetail
.
getUpdatedAt
());
xUserDetail
.
setIsAuthenticated
(
userDetail
.
getIsAuthenticated
());
return
xUserDetail
;
}
private
XUser
fromUser
(
User
user
)
{
if
(
user
==
null
)
{
return
null
;
}
XUser
xUser
=
new
XUser
();
xUser
.
setUpdatedAt
(
user
.
getUpdatedAt
());
xUser
.
setId
(
user
.
getId
());
xUser
.
setPassword
(
user
.
getPassword
());
xUser
.
setRegisteredFrom
(
user
.
getRegisteredFrom
());
xUser
.
setUuid
(
user
.
getUuid
());
xUser
.
setEnable
(
user
.
getEnable
());
xUser
.
setPhoneNo
(
user
.
getPhoneNo
());
xUser
.
setUpdatedAt
(
user
.
getUpdatedAt
());
return
xUser
;
}
@Override
public
UserSysResult
<
XUser
>
findUserByUserId
(
Long
id
)
{
if
(
id
==
null
||
id
.
longValue
()
<
1
)
{
return
returnValue
(
null
,
"参数必须是正整数"
);
}
User
user
=
userService
.
findById
(
id
);
return
returnValue
(
fromUser
(
user
),
""
);
}
@Override
@Override
public
UserSysResult
<
String
>
queryOpenIdByPhoneNo
(
String
phoneNo
)
{
public
UserSysResult
<
XUserDetail
>
findUserDetailByPhone
(
String
phoneNo
)
{
UserSysResult
<
String
>
userSysResult
=
returnValue
(
null
,
null
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
returnValue
(
null
,
"手机号格式不正确"
);
userSysResult
.
setMsg
(
"手机号错误"
);
}
return
userSysResult
;
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
}
return
returnValue
(
fromUserDetail
(
userDetail
),
""
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
}
userSysResult
.
setMsg
(
"手机号格式错误"
);
return
userSysResult
;
@Override
}
public
UserSysResult
<
XUserDetail
>
saveUserDetail
(
UserDetailUpdateBean
userDetailUpdateBean
)
{
WechatUserInfo
wechatUserInfo
=
wechatService
.
findWechatUserInfoByPhoneNo
(
phoneNo
);
if
(
null
==
userDetailUpdateBean
)
{
String
openId
=
null
==
wechatUserInfo
?
null
:
wechatUserInfo
.
getOpenId
();
return
returnValue
(
null
,
"要保存的用户详情对象不能为null"
);
return
returnValue
(
openId
,
null
);
}
}
UserDetail
userDetail
=
new
UserDetail
();
if
(
null
!=
userDetailUpdateBean
.
getId
()
&&
userDetailUpdateBean
.
getId
()
>
0L
)
{
@Override
userDetail
.
setId
(
userDetailUpdateBean
.
getId
());
public
UserSysResult
<
UserRegisterTrace
>
findRegisterTraceByPhoneNo
(
String
s
)
{
}
userDetail
.
setUserId
(
userDetailUpdateBean
.
getUserId
());
userDetail
.
setName
(
userDetailUpdateBean
.
getName
());
userDetail
.
setPhoneNo
(
userDetailUpdateBean
.
getPhoneNo
());
userDetail
.
setIdNo
(
userDetailUpdateBean
.
getIdNo
());
Timestamp
time
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setCreatedAt
(
time
);
userDetail
.
setUpdatedAt
(
time
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
try
{
userDetail
.
setGender
(
idCardService
.
getIdCardInfo
(
userDetailUpdateBean
.
getIdNo
()).
getGender
());
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"根据身份证获取性别出错,错误信息:"
+
e
);
return
returnValue
(
null
,
"根据身份证获取性别出错."
);
}
userDetail
.
setEmail
(
userDetailUpdateBean
.
getEmail
());
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
)
{
XUserDetail
xUserDetail
=
convertObject
(
JSON
.
toJSONString
(
userDetail
),
new
TypeReference
<
XUserDetail
>()
{
});
return
returnValue
(
xUserDetail
,
""
);
}
return
returnValue
(
null
,
"保存失败"
);
}
@Override
public
UserSysResult
<
XLoginInfo
>
getLoginInfo
(
String
token
)
{
SessionStruct
sessionStruct
=
getSessionStruct
();
LoginInfo
loginInfo
=
new
LoginInfo
();
loginInfo
.
setUser
(
UserRet
.
getUserRet
(
sessionStruct
.
getValues
().
getUser
()));
loginInfo
.
setToken
(
sessionStruct
.
getSid
());
LoginInfo
.
LoginContext
context
=
new
LoginInfo
.
LoginContext
();
context
.
setChannelId
(
sessionStruct
.
getValues
().
getLoginProperties
().
getChannelId
());
context
.
setCreatedFrom
(
sessionStruct
.
getValues
().
getLoginProperties
().
getCreatedFrom
());
context
.
setAppChannel
(
sessionStruct
.
getValues
().
getLoginProperties
().
getAppChannel
());
loginInfo
.
setLoginContext
(
context
);
XLoginInfo
xLoginInfo
=
LoginInfo
.
getXLoginInfo
(
loginInfo
);
return
returnValue
(
xLoginInfo
,
""
);
}
@Override
public
UserSysResult
<
XLoginInfo
>
appLoginAndFetchLoginInfo
(
AppLoginParam
appLoginParam
,
HttpServletRequest
request
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
appLoginParam
.
getPhoneNo
()))
{
return
returnValue
(
null
,
"账户或者密码错误"
);
}
String
requestIp
=
IPUtil
.
getRemoteIP
(
request
);
LOGGER
.
info
(
"第三方用户登录, loginFrom:{}, requestIp:{}"
,
appLoginParam
.
getRegisterFrom
(),
requestIp
);
User
user
=
userService
.
findByPhoneInDb
(
appLoginParam
.
getPhoneNo
());
if
(
user
==
null
)
{
user
=
register
(
appLoginParam
.
getRegisterFrom
(),
appLoginParam
.
getPhoneNo
(),
appLoginParam
.
getIdNo
(),
appLoginParam
.
getName
());
}
if
(
user
==
null
)
{
return
returnValue
(
null
,
"账户或者密码错误"
);
}
Merchant
merchant
=
merchantService
.
findMerchantByName
(
appLoginParam
.
getKey
());
if
(
merchant
==
null
)
{
return
returnValue
(
null
,
"无效的商户"
);
}
LoginProperties
loginProperties
=
new
LoginProperties
();
loginProperties
.
setChannelId
(
appLoginParam
.
getChannelId
());
loginProperties
.
setMerchantName
(
merchant
.
getName
());
loginProperties
.
setCreatedFrom
(
appLoginParam
.
getRegisterFrom
());
loginProperties
.
setAppChannel
(
appLoginParam
.
getAppChannel
());
SessionStruct
sessionStruct
=
sessionService
.
createSessionAndPersist
(
user
,
loginProperties
);
LoginInfo
loginInfo
=
new
LoginInfo
();
loginInfo
.
setUser
(
UserRet
.
getUserRet
(
user
));
loginInfo
.
setToken
(
sessionStruct
.
getSid
());
LoginInfo
.
LoginContext
context
=
new
LoginInfo
.
LoginContext
();
context
.
setChannelId
(
sessionStruct
.
getValues
().
getLoginProperties
().
getChannelId
());
context
.
setCreatedFrom
(
sessionStruct
.
getValues
().
getLoginProperties
().
getCreatedFrom
());
context
.
setAppChannel
(
appLoginParam
.
getAppChannel
());
loginInfo
.
setLoginContext
(
context
);
LOGGER
.
info
(
"第三方用户获取信息登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
appLoginParam
.
getRegisterFrom
(),
appLoginParam
.
getPhoneNo
(),
appLoginParam
.
getAppChannel
());
XLoginInfo
xLoginInfo
=
convertObject
(
JSON
.
toJSONString
(
loginInfo
),
new
TypeReference
<
XLoginInfo
>()
{
});
return
returnValue
(
xLoginInfo
,
""
);
}
private
<
T
>
T
convertObject
(
String
json
,
TypeReference
typeReference
)
{
try
{
if
(
StringUtils
.
isEmpty
(
json
))
{
return
null
;
return
null
;
}
return
MAPPER
.
readValue
(
json
,
typeReference
);
}
catch
(
Exception
ex
)
{
LOGGER
.
error
(
"用户信息转换出错,错误信息{}"
,
ex
);
return
null
;
}
}
}
@Override
public
void
updateUserQQ
(
String
qq
,
Long
userId
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
)
{
LOGGER
.
error
(
"QQ或用户id非法,不允许修改:qq{}, userid:{}"
,
qq
,
userId
);
return
;
}
userDetailService
.
updateUserQQ
(
userId
,
qq
);
}
@Override
public
UserSysResult
<
List
<
XContact
>>
findContactsByUserId
(
Long
userId
)
{
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
List
<
XContact
>
xContacts
=
convertObject
(
JSON
.
toJSONString
(
contacts
),
new
TypeReference
<
List
<
XContact
>>()
{
});
return
returnValue
(
xContacts
,
""
);
}
@Override
public
UserSysResult
<
List
<
XContact
>>
saveContacts
(
Long
userId
,
List
<
XContact
>
contacts
)
{
if
(
null
==
userId
||
userId
==
0L
)
{
return
returnValue
(
null
,
"保存联系人列表失败,用户id为空"
);
}
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
return
returnValue
(
null
,
"保存联系人列表失败,列表为空"
);
}
//做一次类型转换,
String
jsonContacts
=
JSON
.
toJSONString
(
contacts
);
List
<
Contact
>
contactList
=
null
;
try
{
contactList
=
MAPPER
.
readValue
(
jsonContacts
,
new
TypeReference
<
List
<
Contact
>>()
{
});
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"联系人列表转换错误:{}"
,
e
.
getMessage
());
return
returnValue
(
null
,
"联系人转换错误"
);
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
for
(
Contact
c
:
contactList
)
{
c
.
setId
(
null
);
c
.
setUserId
(
userId
);
c
.
setRelation
(
c
.
getRelation
()
==
null
?
Relation
.
OTHER
:
c
.
getRelation
());
c
.
setCreatedAt
(
now
);
c
.
setUpdateAt
(
now
);
}
List
<
Contact
>
result
=
contactService
.
save
(
contactList
);
List
<
XContact
>
xResult
=
convertObject
(
JSON
.
toJSONString
(
result
),
new
TypeReference
<
List
<
XContact
>>()
{
});
return
returnValue
(
xResult
,
""
);
}
@Override
public
UserSysResult
<
XAddress
>
findAddressByUserId
(
Long
userId
)
{
UserSysResult
<
XAddress
>
userSysResult
=
returnValue
(
null
,
null
);
Address
address
=
addressService
.
findByUserId
(
userId
);
if
(
null
==
address
)
{
return
userSysResult
;
}
XAddress
xAddress
=
convertObject
(
JSON
.
toJSONString
(
address
),
new
TypeReference
<
XAddress
>()
{
});
return
returnValue
(
xAddress
,
""
);
}
@Override
public
UserSysResult
<
XAddress
>
saveAddress
(
XAddress
xAddress
)
{
UserSysResult
<
XAddress
>
userSysResult
=
returnValue
(
null
,
null
);
if
(
null
==
xAddress
)
{
return
userSysResult
;
}
if
(
null
==
xAddress
.
getUserId
()
||
null
==
xAddress
.
getProvinceCode
()
||
null
==
xAddress
.
getCityCode
())
{
return
userSysResult
;
}
Address
addressObj
=
addressService
.
findByUserId
(
xAddress
.
getUserId
());
if
(
addressObj
==
null
)
{
addressObj
=
new
Address
();
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
addressObj
.
setCreatedAt
(
now
);
addressObj
.
setUpdateAt
(
now
);
}
addressObj
.
setUserId
(
xAddress
.
getUserId
());
addressObj
.
setProvinceCode
(
xAddress
.
getProvinceCode
());
addressObj
.
setCityCode
(
xAddress
.
getCityCode
());
addressObj
.
setCity
(
xAddress
.
getCity
());
addressObj
.
setDistrictCode
(
xAddress
.
getDistrictCode
());
addressObj
.
setDistrict
(
xAddress
.
getDistrict
());
addressObj
.
setAddress
(
xAddress
.
getAddress
());
addressObj
.
setProvince
(
xAddress
.
getProvince
());
addressObj
=
addressService
.
save
(
addressObj
);
XAddress
address
=
convertObject
(
JSON
.
toJSONString
(
addressObj
),
new
TypeReference
<
XAddress
>()
{
});
return
returnValue
(
address
,
""
);
}
@Override
public
UserSysResult
<
XUserExtInfo
>
updateUserExtInfo
(
XUserExtInfo
xUserExtInfo
)
{
UserSysResult
<
XUserExtInfo
>
userSysResult
=
returnValue
(
null
,
null
);
if
(
null
==
xUserExtInfo
)
{
return
userSysResult
;
}
if
(
null
==
xUserExtInfo
.
getUserId
()
||
0L
==
xUserExtInfo
.
getUserId
())
{
return
returnValue
(
null
,
"用户id为空"
);
}
UserExtInfo
info
=
userExtInfoService
.
findByUserId
(
xUserExtInfo
.
getUserId
());
if
(
info
==
null
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
info
=
new
UserExtInfo
();
info
.
setUserId
(
xUserExtInfo
.
getUserId
());
info
.
setCreatedAt
(
now
);
info
.
setUpdateAt
(
now
);
}
if
(
xUserExtInfo
.
getIncomeEnum
()
!=
null
)
{
info
.
setIncomeEnum
(
IncomeEnum
.
valueOf
(
xUserExtInfo
.
getIncomeEnum
().
name
()));
}
if
(
xUserExtInfo
.
getIncomeRangeEnum
()
!=
null
)
{
info
.
setIncomeRangeEnum
(
IncomeRangeEnum
.
valueOf
(
xUserExtInfo
.
getIncomeRangeEnum
().
name
()));
}
if
(
xUserExtInfo
.
getOccupationEnum
()
!=
null
)
{
info
.
setOccupationEnum
(
OccupationEnum
.
valueOf
(
xUserExtInfo
.
getOccupationEnum
().
name
()));
}
if
(
xUserExtInfo
.
getEducationEnum
()
!=
null
)
{
info
.
setEducationEnum
(
EducationEnum
.
valueOf
(
xUserExtInfo
.
getEducationEnum
().
name
()));
}
if
(
xUserExtInfo
.
getHasCar
()
!=
null
)
{
info
.
setHasCar
(
xUserExtInfo
.
getHasCar
());
}
if
(
xUserExtInfo
.
getHasCreditCard
()
!=
null
)
{
info
.
setHasCreditCard
(
xUserExtInfo
.
getHasCreditCard
());
}
if
(
xUserExtInfo
.
getHasHouse
()
!=
null
)
{
info
.
setHasHouse
(
xUserExtInfo
.
getHasHouse
());
}
if
(
xUserExtInfo
.
getMarryStatus
()
!=
null
)
{
info
.
setMarryStatus
(
MaritalStatus
.
valueOf
(
xUserExtInfo
.
getMarryStatus
().
name
()));
}
info
=
userExtInfoService
.
save
(
info
);
XUserExtInfo
userExtInfo
=
convertObject
(
JSON
.
toJSONString
(
info
),
new
TypeReference
<
XUserExtInfo
>()
{
});
return
returnValue
(
userExtInfo
,
""
);
}
@Override
public
UserSysResult
<
String
>
queryOpenIdByXyqbUserId
(
Long
userId
)
{
if
(
userId
==
null
||
userId
<
1
)
{
return
returnValue
(
null
,
"用户id不能为空"
);
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
if
(
wechatUserInfo
==
null
)
{
return
returnValue
(
null
,
"wechat信息为空"
);
}
return
returnValue
(
wechatUserInfo
.
getOpenId
(),
"success"
);
}
@Override
public
UserSysResult
<
Boolean
>
disableUser
(
Long
userId
)
{
return
null
;
}
@Override
public
UserSysResult
<
String
>
queryOpenIdByPhoneNo
(
String
phoneNo
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
returnValue
(
null
,
"手机号格式不正确"
);
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
findWechatUserInfoByPhoneNo
(
phoneNo
);
String
openId
=
null
==
wechatUserInfo
?
null
:
wechatUserInfo
.
getOpenId
();
return
returnValue
(
openId
,
null
);
}
@Override
public
UserSysResult
<
UserRegisterTrace
>
findRegisterTraceByPhoneNo
(
String
phoneNo
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
returnValue
(
null
,
"手机号格式不正确"
);
}
return
null
;
}
/**
* 封装返回结果.
*
* @param t
* @param message
* @param <T>
* @return
*/
private
<
T
>
UserSysResult
<
T
>
returnValue
(
T
t
,
String
message
)
{
UserSysResult
<
T
>
userSysResult
=
new
UserSysResult
();
userSysResult
.
setMsg
(
message
);
/**
/**
* 封装返回结果.
* 无返回结果时,返回的code和BusinessCode均是0001
* @param t
* @param message
* @param <T>
* @return
*/
*/
private
<
T
>
UserSysResult
<
T
>
returnValue
(
T
t
,
String
message
)
{
if
(
null
==
t
)
{
UserSysResult
<
T
>
userSysResult
=
new
UserSysResult
();
userSysResult
.
setBusinessCode
(
"0001"
);
userSysResult
.
setMsg
(
message
);
userSysResult
.
setCode
(
"0001"
);
/**
}
else
{
* 无返回结果时,返回的code和BusinessCode均是0001
userSysResult
.
setBusinessCode
(
"0000"
);
*/
userSysResult
.
setCode
(
"0000"
);
if
(
null
==
t
)
{
}
userSysResult
.
setData
(
null
);
userSysResult
.
setData
(
t
);
userSysResult
.
setBusinessCode
(
"0001"
);
return
userSysResult
;
userSysResult
.
setCode
(
"0001"
);
}
}
else
{
userSysResult
.
setData
(
t
);
/**
userSysResult
.
setBusinessCode
(
"0000"
);
* 注册新用户
userSysResult
.
setCode
(
"0000"
);
*
}
* @return
return
userSysResult
;
*/
private
User
register
(
Long
registerFrom
,
String
phoneNo
,
String
idNo
,
String
name
)
{
String
randomCode
=
String
.
valueOf
(
random
.
nextInt
(
899999
)
+
100000
);
String
uuid
=
lkbUserService
.
registerApp
(
phoneNo
,
randomCode
);
Timestamp
currentTime
=
new
Timestamp
(
System
.
currentTimeMillis
());
LOGGER
.
info
(
"第三方登录用户,保存 User"
);
User
user
=
new
User
();
user
.
setRegisteredFrom
(
registerFrom
);
user
.
setUuid
(
uuid
);
user
.
setEnable
(
true
);
user
.
setPhoneNo
(
phoneNo
);
user
.
setPassword
(
PasswordUtil
.
MD5
(
randomCode
+
Constants
.
PASSWORD_SALT
));
user
.
setUpdatedAt
(
currentTime
);
user
.
setCreatedAt
(
currentTime
);
userRepository
.
saveAndFlush
(
user
);
if
(
registerFrom
!=
645L
)
{
smsService
.
sendAfterRegister
(
phoneNo
);
LOGGER
.
info
(
"第三方登录用户注册成功, registerFrom:{}, phoneNo:{}, 并且已发送短信通知"
,
registerFrom
,
phoneNo
);
}
}
/**
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotEmpty
(
idNo
)
&&
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotEmpty
(
name
))
{
* 注册新用户
LOGGER
.
info
(
"第三方登录用户,保存 UserDetail"
);
*
* @return
IdCardInfo
cardInfo
;
*/
try
{
private
User
register
(
Long
registerFrom
,
String
phoneNo
,
String
idNo
,
String
name
)
{
cardInfo
=
idCardService
.
getIdCardInfoWithExceptions
(
idNo
);
String
randomCode
=
String
.
valueOf
(
random
.
nextInt
(
899999
)
+
100000
);
UserDetail
userDetail
=
new
UserDetail
();
userDetail
.
setIdNo
(
cardInfo
.
getIdNo
());
String
uuid
=
lkbUserService
.
registerApp
(
phoneNo
,
randomCode
);
userDetail
.
setPhoneNo
(
phoneNo
);
Timestamp
currentTime
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setName
(
name
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
LOGGER
.
info
(
"第三方登录用户,保存 User"
);
userDetail
.
setCreatedAt
(
currentTime
);
userDetail
.
setUpdatedAt
(
currentTime
);
User
user
=
new
User
();
userDetail
.
setUserId
(
user
.
getId
());
user
.
setRegisteredFrom
(
registerFrom
);
userDetail
.
setGender
(
cardInfo
.
getGender
());
user
.
setUuid
(
uuid
);
userDetailService
.
saveUserDetail
(
userDetail
);
user
.
setEnable
(
true
);
user
.
setPhoneNo
(
phoneNo
);
lkbUserService
.
userUpdate
(
user
.
getUuid
(),
name
,
idNo
);
user
.
setPassword
(
PasswordUtil
.
MD5
(
randomCode
+
Constants
.
PASSWORD_SALT
));
}
catch
(
Exception
e
)
{
user
.
setUpdatedAt
(
currentTime
);
LOGGER
.
error
(
"保存 UserDetail 出现异常"
,
e
);
user
.
setCreatedAt
(
currentTime
);
}
userRepository
.
saveAndFlush
(
user
);
if
(
registerFrom
!=
645L
)
{
smsService
.
sendAfterRegister
(
phoneNo
);
LOGGER
.
info
(
"第三方登录用户注册成功, registerFrom:{}, phoneNo:{}, 并且已发送短信通知"
,
registerFrom
,
phoneNo
);
}
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotEmpty
(
idNo
)
&&
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotEmpty
(
name
))
{
LOGGER
.
info
(
"第三方登录用户,保存 UserDetail"
);
IdCardInfo
cardInfo
;
try
{
cardInfo
=
idCardService
.
getIdCardInfoWithExceptions
(
idNo
);
UserDetail
userDetail
=
new
UserDetail
();
userDetail
.
setIdNo
(
cardInfo
.
getIdNo
());
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setName
(
name
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
userDetail
.
setCreatedAt
(
currentTime
);
userDetail
.
setUpdatedAt
(
currentTime
);
userDetail
.
setUserId
(
user
.
getId
());
userDetail
.
setGender
(
cardInfo
.
getGender
());
userDetailService
.
saveUserDetail
(
userDetail
);
lkbUserService
.
userUpdate
(
user
.
getUuid
(),
name
,
idNo
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"保存 UserDetail 出现异常"
,
e
);
}
}
return
user
;
}
}
return
user
;
}
}
}
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