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
45f5f605
Commit
45f5f605
authored
Apr 24, 2017
by
minminyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
禁用用户的同时删除相应的缓存
parent
8aa4d2be
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
435 additions
and
421 deletions
+435
-421
InnerController.java
...tgroup/xyqb/controller/external/user/InnerController.java
+310
-302
ISessionService.java
...a/cn/quantgroup/xyqb/service/session/ISessionService.java
+11
-8
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+114
-111
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/InnerController.java
View file @
45f5f605
...
...
@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.*;
import
cn.quantgroup.xyqb.entity.enumerate.*
;
import
cn.quantgroup.xyqb.model.*
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.user.*
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -28,343 +29,350 @@ import java.util.List;
@RequestMapping
(
"/innerapi"
)
public
class
InnerController
{
private
static
final
org
.
slf4j
.
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
InnerController
.
class
);
private
static
final
org
.
slf4j
.
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
InnerController
.
class
);
@Autowired
private
IUserService
userService
;
@Autowired
private
IUserDetailService
userDetailService
;
@Autowired
private
IIdCardService
idCardService
;
@Autowired
private
IUserExtInfoService
userExtInfoService
;
@Autowired
private
IContactService
contactService
;
@Autowired
private
IAddressService
addressService
;
@Autowired
private
IWechatService
wechatService
;
@Autowired
private
IUserService
userService
;
@Autowired
private
IUserDetailService
userDetailService
;
@Autowired
private
IIdCardService
idCardService
;
@Autowired
private
IUserExtInfoService
userExtInfoService
;
@Autowired
private
IContactService
contactService
;
@Autowired
private
IAddressService
addressService
;
@Autowired
private
IWechatService
wechatService
;
@Autowired
private
ISessionService
sessionService
;
@RequestMapping
(
"/user/search/phoneNo"
)
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
user
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
UserRet
userRet
=
UserRet
.
getUserRet
(
user
);
return
JsonResult
.
buildSuccessResult
(
""
,
userRet
);
@RequestMapping
(
"/user/search/phoneNo"
)
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
User
user
=
userService
.
findByPhoneInDb
(
phoneNo
);
if
(
user
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
UserRet
userRet
=
UserRet
.
getUserRet
(
user
);
return
JsonResult
.
buildSuccessResult
(
""
,
userRet
);
}
@RequestMapping
(
"/user/search/uuid"
)
public
JsonResult
findByUuid
(
String
uuid
)
{
User
user
=
userService
.
findByUuidInDb
(
uuid
);
if
(
user
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
UserRet
userRet
=
UserRet
.
getUserRet
(
user
);
return
JsonResult
.
buildSuccessResult
(
""
,
userRet
);
@RequestMapping
(
"/user/search/uuid"
)
public
JsonResult
findByUuid
(
String
uuid
)
{
User
user
=
userService
.
findByUuidInDb
(
uuid
);
if
(
user
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
UserRet
userRet
=
UserRet
.
getUserRet
(
user
);
return
JsonResult
.
buildSuccessResult
(
""
,
userRet
);
}
@RequestMapping
(
"/user/save"
)
public
JsonResult
saveUser
(
String
phoneNo
,
Long
registeredFrom
,
Long
createdAt
,
Long
updatedAt
,
String
password
,
String
uuid
)
{
//参数验证
if
(
StringUtils
.
isBlank
(
phoneNo
)){
return
JsonResult
.
buildErrorStateResult
(
"用户手机号不能为空."
,
null
);
}
if
(
registeredFrom
==
null
){
registeredFrom
=
0L
;
}
if
(
StringUtils
.
isBlank
(
password
)){
password
=
""
;
}
if
(
StringUtils
.
isBlank
(
uuid
)){
return
JsonResult
.
buildErrorStateResult
(
"用户uuid为空."
,
null
);
}
if
(
createdAt
==
0L
||
updatedAt
==
0L
){
createdAt
=
System
.
currentTimeMillis
();
updatedAt
=
System
.
currentTimeMillis
();
}
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
user
==
null
)
{
user
=
new
User
();
}
user
.
setPhoneNo
(
phoneNo
);
user
.
setCreatedAt
(
new
Timestamp
(
createdAt
));
user
.
setUpdatedAt
(
new
Timestamp
(
updatedAt
));
user
.
setEnable
(
true
);
user
.
setRegisteredFrom
(
registeredFrom
);
user
.
setUuid
(
uuid
);
user
.
setPassword
(
password
);
user
=
userService
.
saveUser
(
user
);
UserRet
userRet
=
null
;
if
(
user
!=
null
){
userRet
=
UserRet
.
getUserRet
(
user
);
}
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
@RequestMapping
(
"/user/save"
)
public
JsonResult
saveUser
(
String
phoneNo
,
Long
registeredFrom
,
Long
createdAt
,
Long
updatedAt
,
String
password
,
String
uuid
)
{
//参数验证
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户手机号不能为空."
,
null
);
}
if
(
registeredFrom
==
null
)
{
registeredFrom
=
0L
;
}
if
(
StringUtils
.
isBlank
(
password
))
{
password
=
""
;
}
if
(
StringUtils
.
isBlank
(
uuid
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户uuid为空."
,
null
);
}
if
(
createdAt
==
0L
||
updatedAt
==
0L
)
{
createdAt
=
System
.
currentTimeMillis
();
updatedAt
=
System
.
currentTimeMillis
();
}
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
user
==
null
)
{
user
=
new
User
();
}
user
.
setPhoneNo
(
phoneNo
);
user
.
setCreatedAt
(
new
Timestamp
(
createdAt
));
user
.
setUpdatedAt
(
new
Timestamp
(
updatedAt
));
user
.
setEnable
(
true
);
user
.
setRegisteredFrom
(
registeredFrom
);
user
.
setUuid
(
uuid
);
user
.
setPassword
(
password
);
user
=
userService
.
saveUser
(
user
);
UserRet
userRet
=
null
;
if
(
user
!=
null
)
{
userRet
=
UserRet
.
getUserRet
(
user
);
}
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
}
/**
* 保存用户详细信息
* @param userId
* @param phoneNo
* @param name
* @param idNo
* @param email
* @return
*/
@RequestMapping
(
"/user_detail/save"
)
public
JsonResult
saveUserDetail
(
Long
userId
,
String
phoneNo
,
String
name
,
String
idNo
,
String
email
,
Long
id
){
//参数验证
if
(
userId
==
null
||
userId
==
0L
){
return
JsonResult
.
buildErrorStateResult
(
"用户id为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
phoneNo
)){
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
name
)){
return
JsonResult
.
buildErrorStateResult
(
"用户名为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
idNo
)){
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
}
UserDetail
userDetail
=
new
UserDetail
();
if
(
id
!=
null
&&
id
>
0
){
userDetail
.
setId
(
id
);
}
userDetail
.
setUserId
(
userId
);
userDetail
.
setName
(
name
);
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setIdNo
(
idNo
);
Timestamp
time
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setCreatedAt
(
time
);
userDetail
.
setUpdatedAt
(
time
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
try
{
userDetail
.
setGender
(
idCardService
.
getIdCardInfo
(
idNo
).
getGender
());
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"根据身份证获取性别出错,错误信息:"
+
e
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
userDetail
.
setEmail
(
email
);
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
){
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
/**
* 保存用户详细信息
*
* @param userId
* @param phoneNo
* @param name
* @param idNo
* @param email
* @return
*/
@RequestMapping
(
"/user_detail/save"
)
public
JsonResult
saveUserDetail
(
Long
userId
,
String
phoneNo
,
String
name
,
String
idNo
,
String
email
,
Long
id
)
{
//参数验证
if
(
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户id为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
name
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户名为空."
,
null
);
}
if
(
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
}
UserDetail
userDetail
=
new
UserDetail
();
if
(
id
!=
null
&&
id
>
0
)
{
userDetail
.
setId
(
id
);
}
userDetail
.
setUserId
(
userId
);
userDetail
.
setName
(
name
);
userDetail
.
setPhoneNo
(
phoneNo
);
userDetail
.
setIdNo
(
idNo
);
Timestamp
time
=
new
Timestamp
(
System
.
currentTimeMillis
());
userDetail
.
setCreatedAt
(
time
);
userDetail
.
setUpdatedAt
(
time
);
userDetail
.
setIdType
(
IdType
.
ID_CARD
);
try
{
userDetail
.
setGender
(
idCardService
.
getIdCardInfo
(
idNo
).
getGender
());
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"根据身份证获取性别出错,错误信息:"
+
e
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
userDetail
.
setEmail
(
email
);
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
/**
* 根据用户id查询用户的详细信息
* @param userId
* @return
*/
@RequestMapping
(
"/user_detail/search/userId"
)
public
JsonResult
findUserDetailByUserId
(
Long
userId
){
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
if
(
userDetail
!=
null
){
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
/**
* 根据用户id查询用户的详细信息
*
* @param userId
* @return
*/
@RequestMapping
(
"/user_detail/search/userId"
)
public
JsonResult
findUserDetailByUserId
(
Long
userId
)
{
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
@RequestMapping
(
"/user/search/userId"
)
public
JsonResult
findUserByUserId
(
Long
userId
){
User
user
=
userService
.
findById
(
userId
);
if
(
user
!=
null
){
return
JsonResult
.
buildSuccessResult
(
null
,
UserRet
.
getUserRet
(
user
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
@RequestMapping
(
"/user/search/userId"
)
public
JsonResult
findUserByUserId
(
Long
userId
)
{
User
user
=
userService
.
findById
(
userId
);
if
(
user
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserRet
.
getUserRet
(
user
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
@RequestMapping
(
"/user_detail/search/phone"
)
public
JsonResult
findUserDetailByPhone
(
String
phoneNo
){
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
if
(
userDetail
!=
null
){
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
@RequestMapping
(
"/user_detail/search/phone"
)
public
JsonResult
findUserDetailByPhone
(
String
phoneNo
)
{
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
@RequestMapping
(
"/user_detail/update/qq"
)
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
){
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
){
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败,qq或用户id为空"
,
null
);
}
userDetailService
.
updateUserQQ
(
userId
,
qq
);
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
@RequestMapping
(
"/user_detail/update/qq"
)
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败,qq或用户id为空"
,
null
);
}
userDetailService
.
updateUserQQ
(
userId
,
qq
);
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
@RequestMapping
(
"/contact/search/user_id"
)
public
JsonResult
findContactsByUserId
(
Long
userId
)
{
if
(
null
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
}
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
contacts
));
@RequestMapping
(
"/contact/search/user_id"
)
public
JsonResult
findContactsByUserId
(
Long
userId
)
{
if
(
null
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
}
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
contacts
));
}
@RequestMapping
(
"/contact/save/contacts"
)
public
JsonResult
save2Contact
(
Long
userId
,
@RequestParam
(
value
=
"contacts"
)
String
contactsStr
)
{
LOGGER
.
info
(
"保存用户联系人:userId:{}, contacts:"
+
contactsStr
);
if
(
StringUtils
.
isEmpty
(
contactsStr
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
List
<
Contact
>
userContact
=
contactService
.
findByUserId
(
userId
);
if
(
userContact
!=
null
&&
userContact
.
size
()
>=
2
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
userContact
));
}
List
<
Contact
>
contacts
=
JSONObject
.
parseObject
(
contactsStr
,
new
TypeReference
<
List
<
Contact
>>()
{});
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
for
(
Contact
c
:
contacts
)
{
c
.
setId
(
null
);
c
.
setUserId
(
userId
);
c
.
setCreatedAt
(
now
);
c
.
setUpdateAt
(
now
);
}
List
<
Contact
>
result
=
contactService
.
save
(
contacts
);
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
result
));
@RequestMapping
(
"/contact/save/contacts"
)
public
JsonResult
save2Contact
(
Long
userId
,
@RequestParam
(
value
=
"contacts"
)
String
contactsStr
)
{
LOGGER
.
info
(
"保存用户联系人:userId:{}, contacts:"
+
contactsStr
);
if
(
StringUtils
.
isEmpty
(
contactsStr
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
List
<
Contact
>
userContact
=
contactService
.
findByUserId
(
userId
);
if
(
userContact
!=
null
&&
userContact
.
size
()
>=
2
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
userContact
));
}
List
<
Contact
>
contacts
=
JSONObject
.
parseObject
(
contactsStr
,
new
TypeReference
<
List
<
Contact
>>()
{
});
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
for
(
Contact
c
:
contacts
)
{
c
.
setId
(
null
);
c
.
setUserId
(
userId
);
c
.
setCreatedAt
(
now
);
c
.
setUpdateAt
(
now
);
}
List
<
Contact
>
result
=
contactService
.
save
(
contacts
);
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
result
));
}
@RequestMapping
(
"/address/search/user_id"
)
public
JsonResult
findAddressByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Address
address
=
addressService
.
findByUserId
(
userId
);
if
(
address
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
null
,
AddressRet
.
address2AddressRet
(
address
));
@RequestMapping
(
"/address/search/user_id"
)
public
JsonResult
findAddressByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Address
address
=
addressService
.
findByUserId
(
userId
);
if
(
address
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
null
,
AddressRet
.
address2AddressRet
(
address
));
}
@RequestMapping
(
"/address/save"
)
public
JsonResult
saveAddress
(
Long
userId
,
Long
provinceCode
,
Long
cityCode
,
String
city
,
Long
districtCode
,
String
district
,
String
address
,
String
province
)
{
LOGGER
.
info
(
"保存地址详情:city:{},province:{}"
+
city
,
province
);
if
(
userId
==
null
||
provinceCode
==
null
||
cityCode
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Address
addressObj
=
addressService
.
findByUserId
(
userId
);
if
(
addressObj
==
null
)
{
addressObj
=
new
Address
();
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
addressObj
.
setCreatedAt
(
now
);
addressObj
.
setUpdateAt
(
now
);
}
addressObj
.
setUserId
(
userId
);
addressObj
.
setProvinceCode
(
provinceCode
);
addressObj
.
setCityCode
(
cityCode
);
addressObj
.
setCity
(
city
);
addressObj
.
setDistrictCode
(
districtCode
);
addressObj
.
setDistrict
(
district
);
addressObj
.
setAddress
(
address
);
addressObj
.
setProvince
(
province
);
addressObj
=
addressService
.
save
(
addressObj
);
return
JsonResult
.
buildSuccessResult
(
null
,
AddressRet
.
address2AddressRet
(
addressObj
));
@RequestMapping
(
"/address/save"
)
public
JsonResult
saveAddress
(
Long
userId
,
Long
provinceCode
,
Long
cityCode
,
String
city
,
Long
districtCode
,
String
district
,
String
address
,
String
province
)
{
LOGGER
.
info
(
"保存地址详情:city:{},province:{}"
+
city
,
province
);
if
(
userId
==
null
||
provinceCode
==
null
||
cityCode
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
Address
addressObj
=
addressService
.
findByUserId
(
userId
);
if
(
addressObj
==
null
)
{
addressObj
=
new
Address
();
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
addressObj
.
setCreatedAt
(
now
);
addressObj
.
setUpdateAt
(
now
);
}
addressObj
.
setUserId
(
userId
);
addressObj
.
setProvinceCode
(
provinceCode
);
addressObj
.
setCityCode
(
cityCode
);
addressObj
.
setCity
(
city
);
addressObj
.
setDistrictCode
(
districtCode
);
addressObj
.
setDistrict
(
district
);
addressObj
.
setAddress
(
address
);
addressObj
.
setProvince
(
province
);
addressObj
=
addressService
.
save
(
addressObj
);
return
JsonResult
.
buildSuccessResult
(
null
,
AddressRet
.
address2AddressRet
(
addressObj
));
}
@RequestMapping
(
"/user_ext_info/update"
)
public
JsonResult
updateMarryStatus
(
Long
userId
,
IncomeEnum
incomeEnum
,
IncomeRangeEnum
incomeRangeEnum
,
OccupationEnum
occupationEnum
,
EducationEnum
educationEnum
,
Boolean
hasCar
,
Boolean
hasSocialSecurity
,
Boolean
hasHouse
,
Boolean
hasCreditCard
,
MaritalStatus
maritalStatus
)
{
if
(
null
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户ID不能为空"
,
null
);
}
UserExtInfo
info
=
userExtInfoService
.
findByUserId
(
userId
);
if
(
info
==
null
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
info
=
new
UserExtInfo
();
info
.
setUserId
(
userId
);
info
.
setCreatedAt
(
now
);
info
.
setUpdateAt
(
now
);
}
if
(
incomeEnum
!=
null
)
{
info
.
setIncomeEnum
(
incomeEnum
);
}
if
(
incomeRangeEnum
!=
null
)
{
info
.
setIncomeRangeEnum
(
incomeRangeEnum
);
}
if
(
occupationEnum
!=
null
)
{
info
.
setOccupationEnum
(
occupationEnum
);
}
if
(
educationEnum
!=
null
)
{
info
.
setEducationEnum
(
educationEnum
);
}
if
(
hasCar
!=
null
)
{
info
.
setHasCar
(
hasCar
);
}
if
(
hasSocialSecurity
!=
null
)
{
info
.
setHasCreditCard
(
hasCreditCard
);
}
if
(
hasHouse
!=
null
)
{
info
.
setHasHouse
(
hasHouse
);
}
if
(
maritalStatus
!=
null
)
{
info
.
setMarryStatus
(
maritalStatus
);
}
info
=
userExtInfoService
.
save
(
info
);
return
JsonResult
.
buildSuccessResult
(
null
,
UserExtInfoRet
.
getUserExtInfoRet
(
info
));
@RequestMapping
(
"/user_ext_info/update"
)
public
JsonResult
updateMarryStatus
(
Long
userId
,
IncomeEnum
incomeEnum
,
IncomeRangeEnum
incomeRangeEnum
,
OccupationEnum
occupationEnum
,
EducationEnum
educationEnum
,
Boolean
hasCar
,
Boolean
hasSocialSecurity
,
Boolean
hasHouse
,
Boolean
hasCreditCard
,
MaritalStatus
maritalStatus
)
{
if
(
null
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户ID不能为空"
,
null
);
}
@RequestMapping
(
"/user_detail/search_list"
)
public
JsonResult
searchUserDetailList
(
String
name
,
String
phoneNo
,
String
idNo
)
{
List
<
UserDetail
>
userDetails
=
userDetailService
.
searchUserDetailList
(
name
,
phoneNo
,
idNo
);
return
JsonResult
.
buildSuccessResult
(
"success"
,
userDetails
);
UserExtInfo
info
=
userExtInfoService
.
findByUserId
(
userId
);
if
(
info
==
null
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
info
=
new
UserExtInfo
();
info
.
setUserId
(
userId
);
info
.
setCreatedAt
(
now
);
info
.
setUpdateAt
(
now
);
}
if
(
incomeEnum
!=
null
)
{
info
.
setIncomeEnum
(
incomeEnum
);
}
if
(
incomeRangeEnum
!=
null
)
{
info
.
setIncomeRangeEnum
(
incomeRangeEnum
);
}
if
(
occupationEnum
!=
null
)
{
info
.
setOccupationEnum
(
occupationEnum
);
}
if
(
educationEnum
!=
null
)
{
info
.
setEducationEnum
(
educationEnum
);
}
if
(
hasCar
!=
null
)
{
info
.
setHasCar
(
hasCar
);
}
if
(
hasSocialSecurity
!=
null
)
{
info
.
setHasCreditCard
(
hasCreditCard
);
}
if
(
hasHouse
!=
null
)
{
info
.
setHasHouse
(
hasHouse
);
}
if
(
maritalStatus
!=
null
)
{
info
.
setMarryStatus
(
maritalStatus
);
}
info
=
userExtInfoService
.
save
(
info
);
return
JsonResult
.
buildSuccessResult
(
null
,
UserExtInfoRet
.
getUserExtInfoRet
(
info
));
}
@RequestMapping
(
"/user_detail/search_list"
)
public
JsonResult
searchUserDetailList
(
String
name
,
String
phoneNo
,
String
idNo
)
{
List
<
UserDetail
>
userDetails
=
userDetailService
.
searchUserDetailList
(
name
,
phoneNo
,
idNo
);
return
JsonResult
.
buildSuccessResult
(
"success"
,
userDetails
);
}
@RequestMapping
(
"/user_ext_info/search/user_id"
)
public
JsonResult
searchUserExtInfoByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
UserExtInfo
userExtInfo
=
userExtInfoService
.
findByUserId
(
userId
);
if
(
userExtInfo
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
UserExtInfoRet
.
getUserExtInfoRet
(
userExtInfo
));
@RequestMapping
(
"/user_ext_info/search/user_id"
)
public
JsonResult
searchUserExtInfoByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
UserExtInfo
userExtInfo
=
userExtInfoService
.
findByUserId
(
userId
);
if
(
userExtInfo
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
UserExtInfoRet
.
getUserExtInfoRet
(
userExtInfo
));
}
@RequestMapping
(
"/user/query/openId"
)
public
JsonResult
queryOpenIdByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
if
(
wechatUserInfo
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
wechatUserInfo
.
getOpenId
());
@RequestMapping
(
"/user/query/openId"
)
public
JsonResult
queryOpenIdByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
if
(
wechatUserInfo
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
wechatUserInfo
.
getOpenId
());
}
@RequestMapping
(
"/user/disable"
)
public
JsonResult
disableUser
(
Long
userId
)
{
if
(
null
==
userId
||
0L
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
User
user
=
userService
.
findById
(
userId
);
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
"未查询到该用户,用户id:"
+
userId
,
null
);
}
user
.
setEnable
(
false
);
user
=
userService
.
saveUser
(
user
);
return
JsonResult
.
buildSuccessResult
(
"用户已禁用."
,
user
.
getEnable
()
==
false
);
@RequestMapping
(
"/user/disable"
)
public
JsonResult
disableUser
(
Long
userId
)
{
if
(
null
==
userId
||
0L
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
User
user
=
userService
.
findById
(
userId
);
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
"未查询到该用户,用户id:"
+
userId
,
null
);
}
user
.
setEnable
(
false
);
user
=
userService
.
saveUser
(
user
);
if
(!
user
.
getEnable
())
{
sessionService
.
deleteByUserId
(
userId
);
}
return
JsonResult
.
buildSuccessResult
(
"用户已禁用."
,
user
.
getEnable
()
==
false
);
}
}
\ No newline at end of file
src/main/java/cn/quantgroup/xyqb/service/session/ISessionService.java
View file @
45f5f605
...
...
@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.service.session;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.function.OneArgFunction
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
...
...
@@ -14,15 +13,19 @@ import cn.quantgroup.xyqb.model.session.SessionValue;
public
interface
ISessionService
{
AuthBean
createSession
(
Long
channelId
,
Long
createdFrom
,
String
appChannel
,
User
user
,
Merchant
merchant
);
AuthBean
createSession
(
Long
channelId
,
Long
createdFrom
,
String
appChannel
,
User
user
,
Merchant
merchant
);
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
loginProperties
);
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
loginProperties
);
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
);
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
);
String
findSessionValueBySessionId
(
String
sessionId
);
SessionStruct
newSession
(
User
user
,
LoginProperties
properties
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
String
findSessionValueBySessionId
(
String
sessionId
);
SessionStruct
findSessionBySessionId
(
String
sessionId
);
SessionStruct
newSession
(
User
user
,
LoginProperties
properties
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
SessionStruct
findSessionBySessionId
(
String
sessionId
);
void
deleteByUserId
(
long
userId
);
}
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
45f5f605
...
...
@@ -3,9 +3,7 @@ package cn.quantgroup.xyqb.service.session.impl;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.function.OneArgFunction
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionValue
;
...
...
@@ -21,136 +19,141 @@ import org.springframework.stereotype.Service;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
/**
*
* Created by 11 on 2016/12/28.
*/
@Slf4j
@Service
public
class
SessionServiceImpl
implements
ISessionService
{
public
class
SessionServiceImpl
implements
ISessionService
{
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
stringRedisTemplate
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
stringRedisTemplate
;
@Override
public
AuthBean
createSession
(
Long
channelId
,
Long
createdFrom
,
String
appChannel
,
User
user
,
Merchant
merchant
)
{
AuthBean
authBean
=
new
AuthBean
();
LoginProperties
properties
=
new
LoginProperties
();
properties
.
setAppChannel
(
appChannel
);
properties
.
setMerchantName
(
merchant
.
getName
());
properties
.
setChannelId
(
channelId
);
properties
.
setCreatedFrom
(
createdFrom
);
//找到用户
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
// String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isNotEmpty
(
sessionId
))
{
SessionStruct
sessionStruct
=
findSessionBySessionId
(
sessionId
);
sessionStruct
.
setAttribute
(
"channelId"
,
String
.
valueOf
(
channelId
));
sessionStruct
.
setAttribute
(
"createdFrom"
,
String
.
valueOf
(
createdFrom
));
sessionStruct
.
setAttribute
(
"appChannel"
,
String
.
valueOf
(
appChannel
));
authBean
.
setPhoneNo
(
user
.
getPhoneNo
());
authBean
.
setToken
(
sessionStruct
.
getSid
());
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
log
.
info
(
"用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
createdFrom
,
user
.
getPhoneNo
(),
appChannel
);
return
authBean
;
}
SessionStruct
sessionStruct
=
createSessionAndPersist
(
user
,
properties
);
authBean
.
setPhoneNo
(
user
.
getPhoneNo
());
authBean
.
setToken
(
sessionStruct
.
getSid
());
log
.
info
(
"用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
createdFrom
,
user
.
getPhoneNo
(),
appChannel
);
return
authBean
;
@Override
public
AuthBean
createSession
(
Long
channelId
,
Long
createdFrom
,
String
appChannel
,
User
user
,
Merchant
merchant
)
{
AuthBean
authBean
=
new
AuthBean
();
LoginProperties
properties
=
new
LoginProperties
();
properties
.
setAppChannel
(
appChannel
);
properties
.
setMerchantName
(
merchant
.
getName
());
properties
.
setChannelId
(
channelId
);
properties
.
setCreatedFrom
(
createdFrom
);
//找到用户
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
// String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isNotEmpty
(
sessionId
))
{
SessionStruct
sessionStruct
=
findSessionBySessionId
(
sessionId
);
sessionStruct
.
setAttribute
(
"channelId"
,
String
.
valueOf
(
channelId
));
sessionStruct
.
setAttribute
(
"createdFrom"
,
String
.
valueOf
(
createdFrom
));
sessionStruct
.
setAttribute
(
"appChannel"
,
String
.
valueOf
(
appChannel
));
authBean
.
setPhoneNo
(
user
.
getPhoneNo
());
authBean
.
setToken
(
sessionStruct
.
getSid
());
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
log
.
info
(
"用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
createdFrom
,
user
.
getPhoneNo
(),
appChannel
);
return
authBean
;
}
SessionStruct
sessionStruct
=
createSessionAndPersist
(
user
,
properties
);
authBean
.
setPhoneNo
(
user
.
getPhoneNo
());
authBean
.
setToken
(
sessionStruct
.
getSid
());
log
.
info
(
"用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}"
,
createdFrom
,
user
.
getPhoneNo
(),
appChannel
);
return
authBean
;
}
@Override
public
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
properties
)
{
SessionStruct
sessionStruct
;
//获取sessionid
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
if
(
StringUtils
.
length
(
sessionId
)
==
36
)
{
sessionStruct
=
findSessionBySessionId
(
sessionId
);
if
(
sessionStruct
==
null
)
{
sessionStruct
=
newSession
(
user
,
properties
);
}
else
{
sessionStruct
.
getValues
().
setLoginProperties
(
properties
);
}
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
}
else
{
sessionStruct
=
newSession
(
user
,
properties
);
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
}
return
sessionStruct
;
@Override
public
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
properties
)
{
SessionStruct
sessionStruct
;
//获取sessionid
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
if
(
StringUtils
.
length
(
sessionId
)
==
36
)
{
sessionStruct
=
findSessionBySessionId
(
sessionId
);
if
(
sessionStruct
==
null
)
{
sessionStruct
=
newSession
(
user
,
properties
);
}
else
{
sessionStruct
.
getValues
().
setLoginProperties
(
properties
);
}
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
}
else
{
sessionStruct
=
newSession
(
user
,
properties
);
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
}
return
sessionStruct
;
}
@Override
public
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
)
{
return
stringRedisTemplate
.
opsForValue
().
get
(
generateLoginPropertiesKey
(
userId
,
properties
));
}
private
String
generateLoginPropertiesKey
(
Long
userId
,
LoginProperties
properties
)
{
if
(
"baitiao"
.
equals
(
properties
.
getMerchantName
()))
{
return
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":"
+
properties
.
getMerchantName
()
+
":"
+
properties
.
getCreatedFrom
();
}
else
{
return
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":"
+
properties
.
getMerchantName
();
}
}
@Override
public
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
)
{
return
stringRedisTemplate
.
opsForValue
().
get
(
generateLoginPropertiesKey
(
userId
,
properties
));
}
@Override
public
String
findSessionValueBySessionId
(
String
sessionId
){
String
result
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_CACHE
+
sessionId
);
return
StringUtils
.
defaultString
(
result
,
""
);
private
String
generateLoginPropertiesKey
(
Long
userId
,
LoginProperties
properties
)
{
if
(
"baitiao"
.
equals
(
properties
.
getMerchantName
()))
{
return
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":"
+
properties
.
getMerchantName
()
+
":"
+
properties
.
getCreatedFrom
();
}
else
{
return
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":"
+
properties
.
getMerchantName
();
}
}
@Override
public
SessionStruct
newSession
(
User
user
,
LoginProperties
loginProperties
){
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
SessionStruct
sessionStruct
=
new
SessionStruct
();
SessionValue
sessionValue
=
new
SessionValue
();
sessionStruct
.
setSid
(
UUID
.
randomUUID
().
toString
());
sessionValue
.
setCreatedAt
(
now
);
sessionValue
.
setLastAccessTime
(
now
);
sessionValue
.
setUser
(
user
);
sessionValue
.
setLoginProperties
(
loginProperties
);
Map
<
String
,
String
>
values
=
new
HashMap
<>();
sessionValue
.
setValues
(
values
);
sessionStruct
.
setValues
(
sessionValue
);
return
sessionStruct
;
}
@Override
public
String
findSessionValueBySessionId
(
String
sessionId
)
{
String
result
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_CACHE
+
sessionId
);
return
StringUtils
.
defaultString
(
result
,
""
);
}
@Override
public
void
persistSession
(
String
token
,
SessionValue
sessionValue
)
{
Timestamp
current
=
new
Timestamp
(
System
.
currentTimeMillis
());
sessionValue
.
setLastAccessTime
(
current
);
String
json
=
JSON
.
toJSONString
(
sessionValue
);
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
Session
.
USER_SESSION_CACHE
+
token
,
json
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
}
@Override
public
SessionStruct
newSession
(
User
user
,
LoginProperties
loginProperties
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
SessionStruct
sessionStruct
=
new
SessionStruct
();
SessionValue
sessionValue
=
new
SessionValue
();
sessionStruct
.
setSid
(
UUID
.
randomUUID
().
toString
());
sessionValue
.
setCreatedAt
(
now
);
sessionValue
.
setLastAccessTime
(
now
);
sessionValue
.
setUser
(
user
);
sessionValue
.
setLoginProperties
(
loginProperties
);
Map
<
String
,
String
>
values
=
new
HashMap
<>();
sessionValue
.
setValues
(
values
);
sessionStruct
.
setValues
(
sessionValue
);
return
sessionStruct
;
}
@Override
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
if
(
StringUtils
.
isEmpty
(
sessionValue
))
{
return
null
;
}
try
{
SessionValue
value
=
JSON
.
parseObject
(
sessionValue
,
SessionValue
.
class
);
if
(
null
==
value
)
{
return
null
;
}
SessionStruct
struct
=
new
SessionStruct
();
struct
.
setSid
(
sessionId
);
struct
.
setValues
(
value
);
return
struct
;
}
catch
(
Exception
ex
)
{
return
null
;
}
@Override
public
void
persistSession
(
String
token
,
SessionValue
sessionValue
)
{
Timestamp
current
=
new
Timestamp
(
System
.
currentTimeMillis
());
sessionValue
.
setLastAccessTime
(
current
);
String
json
=
JSON
.
toJSONString
(
sessionValue
);
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
Session
.
USER_SESSION_CACHE
+
token
,
json
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
}
@Override
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
if
(
StringUtils
.
isEmpty
(
sessionValue
))
{
return
null
;
}
try
{
SessionValue
value
=
JSON
.
parseObject
(
sessionValue
,
SessionValue
.
class
);
if
(
null
==
value
)
{
return
null
;
}
SessionStruct
struct
=
new
SessionStruct
();
struct
.
setSid
(
sessionId
);
struct
.
setValues
(
value
);
return
struct
;
}
catch
(
Exception
ex
)
{
return
null
;
}
}
@Override
public
void
deleteByUserId
(
long
userId
)
{
String
pattern
=
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":*"
;
Set
<
String
>
keys
=
stringRedisTemplate
.
keys
(
pattern
);
stringRedisTemplate
.
delete
(
keys
);
}
}
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