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
d3956a85
Commit
d3956a85
authored
Apr 24, 2017
by
minminyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
禁用用户的同时删除相应的缓存
parent
8aa4d2be
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
975 additions
and
947 deletions
+975
-947
InnerController.java
...tgroup/xyqb/controller/external/user/InnerController.java
+312
-302
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+416
-413
ISessionService.java
...a/cn/quantgroup/xyqb/service/session/ISessionService.java
+11
-8
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+121
-111
UserServiceImpl.java
...cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
+115
-113
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/InnerController.java
View file @
d3956a85
...
@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.*;
...
@@ -4,6 +4,7 @@ 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.*
;
import
cn.quantgroup.xyqb.service.auth.IIdCardService
;
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.user.*
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
cn.quantgroup.xyqb.service.wechat.IWechatService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
...
@@ -44,7 +45,8 @@ public class InnerController {
...
@@ -44,7 +45,8 @@ public class InnerController {
private
IAddressService
addressService
;
private
IAddressService
addressService
;
@Autowired
@Autowired
private
IWechatService
wechatService
;
private
IWechatService
wechatService
;
@Autowired
private
ISessionService
sessionService
;
@RequestMapping
(
"/user/search/phoneNo"
)
@RequestMapping
(
"/user/search/phoneNo"
)
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
public
JsonResult
findByPhoneNo
(
String
phoneNo
)
{
...
@@ -71,19 +73,19 @@ public class InnerController {
...
@@ -71,19 +73,19 @@ public class InnerController {
String
phoneNo
,
Long
registeredFrom
,
Long
createdAt
,
Long
updatedAt
,
String
phoneNo
,
Long
registeredFrom
,
Long
createdAt
,
Long
updatedAt
,
String
password
,
String
uuid
)
{
String
password
,
String
uuid
)
{
//参数验证
//参数验证
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户手机号不能为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户手机号不能为空."
,
null
);
}
}
if
(
registeredFrom
==
null
)
{
if
(
registeredFrom
==
null
)
{
registeredFrom
=
0L
;
registeredFrom
=
0L
;
}
}
if
(
StringUtils
.
isBlank
(
password
))
{
if
(
StringUtils
.
isBlank
(
password
))
{
password
=
""
;
password
=
""
;
}
}
if
(
StringUtils
.
isBlank
(
uuid
))
{
if
(
StringUtils
.
isBlank
(
uuid
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户uuid为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户uuid为空."
,
null
);
}
}
if
(
createdAt
==
0L
||
updatedAt
==
0L
)
{
if
(
createdAt
==
0L
||
updatedAt
==
0L
)
{
createdAt
=
System
.
currentTimeMillis
();
createdAt
=
System
.
currentTimeMillis
();
updatedAt
=
System
.
currentTimeMillis
();
updatedAt
=
System
.
currentTimeMillis
();
}
}
...
@@ -100,7 +102,7 @@ public class InnerController {
...
@@ -100,7 +102,7 @@ public class InnerController {
user
.
setPassword
(
password
);
user
.
setPassword
(
password
);
user
=
userService
.
saveUser
(
user
);
user
=
userService
.
saveUser
(
user
);
UserRet
userRet
=
null
;
UserRet
userRet
=
null
;
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
userRet
=
UserRet
.
getUserRet
(
user
);
userRet
=
UserRet
.
getUserRet
(
user
);
}
}
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
return
JsonResult
.
buildSuccessResult
(
null
,
userRet
);
...
@@ -108,6 +110,7 @@ public class InnerController {
...
@@ -108,6 +110,7 @@ public class InnerController {
/**
/**
* 保存用户详细信息
* 保存用户详细信息
*
* @param userId
* @param userId
* @param phoneNo
* @param phoneNo
* @param name
* @param name
...
@@ -117,22 +120,22 @@ public class InnerController {
...
@@ -117,22 +120,22 @@ public class InnerController {
*/
*/
@RequestMapping
(
"/user_detail/save"
)
@RequestMapping
(
"/user_detail/save"
)
public
JsonResult
saveUserDetail
(
Long
userId
,
String
phoneNo
,
String
name
,
String
idNo
,
public
JsonResult
saveUserDetail
(
Long
userId
,
String
phoneNo
,
String
name
,
String
idNo
,
String
email
,
Long
id
)
{
String
email
,
Long
id
)
{
//参数验证
//参数验证
if
(
userId
==
null
||
userId
==
0L
)
{
if
(
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户id为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户id为空."
,
null
);
}
}
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
if
(
StringUtils
.
isBlank
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户手机号为空."
,
null
);
}
}
if
(
StringUtils
.
isBlank
(
name
))
{
if
(
StringUtils
.
isBlank
(
name
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户名为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户名为空."
,
null
);
}
}
if
(
StringUtils
.
isBlank
(
idNo
))
{
if
(
StringUtils
.
isBlank
(
idNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"用户身份证为空."
,
null
);
}
}
UserDetail
userDetail
=
new
UserDetail
();
UserDetail
userDetail
=
new
UserDetail
();
if
(
id
!=
null
&&
id
>
0
)
{
if
(
id
!=
null
&&
id
>
0
)
{
userDetail
.
setId
(
id
);
userDetail
.
setId
(
id
);
}
}
userDetail
.
setUserId
(
userId
);
userDetail
.
setUserId
(
userId
);
...
@@ -151,47 +154,48 @@ public class InnerController {
...
@@ -151,47 +154,48 @@ public class InnerController {
}
}
userDetail
.
setEmail
(
email
);
userDetail
.
setEmail
(
email
);
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
userDetail
=
userDetailService
.
saveUserDetail
(
userDetail
);
if
(
userDetail
!=
null
)
{
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
}
/**
/**
* 根据用户id查询用户的详细信息
* 根据用户id查询用户的详细信息
*
* @param userId
* @param userId
* @return
* @return
*/
*/
@RequestMapping
(
"/user_detail/search/userId"
)
@RequestMapping
(
"/user_detail/search/userId"
)
public
JsonResult
findUserDetailByUserId
(
Long
userId
)
{
public
JsonResult
findUserDetailByUserId
(
Long
userId
)
{
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
UserDetail
userDetail
=
userDetailService
.
findByUserId
(
userId
);
if
(
userDetail
!=
null
)
{
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
}
@RequestMapping
(
"/user/search/userId"
)
@RequestMapping
(
"/user/search/userId"
)
public
JsonResult
findUserByUserId
(
Long
userId
)
{
public
JsonResult
findUserByUserId
(
Long
userId
)
{
User
user
=
userService
.
findById
(
userId
);
User
user
=
userService
.
findById
(
userId
);
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserRet
.
getUserRet
(
user
));
return
JsonResult
.
buildSuccessResult
(
null
,
UserRet
.
getUserRet
(
user
));
}
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
}
@RequestMapping
(
"/user_detail/search/phone"
)
@RequestMapping
(
"/user_detail/search/phone"
)
public
JsonResult
findUserDetailByPhone
(
String
phoneNo
)
{
public
JsonResult
findUserDetailByPhone
(
String
phoneNo
)
{
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
UserDetail
userDetail
=
userDetailService
.
findByPhoneNo
(
phoneNo
);
if
(
userDetail
!=
null
)
{
if
(
userDetail
!=
null
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
return
JsonResult
.
buildSuccessResult
(
null
,
UserDetailRet
.
getUserDetail
(
userDetail
));
}
}
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
return
JsonResult
.
buildErrorStateResult
(
""
,
null
);
}
}
@RequestMapping
(
"/user_detail/update/qq"
)
@RequestMapping
(
"/user_detail/update/qq"
)
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
)
{
public
JsonResult
updateUserQQ
(
String
qq
,
Long
userId
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
)
{
if
(
StringUtils
.
isEmpty
(
qq
)
||
userId
==
null
||
userId
==
0L
)
{
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败,qq或用户id为空"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败,qq或用户id为空"
,
null
);
}
}
userDetailService
.
updateUserQQ
(
userId
,
qq
);
userDetailService
.
updateUserQQ
(
userId
,
qq
);
...
@@ -204,7 +208,7 @@ public class InnerController {
...
@@ -204,7 +208,7 @@ public class InnerController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
List
<
Contact
>
contacts
=
contactService
.
findByUserId
(
userId
);
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
if
(
null
==
contacts
||
contacts
.
size
()
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
return
JsonResult
.
buildErrorStateResult
(
null
,
Collections
.
emptyList
());
}
}
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
contacts
));
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
contacts
));
...
@@ -220,10 +224,11 @@ public class InnerController {
...
@@ -220,10 +224,11 @@ public class InnerController {
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
List
<
Contact
>
userContact
=
contactService
.
findByUserId
(
userId
);
List
<
Contact
>
userContact
=
contactService
.
findByUserId
(
userId
);
if
(
userContact
!=
null
&&
userContact
.
size
()
>=
2
)
{
if
(
userContact
!=
null
&&
userContact
.
size
()
>=
2
)
{
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
userContact
));
return
JsonResult
.
buildSuccessResult
(
null
,
ContactRet
.
contacts2ContactRets
(
userContact
));
}
}
List
<
Contact
>
contacts
=
JSONObject
.
parseObject
(
contactsStr
,
new
TypeReference
<
List
<
Contact
>>()
{});
List
<
Contact
>
contacts
=
JSONObject
.
parseObject
(
contactsStr
,
new
TypeReference
<
List
<
Contact
>>()
{
});
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
if
(
CollectionUtils
.
isEmpty
(
contacts
))
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
...
@@ -342,11 +347,11 @@ public class InnerController {
...
@@ -342,11 +347,11 @@ public class InnerController {
@RequestMapping
(
"/user/query/openId"
)
@RequestMapping
(
"/user/query/openId"
)
public
JsonResult
queryOpenIdByUserId
(
Long
userId
)
{
public
JsonResult
queryOpenIdByUserId
(
Long
userId
)
{
if
(
userId
==
null
)
{
if
(
userId
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
}
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
WechatUserInfo
wechatUserInfo
=
wechatService
.
queryOpenIdByUserId
(
userId
);
if
(
wechatUserInfo
==
null
)
{
if
(
wechatUserInfo
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
return
JsonResult
.
buildErrorStateResult
(
null
,
null
);
}
}
return
JsonResult
.
buildSuccessResult
(
"success"
,
wechatUserInfo
.
getOpenId
());
return
JsonResult
.
buildSuccessResult
(
"success"
,
wechatUserInfo
.
getOpenId
());
...
@@ -354,15 +359,20 @@ public class InnerController {
...
@@ -354,15 +359,20 @@ public class InnerController {
@RequestMapping
(
"/user/disable"
)
@RequestMapping
(
"/user/disable"
)
public
JsonResult
disableUser
(
Long
userId
)
{
public
JsonResult
disableUser
(
Long
userId
)
{
if
(
null
==
userId
||
0L
==
userId
)
{
if
(
null
==
userId
||
0L
==
userId
)
{
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"userId不能为空"
,
null
);
}
}
User
user
=
userService
.
findById
(
userId
);
User
user
=
userService
.
findById
(
userId
);
if
(
null
==
user
)
{
if
(
null
==
user
)
{
return
JsonResult
.
buildErrorStateResult
(
"未查询到该用户,用户id:"
+
userId
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"未查询到该用户,用户id:"
+
userId
,
null
);
}
}
user
.
setEnable
(
false
);
user
.
setEnable
(
false
);
user
.
setUpdatedAt
(
new
Timestamp
(
System
.
currentTimeMillis
()));
LOGGER
.
info
(
"注销用户的信息,userId={}"
,
userId
);
user
=
userService
.
saveUser
(
user
);
user
=
userService
.
saveUser
(
user
);
if
(!
user
.
getEnable
())
{
sessionService
.
deleteByUserId
(
userId
);
}
return
JsonResult
.
buildSuccessResult
(
"用户已禁用."
,
user
.
getEnable
()
==
false
);
return
JsonResult
.
buildSuccessResult
(
"用户已禁用."
,
user
.
getEnable
()
==
false
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
d3956a85
...
@@ -106,6 +106,9 @@ public class UserController implements IBaseController {
...
@@ -106,6 +106,9 @@ public class UserController implements IBaseController {
JsonResult
successResult
=
validMap
.
get
(
"success"
);
JsonResult
successResult
=
validMap
.
get
(
"success"
);
String
phoneNo
=
successResult
.
getData
().
toString
();
String
phoneNo
=
successResult
.
getData
().
toString
();
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
user
!=
null
&&
!
user
.
getEnable
())
{
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
if
(
user
==
null
)
{
if
(
user
==
null
)
{
user
=
registerFastWhenLogin
(
phoneNo
,
channelId
,
createdFrom
,
appChannel
);
user
=
registerFastWhenLogin
(
phoneNo
,
channelId
,
createdFrom
,
appChannel
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
...
@@ -403,7 +406,7 @@ public class UserController implements IBaseController {
...
@@ -403,7 +406,7 @@ public class UserController implements IBaseController {
String
userName
=
credentialArr
[
0
];
String
userName
=
credentialArr
[
0
];
String
pass
=
credentialArr
[
1
];
String
pass
=
credentialArr
[
1
];
User
user
=
userService
.
findByPhoneWithCache
(
userName
);
User
user
=
userService
.
findByPhoneWithCache
(
userName
);
if
(
user
==
null
)
{
if
(
user
==
null
||
!
user
.
getEnable
()
)
{
return
null
;
return
null
;
}
}
//验证密码
//验证密码
...
@@ -421,7 +424,7 @@ public class UserController implements IBaseController {
...
@@ -421,7 +424,7 @@ public class UserController implements IBaseController {
//查询用户,存在则保存用户session信息,userId为uuid
//查询用户,存在则保存用户session信息,userId为uuid
User
user
=
userService
.
findByUuidInDb
(
userId
);
User
user
=
userService
.
findByUuidInDb
(
userId
);
//用户信息存在,更新session中的最后访问时间,重新写入缓存.
//用户信息存在,更新session中的最后访问时间,重新写入缓存.
if
(
null
!=
user
)
{
if
(
null
!=
user
||
!
user
.
getEnable
()
)
{
return
new
JsonResult
(
sessionService
.
createSession
(
channelId
,
createdFrom
,
appChannel
,
user
,
merchant
));
return
new
JsonResult
(
sessionService
.
createSession
(
channelId
,
createdFrom
,
appChannel
,
user
,
merchant
));
}
else
{
}
else
{
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
...
...
src/main/java/cn/quantgroup/xyqb/service/session/ISessionService.java
View file @
d3956a85
...
@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.service.session;
...
@@ -2,7 +2,6 @@ package cn.quantgroup.xyqb.service.session;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.function.OneArgFunction
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
...
@@ -21,8 +20,12 @@ public interface ISessionService {
...
@@ -21,8 +20,12 @@ public interface ISessionService {
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
);
String
findSessionIdByUserIdLoginProperties
(
Long
userId
,
LoginProperties
properties
);
String
findSessionValueBySessionId
(
String
sessionId
);
String
findSessionValueBySessionId
(
String
sessionId
);
SessionStruct
newSession
(
User
user
,
LoginProperties
properties
);
SessionStruct
newSession
(
User
user
,
LoginProperties
properties
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
SessionStruct
findSessionBySessionId
(
String
sessionId
);
SessionStruct
findSessionBySessionId
(
String
sessionId
);
void
deleteByUserId
(
long
userId
);
}
}
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
d3956a85
...
@@ -3,34 +3,34 @@ package cn.quantgroup.xyqb.service.session.impl;
...
@@ -3,34 +3,34 @@ package cn.quantgroup.xyqb.service.session.impl;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.Merchant
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.entity.User
;
import
cn.quantgroup.xyqb.function.OneArgFunction
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.AuthBean
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.LoginProperties
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionValue
;
import
cn.quantgroup.xyqb.model.session.SessionValue
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.base.Joiner
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
*
* Created by 11 on 2016/12/28.
* Created by 11 on 2016/12/28.
*/
*/
@Slf4j
@Slf4j
@Service
@Service
public
class
SessionServiceImpl
implements
ISessionService
{
public
class
SessionServiceImpl
implements
ISessionService
{
@Autowired
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
@Qualifier
(
"stringRedisTemplate"
)
...
@@ -47,7 +47,7 @@ public class SessionServiceImpl implements ISessionService{
...
@@ -47,7 +47,7 @@ public class SessionServiceImpl implements ISessionService{
//找到用户
//找到用户
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
String
sessionId
=
findSessionIdByUserIdLoginProperties
(
user
.
getId
(),
properties
);
// String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
// String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isNotEmpty
(
sessionId
))
{
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isNotEmpty
(
sessionId
))
{
SessionStruct
sessionStruct
=
findSessionBySessionId
(
sessionId
);
SessionStruct
sessionStruct
=
findSessionBySessionId
(
sessionId
);
sessionStruct
.
setAttribute
(
"channelId"
,
String
.
valueOf
(
channelId
));
sessionStruct
.
setAttribute
(
"channelId"
,
String
.
valueOf
(
channelId
));
sessionStruct
.
setAttribute
(
"createdFrom"
,
String
.
valueOf
(
createdFrom
));
sessionStruct
.
setAttribute
(
"createdFrom"
,
String
.
valueOf
(
createdFrom
));
...
@@ -99,13 +99,13 @@ public class SessionServiceImpl implements ISessionService{
...
@@ -99,13 +99,13 @@ public class SessionServiceImpl implements ISessionService{
}
}
@Override
@Override
public
String
findSessionValueBySessionId
(
String
sessionId
)
{
public
String
findSessionValueBySessionId
(
String
sessionId
)
{
String
result
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_CACHE
+
sessionId
);
String
result
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_CACHE
+
sessionId
);
return
StringUtils
.
defaultString
(
result
,
""
);
return
StringUtils
.
defaultString
(
result
,
""
);
}
}
@Override
@Override
public
SessionStruct
newSession
(
User
user
,
LoginProperties
loginProperties
)
{
public
SessionStruct
newSession
(
User
user
,
LoginProperties
loginProperties
)
{
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
SessionStruct
sessionStruct
=
new
SessionStruct
();
SessionStruct
sessionStruct
=
new
SessionStruct
();
SessionValue
sessionValue
=
new
SessionValue
();
SessionValue
sessionValue
=
new
SessionValue
();
...
@@ -134,7 +134,7 @@ public class SessionServiceImpl implements ISessionService{
...
@@ -134,7 +134,7 @@ public class SessionServiceImpl implements ISessionService{
@Override
@Override
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
if
(
StringUtils
.
isEmpty
(
sessionValue
))
{
if
(
StringUtils
.
isEmpty
(
sessionValue
))
{
return
null
;
return
null
;
}
}
try
{
try
{
...
@@ -152,5 +152,15 @@ public class SessionServiceImpl implements ISessionService{
...
@@ -152,5 +152,15 @@ public class SessionServiceImpl implements ISessionService{
}
}
@Override
public
void
deleteByUserId
(
long
userId
)
{
String
pattern
=
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":*"
;
Set
<
String
>
keys
=
stringRedisTemplate
.
keys
(
pattern
);
if
(!
CollectionUtils
.
isEmpty
(
keys
))
{
log
.
info
(
"删除用户userId={}的缓存信息,个数:{},keys={}"
,
userId
,
keys
.
size
(),
Joiner
.
on
(
","
).
join
(
keys
));
}
stringRedisTemplate
.
delete
(
keys
);
}
}
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/UserServiceImpl.java
View file @
d3956a85
...
@@ -47,6 +47,7 @@ public class UserServiceImpl implements IUserService {
...
@@ -47,6 +47,7 @@ public class UserServiceImpl implements IUserService {
}
}
@Override
@Override
@CacheEvict
(
value
=
"usercache"
,
key
=
"'xyqbuser' + #user.phoneNo"
,
cacheManager
=
"cacheManager"
)
public
User
saveUser
(
User
user
)
{
public
User
saveUser
(
User
user
)
{
return
userRepository
.
save
(
user
);
return
userRepository
.
save
(
user
);
}
}
...
@@ -101,7 +102,7 @@ public class UserServiceImpl implements IUserService {
...
@@ -101,7 +102,7 @@ public class UserServiceImpl implements IUserService {
user
.
setUuid
(
uuid
);
user
.
setUuid
(
uuid
);
user
.
setPassword
(
PasswordUtil
.
MD5
(
password
.
toLowerCase
()
+
Constants
.
PASSWORD_SALT
));
user
.
setPassword
(
PasswordUtil
.
MD5
(
password
.
toLowerCase
()
+
Constants
.
PASSWORD_SALT
));
//解决线上白条registerFrom为1的问题
//解决线上白条registerFrom为1的问题
if
(
channelId
==
222L
)
{
if
(
channelId
==
222L
)
{
user
.
setRegisteredFrom
(
channelId
);
user
.
setRegisteredFrom
(
channelId
);
}
else
{
}
else
{
user
.
setRegisteredFrom
(
registerFrom
);
user
.
setRegisteredFrom
(
registerFrom
);
...
@@ -120,10 +121,11 @@ public class UserServiceImpl implements IUserService {
...
@@ -120,10 +121,11 @@ public class UserServiceImpl implements IUserService {
/**
/**
* 修改用户密码
* 修改用户密码
* @date 2017-02-15 修改用户修改密码时,更新updatedAt时间
*
* @param phoneNo
* @param phoneNo
* @param password
* @param password
* @return
* @return
* @date 2017-02-15 修改用户修改密码时,更新updatedAt时间
*/
*/
@Override
@Override
@CacheEvict
(
value
=
"usercache"
,
key
=
"'xyqbuser' + #phone"
,
cacheManager
=
"cacheManager"
)
@CacheEvict
(
value
=
"usercache"
,
key
=
"'xyqbuser' + #phone"
,
cacheManager
=
"cacheManager"
)
...
...
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