记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
董敬伟
liquidnet-bus-v1
Commits
448ea260
Commit
448ea260
authored
Aug 26, 2025
by
姜秀龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LostFound 发现缓存有很多问题
parent
0f72e88e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
34 deletions
+74
-34
SweetLostFoundAdminController.java
...rvice/sweet/controller/SweetLostFoundAdminController.java
+5
-0
SweetLostFoundAdminServiceImpl.java
...ce/sweet/service/impl/SweetLostFoundAdminServiceImpl.java
+32
-25
LostFoundRedisUtils.java
...om/liquidnet/service/sweet/utils/LostFoundRedisUtils.java
+37
-9
No files found.
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/controller/SweetLostFoundAdminController.java
View file @
448ea260
...
...
@@ -63,6 +63,11 @@ public class SweetLostFoundAdminController {
@GetMapping
(
"/permission/{phone}/{performanceId}"
)
@ApiOperation
(
"获取权限"
)
/**
* 1. 删除不能图简单直接删除两个 key 这样容易删除单站把全站的也删除掉
* 2. 不能再读取的时候读不到在查 sql 再写入 redis 这里的情况不适用,没权限的用户导致一直查 sql 了
* 另外还会导致因为权限混在一起,crud 的时候考虑的会太复杂,现在分开处理逻辑就简单些,所以要在 cu的写入 redis
*/
public
ResponseDto
<
SweetLostFoundAdminVo
>
getPermission
(
@ApiParam
(
"手机号"
)
@PathVariable
String
phone
,
@ApiParam
(
"演出ID"
)
@PathVariable
String
performanceId
)
{
...
...
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetLostFoundAdminServiceImpl.java
View file @
448ea260
...
...
@@ -64,7 +64,13 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
foundAdmin
.
setPermissionType
(
admin
.
getPermissionType
());
foundAdmin
.
setAuthScope
(
admin
.
getAuthScope
());
foundAdmin
.
setPerformanceId
(
performanceId
);
return
ResponseDto
.
success
(
baseMapper
.
insert
(
foundAdmin
)
>
0
);
boolean
result
=
baseMapper
.
insert
(
foundAdmin
)
>
0
;
SweetLostFoundAdminVo
vo
=
new
SweetLostFoundAdminVo
();
BeanUtils
.
copyProperties
(
foundAdmin
,
vo
);
lostFoundRedisUtils
.
setAdminCache
(
phone
,
performanceId
,
vo
);
return
ResponseDto
.
success
(
result
);
}
// 假设:
...
...
@@ -122,11 +128,12 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
foundAdmin
.
setAuthScope
(
admin
.
getAuthScope
());
foundAdmin
.
setPerformanceId
(
performanceId
);
// 更新缓存
lostFoundRedisUtils
.
deleteAdminCache
(
phone
,
performanceId
);
if
(!
phone
.
equals
(
existingAdmin
.
getPhone
()))
{
lostFoundRedisUtils
.
deleteAdminCache
(
existingAdmin
.
getPhone
(),
performanceId
);
}
// 缓存
SweetLostFoundAdminVo
vo
=
new
SweetLostFoundAdminVo
();
BeanUtils
.
copyProperties
(
foundAdmin
,
vo
);
lostFoundRedisUtils
.
setAdminCache
(
phone
,
performanceId
,
vo
);
// 因为可能会更改权限范围 写入有范围的判断 所以直接删除老的
lostFoundRedisUtils
.
deleteAdminCache
(
existingAdmin
.
getPhone
(),
existingAdmin
.
getPerformanceId
(),
existingAdmin
.
getAuthScope
());
return
ResponseDto
.
success
(
baseMapper
.
updateById
(
foundAdmin
)
>
0
);
}
...
...
@@ -142,7 +149,7 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
// 逻辑删除:更新is_deleted字段为1
admin
.
setIsDeleted
(
1
);
lostFoundRedisUtils
.
deleteAdminCache
(
admin
.
getPhone
(),
admin
.
getPerformanceId
());
lostFoundRedisUtils
.
deleteAdminCache
(
admin
.
getPhone
(),
admin
.
getPerformanceId
()
,
admin
.
getAuthScope
()
);
return
baseMapper
.
updateById
(
admin
)
>
0
;
}
...
...
@@ -195,24 +202,24 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
@Override
public
SweetLostFoundAdminVo
hasPermission
(
String
phone
,
String
performanceId
)
{
SweetLostFoundAdminVo
adminCache
=
lostFoundRedisUtils
.
getAdminCache
(
phone
,
performanceId
);
if
(
adminCache
==
null
)
{
QueryWrapper
<
SweetLostFoundAdmin
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"phone"
,
phone
.
trim
())
.
eq
(
"is_deleted"
,
0
);
queryWrapper
.
and
(
wrapper
->
wrapper
.
eq
(
"performance_id"
,
performanceId
.
trim
())
.
or
()
.
eq
(
"auth_scope"
,
2
)
);
SweetLostFoundAdmin
admin
=
baseMapper
.
selectOne
(
queryWrapper
);
if
(
admin
==
null
)
{
return
null
;
}
SweetLostFoundAdminVo
vo
=
new
SweetLostFoundAdminVo
();
BeanUtils
.
copyProperties
(
admin
,
vo
);
lostFoundRedisUtils
.
setAdminCache
(
phone
,
performanceId
,
vo
);
return
vo
;
}
//
if (adminCache == null) {
//
QueryWrapper<SweetLostFoundAdmin> queryWrapper = new QueryWrapper<>();
//
queryWrapper.eq("phone", phone.trim())
//
.eq("is_deleted", 0);
//
queryWrapper.and(wrapper ->
//
wrapper.eq("performance_id", performanceId.trim())
//
.or()
//
.eq("auth_scope", 2)
//
);
//
SweetLostFoundAdmin admin = baseMapper.selectOne(queryWrapper);
//
if (admin == null) {
//
return null;
//
}
//
SweetLostFoundAdminVo vo = new SweetLostFoundAdminVo();
//
BeanUtils.copyProperties(admin, vo);
//
lostFoundRedisUtils.setAdminCache(phone, performanceId, vo);
//
return vo;
//
}
return
adminCache
;
}
}
\ No newline at end of file
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/utils/LostFoundRedisUtils.java
View file @
448ea260
...
...
@@ -162,10 +162,18 @@ public class LostFoundRedisUtils {
*/
public
SweetLostFoundAdminVo
getAdminCache
(
String
phone
,
String
performanceId
)
{
try
{
String
key
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
Object
cachedValue
=
redisUtil
.
get
(
key
);
if
(
cachedValue
!=
null
)
{
return
(
SweetLostFoundAdminVo
)
cachedValue
;
// 优先检查全站管理员缓存
String
globalKey
=
ADMIN_DETAIL_KEY
+
phone
+
":global"
;
Object
globalCache
=
redisUtil
.
get
(
globalKey
);
if
(
globalCache
!=
null
)
{
return
(
SweetLostFoundAdminVo
)
globalCache
;
}
// 检查特定演出管理员缓存
String
specificKey
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
Object
specificCache
=
redisUtil
.
get
(
specificKey
);
if
(
specificCache
!=
null
)
{
return
(
SweetLostFoundAdminVo
)
specificCache
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"检查管理员缓存失败"
,
e
);
...
...
@@ -182,8 +190,15 @@ public class LostFoundRedisUtils {
*/
public
void
setAdminCache
(
String
phone
,
String
performanceId
,
SweetLostFoundAdminVo
vo
)
{
try
{
String
key
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
set
(
key
,
vo
,
DETAIL_EXPIRE_TIME
);
if
(
vo
.
getAuthScope
()
!=
null
&&
vo
.
getAuthScope
()
==
2
)
{
// 全站管理员使用全局缓存键
String
globalKey
=
ADMIN_DETAIL_KEY
+
phone
+
":global"
;
redisUtil
.
set
(
globalKey
,
vo
,
DETAIL_EXPIRE_TIME
);
}
else
{
// 特定演出管理员使用演出特定的缓存键
String
specificKey
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
set
(
specificKey
,
vo
,
DETAIL_EXPIRE_TIME
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"设置管理员缓存失败"
,
e
);
}
...
...
@@ -195,12 +210,25 @@ public class LostFoundRedisUtils {
* @param phone 手机号
* @param performanceId 演出ID
*/
public
void
deleteAdminCache
(
String
phone
,
String
performanceId
)
{
public
void
deleteAdminCache
(
String
phone
,
String
performanceId
,
Integer
authScope
)
{
try
{
String
key
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
del
(
key
);
if
(
authScope
!=
null
&&
authScope
==
1
)
{
// 删除特定演出管理员缓存
String
specificKey
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
del
(
specificKey
);
}
else
if
(
authScope
!=
null
&&
authScope
==
2
)
{
// 删除全站管理员缓存
String
globalKey
=
ADMIN_DETAIL_KEY
+
phone
+
":global"
;
redisUtil
.
del
(
globalKey
);
}
else
{
String
specificKey
=
ADMIN_DETAIL_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
del
(
specificKey
);
String
globalKey
=
ADMIN_DETAIL_KEY
+
phone
+
":global"
;
redisUtil
.
del
(
globalKey
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"删除管理员缓存失败"
,
e
);
}
}
}
\ No newline at end of file
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