记得上下班打卡 | 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
9b61cc87
Commit
9b61cc87
authored
Aug 21, 2025
by
姜秀龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LostFoundItem redis
parent
c21f48ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
241 additions
and
31 deletions
+241
-31
SweetLostFoundItemServiceImpl.java
...ice/sweet/service/impl/SweetLostFoundItemServiceImpl.java
+54
-31
LostFoundRedisUtils.java
...om/liquidnet/service/sweet/utils/LostFoundRedisUtils.java
+187
-0
No files found.
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetLostFoundItemServiceImpl.java
View file @
9b61cc87
...
...
@@ -7,8 +7,10 @@ import com.liquidnet.service.sweet.entity.SweetLostFoundItem;
import
com.liquidnet.service.sweet.mapper.SweetLostFoundItemMapper
;
import
com.liquidnet.service.sweet.param.SweetLostFoundItemParam
;
import
com.liquidnet.service.sweet.service.ISweetLostFoundItemService
;
import
com.liquidnet.service.sweet.utils.LostFoundRedisUtils
;
import
com.liquidnet.service.sweet.vo.SweetLostFoundItemVo
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
...
...
@@ -23,6 +25,9 @@ import java.util.stream.Collectors;
@Service
public
class
SweetLostFoundItemServiceImpl
extends
ServiceImpl
<
SweetLostFoundItemMapper
,
SweetLostFoundItem
>
implements
ISweetLostFoundItemService
{
@Autowired
private
LostFoundRedisUtils
lostFoundRedisUtils
;
@Override
public
boolean
publishItem
(
SweetLostFoundItemParam
item
)
{
if
(
item
==
null
)
{
...
...
@@ -38,6 +43,8 @@ public class SweetLostFoundItemServiceImpl extends ServiceImpl<SweetLostFoundIte
lostFoundItem
.
setDescription
(
item
.
getDescription
());
lostFoundItem
.
setItemImage
(
item
.
getItemImage
());
lostFoundRedisUtils
.
deleteItemListCache
(
item
.
getPerformanceId
());
return
baseMapper
.
insert
(
lostFoundItem
)
>
0
;
}
...
...
@@ -57,6 +64,9 @@ public class SweetLostFoundItemServiceImpl extends ServiceImpl<SweetLostFoundIte
existingItem
.
setDescription
(
item
.
getDescription
());
existingItem
.
setItemImage
(
item
.
getItemImage
());
lostFoundRedisUtils
.
deleteItemListCache
(
item
.
getPerformanceId
());
lostFoundRedisUtils
.
deleteItemDetailCache
(
item
.
getId
());
return
baseMapper
.
updateById
(
existingItem
)
>
0
;
}
...
...
@@ -73,6 +83,9 @@ public class SweetLostFoundItemServiceImpl extends ServiceImpl<SweetLostFoundIte
}
item
.
setIsDeleted
(
1
);
lostFoundRedisUtils
.
deleteItemListCache
(
item
.
getPerformanceId
());
return
baseMapper
.
updateById
(
item
)
>
0
;
}
...
...
@@ -82,44 +95,54 @@ public class SweetLostFoundItemServiceImpl extends ServiceImpl<SweetLostFoundIte
return
null
;
}
SweetLostFoundItem
item
=
baseMapper
.
selectById
(
id
);
if
(
item
==
null
||
item
.
getIsDeleted
()
==
1
)
{
return
null
;
SweetLostFoundItemVo
itemDetail
=
lostFoundRedisUtils
.
getItemDetail
(
id
);
if
(
itemDetail
==
null
)
{
SweetLostFoundItem
item
=
baseMapper
.
selectById
(
id
);
if
(
item
==
null
||
item
.
getIsDeleted
()
==
1
)
{
return
null
;
}
SweetLostFoundItemVo
vo
=
new
SweetLostFoundItemVo
();
BeanUtils
.
copyProperties
(
item
,
vo
);
lostFoundRedisUtils
.
setItemDetail
(
id
,
vo
);
return
vo
;
}
SweetLostFoundItemVo
vo
=
new
SweetLostFoundItemVo
();
BeanUtils
.
copyProperties
(
item
,
vo
);
return
vo
;
return
itemDetail
;
}
@Override
public
List
<
SweetLostFoundItemVo
>
getItemList
(
Integer
itemType
,
String
performanceId
)
{
QueryWrapper
<
SweetLostFoundItem
>
queryWrapper
=
new
QueryWrapper
<>();
// 过滤逻辑删除的记录
queryWrapper
.
eq
(
"is_deleted"
,
0
);
// 根据演出ID查询
queryWrapper
.
eq
(
"performance_id"
,
performanceId
.
trim
());
// 根据物品类型查询
if
(
itemType
!=
null
)
{
queryWrapper
.
eq
(
"item_type"
,
itemType
);
List
<
SweetLostFoundItemVo
>
itemList
=
lostFoundRedisUtils
.
getItemList
(
performanceId
,
itemType
);
if
(
itemList
==
null
||
itemList
.
isEmpty
())
{
QueryWrapper
<
SweetLostFoundItem
>
queryWrapper
=
new
QueryWrapper
<>();
// 过滤
queryWrapper
.
eq
(
"is_deleted"
,
0
);
queryWrapper
.
eq
(
"performance_id"
,
performanceId
.
trim
());
// 排序
queryWrapper
.
orderByDesc
(
"create_time"
);
// 执行查询
List
<
SweetLostFoundItem
>
items
=
baseMapper
.
selectList
(
queryWrapper
);
// 转换为VO对象列表
List
<
SweetLostFoundItemVo
>
itemVos
=
items
.
stream
()
.
map
(
item
->
{
SweetLostFoundItemVo
vo
=
new
SweetLostFoundItemVo
();
BeanUtils
.
copyProperties
(
item
,
vo
);
return
vo
;
})
.
collect
(
Collectors
.
toList
());
lostFoundRedisUtils
.
setItemList
(
performanceId
,
itemVos
);
return
itemVos
.
stream
()
.
filter
(
item
->
itemType
.
equals
(
item
.
getItemType
()))
.
collect
(
Collectors
.
toList
());
}
// 排序:按创建时间降序排列
queryWrapper
.
orderByDesc
(
"create_time"
);
// 执行查询
List
<
SweetLostFoundItem
>
items
=
baseMapper
.
selectList
(
queryWrapper
);
// 转换为VO对象列表
return
items
.
stream
()
.
map
(
item
->
{
SweetLostFoundItemVo
vo
=
new
SweetLostFoundItemVo
();
BeanUtils
.
copyProperties
(
item
,
vo
);
return
vo
;
})
.
collect
(
Collectors
.
toList
());
return
itemList
;
}
}
\ No newline at end of file
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/utils/LostFoundRedisUtils.java
0 → 100644
View file @
9b61cc87
package
com
.
liquidnet
.
service
.
sweet
.
utils
;
import
com.liquidnet.common.cache.redis.util.RedisUtil
;
import
com.liquidnet.service.sweet.vo.SweetLostFoundItemVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 失物招领Redis缓存工具类
*
* @author liquidnet
* @since 2025-01-18
*/
@Slf4j
@Component
public
class
LostFoundRedisUtils
{
@Autowired
private
RedisUtil
redisUtil
;
// Redis key前缀
private
static
final
String
LOST_FOUND_KEY_PREFIX
=
"sweet:lost_found:"
;
private
static
final
String
ITEM_LIST_KEY
=
LOST_FOUND_KEY_PREFIX
+
"item_list:"
;
private
static
final
String
ITEM_DETAIL_KEY
=
LOST_FOUND_KEY_PREFIX
+
"item_detail:"
;
private
static
final
String
ADMIN_LIST_KEY
=
LOST_FOUND_KEY_PREFIX
+
"admin_list:"
;
// 缓存过期时间(秒)
private
static
final
long
LIST_EXPIRE_TIME
=
432000
;
// 5天
private
static
final
long
DETAIL_EXPIRE_TIME
=
432000
;
// 5天
/**
* 获取失物信息列表缓存
*
* @param performanceId 演出ID
* @param itemType 物品类型(可选,null表示全部)
* @return 失物信息列表
*/
public
List
<
SweetLostFoundItemVo
>
getItemList
(
String
performanceId
,
Integer
itemType
)
{
try
{
String
key
=
buildItemListKey
(
performanceId
);
Object
cachedValue
=
redisUtil
.
get
(
key
);
if
(
cachedValue
!=
null
)
{
List
<
SweetLostFoundItemVo
>
allItems
=
(
List
<
SweetLostFoundItemVo
>)
cachedValue
;
// 如果指定了itemType,进行筛选
if
(
itemType
!=
null
)
{
return
allItems
.
stream
()
.
filter
(
item
->
itemType
.
equals
(
item
.
getItemType
()))
.
collect
(
Collectors
.
toList
());
}
return
allItems
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取失物信息列表缓存失败"
,
e
);
}
return
null
;
}
/**
* 设置失物信息列表缓存
*
* @param performanceId 演出ID
* @param itemList 失物信息列表
*/
public
void
setItemList
(
String
performanceId
,
List
<
SweetLostFoundItemVo
>
itemList
)
{
try
{
String
key
=
buildItemListKey
(
performanceId
);
redisUtil
.
set
(
key
,
itemList
,
LIST_EXPIRE_TIME
);
}
catch
(
Exception
e
)
{
log
.
error
(
"设置失物信息列表缓存失败"
,
e
);
}
}
/**
* 获取失物信息详情缓存
*
* @param itemId 物品ID
* @return 失物信息详情
*/
public
SweetLostFoundItemVo
getItemDetail
(
Long
itemId
)
{
try
{
String
key
=
ITEM_DETAIL_KEY
+
itemId
;
Object
cachedValue
=
redisUtil
.
get
(
key
);
if
(
cachedValue
!=
null
)
{
return
(
SweetLostFoundItemVo
)
cachedValue
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取失物信息详情缓存失败"
,
e
);
}
return
null
;
}
/**
* 设置失物信息详情缓存
*
* @param itemId 物品ID
* @param itemDetail 失物信息详情
*/
public
void
setItemDetail
(
Long
itemId
,
SweetLostFoundItemVo
itemDetail
)
{
try
{
String
key
=
ITEM_DETAIL_KEY
+
itemId
;
redisUtil
.
set
(
key
,
itemDetail
,
DETAIL_EXPIRE_TIME
);
}
catch
(
Exception
e
)
{
log
.
error
(
"设置失物信息详情缓存失败"
,
e
);
}
}
/**
* 删除失物信息列表缓存
*
* @param performanceId 演出ID
*/
public
void
deleteItemListCache
(
String
performanceId
)
{
try
{
String
key
=
buildItemListKey
(
performanceId
);
redisUtil
.
del
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
"删除失物信息列表缓存失败"
,
e
);
}
}
/**
* 删除失物信息详情缓存
*
* @param itemId 物品ID
*/
public
void
deleteItemDetailCache
(
Long
itemId
)
{
try
{
String
key
=
ITEM_DETAIL_KEY
+
itemId
;
redisUtil
.
del
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
"删除失物信息详情缓存失败"
,
e
);
}
}
/**
* 构建失物信息列表缓存key
*
* @param performanceId 演出ID
* @return 缓存key
*/
private
String
buildItemListKey
(
String
performanceId
)
{
return
ITEM_LIST_KEY
+
performanceId
;
}
/*private String buildItemListKey(String performanceId) {
StringBuilder keyBuilder = new StringBuilder(ITEM_LIST_KEY);
keyBuilder.append(performanceId);
return keyBuilder.toString();
}*/
/**
* 检查管理员是否存在
*
* @param phone 手机号
* @param performanceId 演出ID
* @return 是否存在
*/
public
boolean
isAdminExists
(
String
phone
,
String
performanceId
)
{
try
{
String
key
=
ADMIN_LIST_KEY
+
phone
+
":"
+
performanceId
;
return
redisUtil
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
"检查管理员缓存失败"
,
e
);
return
false
;
}
}
/**
* 设置管理员缓存
*
* @param phone 手机号
* @param performanceId 演出ID
* @param isAdmin 是否是管理员
*/
public
void
setAdminCache
(
String
phone
,
String
performanceId
,
boolean
isAdmin
)
{
try
{
String
key
=
ADMIN_LIST_KEY
+
phone
+
":"
+
performanceId
;
redisUtil
.
set
(
key
,
isAdmin
,
1800
);
// 30分钟
}
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