From 7e18df25f60e472b52f8a1b9a9128f02189da309 Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 14 May 2022 23:18:39 +0800 Subject: [PATCH] fix bug --- .../market/WxCouponChannelController.java | 1 + .../controller/WxCouponChannelController.java | 11 ++---- .../service/util/CouponCacheUtils.java | 37 ++++++++++++------- .../com/iformall/utils/RedisCacheUtils.java | 5 +++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java index ae1318998..c86725048 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponChannelController.java @@ -94,6 +94,7 @@ public class WxCouponChannelController extends BaseController { wxCouponChannelService.updateQrCode(couponChannel,couponChannel.getId(),couponChannel.getType()); } CouponCacheUtils.removeCouponChannelCache(redisTemplate, wxCouponChannel.getId()); + CouponCacheUtils.removeDouyinLivePageCache(redisTemplate, wxCouponChannel.getTenantId(), null, null); return resultData; } diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java index 6ce3d9fc1..c40a017f9 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponChannelController.java @@ -30,6 +30,7 @@ import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxMerchantService; +import com.iformall.service.util.CouponCacheUtils; import com.iformall.utils.RedisCacheUtils; import io.swagger.annotations.Api; @@ -113,17 +114,11 @@ public class WxCouponChannelController extends BaseController { wxCouponChannel.setSortColumns(BaseEntity.SortField.CCUpdateDate_DESC, BaseEntity.SortField.CCId_DESC); wxCouponChannel.setShowBeginTime(new Date()); - String key = EnumCacheKey.DOUYIN_LIVE_PAGE_LIST.getMessage() - + wxCouponChannel.getTenantId() + "_" - + wxCouponChannel.getTargetAd() + "_" - + wxCouponChannel.getBusiness() + "_" - + pageNum + ":"+ pageNum + ":"; - PageInfo page = RedisCacheUtils.getCacheObject(redisTemplate, key, PageInfo.class); - logger.info("WxCouponChannelController.chache.get:{} page:{}",key,page); + PageInfo page = CouponCacheUtils.getDouyinLivePageCache(redisTemplate, wxCouponChannel.getTenantId(), wxCouponChannel.getTargetAd(), wxCouponChannel.getBusiness(), pageNum); if (null == page ) { page = wxCouponChannelService.liveHomePage(wxCouponChannel, pageNum, pageSize); if(page.getList() != null && page.getList().size() > 0){ - RedisCacheUtils.cache(redisTemplate, key, page, 60*60); + CouponCacheUtils.setDouyinLivePageCache(redisTemplate, page, wxCouponChannel.getTenantId(), wxCouponChannel.getTargetAd(), wxCouponChannel.getBusiness(), pageNum); } } return new ResultData(page); diff --git a/mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java b/mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java index f7995d1c5..a9e97702d 100644 --- a/mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java +++ b/mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java @@ -2,11 +2,14 @@ package com.iformall.service.util; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; +import com.github.pagehelper.PageInfo; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.vo.WxMerchantVo; +import com.iformall.enums.EnumCacheKey; import com.iformall.utils.RedisCacheUtils; public class CouponCacheUtils { @@ -57,19 +60,25 @@ public class CouponCacheUtils { return RedisCacheUtils.getCacheListObject(template, key,WxMerchantVo.class); } -// public static void removeDouyinLivePageCache(RedisTemplate template,String tenantId,Integer targetAd,Integer bussiness) { -// String key = "couponMerchant:"+couponId; -// RedisCacheUtils.removeCache(template, key); -// } -// -// public static void setDouyinLivePageCache(RedisTemplate template,Long couponId,List merchantList) { -// String key = "couponMerchant:"+couponId; -// RedisCacheUtils.cache(template, key, merchantList, 24*3600); -// } -// -// public static List getDouyinLivePageCache(RedisTemplate template,Long couponId) { -// String key = "couponMerchant:"+couponId; -// return RedisCacheUtils.getCacheListObject(template, key,WxMerchantVo.class); -// } + public static void removeDouyinLivePageCache(RedisTemplate template,String tenantId,Integer targetAd,Integer bussiness) { + String key = EnumCacheKey.DOUYIN_LIVE_PAGE_LIST.getMessage()+ tenantId+"_"; + if (null != targetAd) { + key = key + targetAd; + if ( null != bussiness) { + key = key + "_"+ bussiness; + } + } + RedisCacheUtils.removeCachePrefix(template, key); + } + + public static void setDouyinLivePageCache(RedisTemplate template,PageInfo pageList,String tenantId,Integer targetAd,Integer bussiness,Integer pageNum) { + String key = EnumCacheKey.DOUYIN_LIVE_PAGE_LIST.getMessage()+ tenantId + "_"+ targetAd + "_"+ bussiness+"_"+pageNum; + RedisCacheUtils.cache(template, key, pageList, 3*3600); + } + + public static PageInfo getDouyinLivePageCache(RedisTemplate template,String tenantId,Integer targetAd,Integer bussiness,Integer pageNum) { + String key = EnumCacheKey.DOUYIN_LIVE_PAGE_LIST.getMessage()+ tenantId + "_"+ targetAd + "_"+ bussiness+"_"+pageNum; + return RedisCacheUtils.getCacheObject(template, key,PageInfo.class); + } } diff --git a/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java b/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java index 8c0cbab4b..d4a3f31e7 100644 --- a/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/RedisCacheUtils.java @@ -164,4 +164,9 @@ public class RedisCacheUtils { template.delete(key); } } + + public static void removeCachePrefix(RedisTemplate template,String prefix) { + Set keys = template.keys(prefix+"*"); + template.delete(keys); + } }