Commit 31dd5ed1 authored by 邓吉芬's avatar 邓吉芬

修改商品缓存

parent 5f4d77c5
...@@ -45,7 +45,7 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A ...@@ -45,7 +45,7 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A
public List<String> listAllActivityGoods(Long activityId) { public List<String> listAllActivityGoods(Long activityId) {
List<String> goodList = new ArrayList<>(); List<String> goodList = new ArrayList<>();
try { try {
Object object = redisTemplate.opsForValue().get(buildKey()); Object object = redisTemplate.opsForValue().get(buildKey(activityId));
if (Objects.nonNull(object)) { if (Objects.nonNull(object)) {
return (List<String>) object; return (List<String>) object;
} }
...@@ -59,7 +59,7 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A ...@@ -59,7 +59,7 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A
if (CollectionUtils.isNotEmpty(activityGoodsList)) { if (CollectionUtils.isNotEmpty(activityGoodsList)) {
goodList = activityGoodsList.stream().map(ActivityGoods::getCode).collect(Collectors.toList()); goodList = activityGoodsList.stream().map(ActivityGoods::getCode).collect(Collectors.toList());
try { try {
redisTemplate.opsForValue().setIfAbsent(buildKey(), goodList, Duration.ofHours(1)); redisTemplate.opsForValue().setIfAbsent(buildKey(activityId), goodList, Duration.ofHours(1));
} catch (Exception e) { } catch (Exception e) {
log.error("往缓存储存活动商品错误: {} ,继续执行操作", e.getMessage()); log.error("往缓存储存活动商品错误: {} ,继续执行操作", e.getMessage());
} }
...@@ -73,7 +73,8 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A ...@@ -73,7 +73,8 @@ public class ActivityGoodsServiceImpl extends ServiceImpl<ActivityGoodsMapper, A
* *
* @return * @return
*/ */
private String buildKey() { private String buildKey(Long activityId) {
return ConStants.SHIZU_DRAW_PREFIX + ConStants.SHIZU_ACTIVITY_GOOD; //shizu:draw:activity:good
return ConStants.SHIZU_DRAW_PREFIX + ConStants.SHIZU_ACTIVITY_GOOD+":"+activityId;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment