Commit d1217400 by 李传峰

feat:[none] 接口加缓存

parent 82b6dc82
...@@ -2864,11 +2864,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -2864,11 +2864,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.MEMBER_ACTIVITY_BOOK_SET, memberActivityBookSetDTO); amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.MEMBER_ACTIVITY_BOOK_SET, memberActivityBookSetDTO);
} }
@Override private ResourcePageVO queryResourcePageByBookGroupIdOrSceneId4Wechat(Long bookGroupId, Long wechatUserId, Long sceneId) {
public ResourcePageVO getResourcePageByBookGroupIdOrSceneId4Wechat(Long bookGroupId, Long wechatUserId, Long sceneId) {
if (null == bookGroupId && null == sceneId) {
throw new BookBizException(BookBizException.PARAM_IS_NULL,"参数缺失");
}
Long bookId = null; Long bookId = null;
if (null != bookGroupId) { if (null != bookGroupId) {
bookId = resourcePageDao.getBookIdByBookGroupId(bookGroupId); bookId = resourcePageDao.getBookIdByBookGroupId(bookGroupId);
...@@ -2928,7 +2924,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -2928,7 +2924,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
couponVOS = couponFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS); couponVOS = couponFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
pushTextPermission = pushTextFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS); pushTextPermission = pushTextFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("查询实体店铺/优惠券失败"+e.getMessage(),e); log.error("查询实体店铺/优惠券失败"+e.getMessage(),e);
} }
resourcePageVO.setResourcePageBookstoreList(bookstoreVOS); resourcePageVO.setResourcePageBookstoreList(bookstoreVOS);
resourcePageVO.setResourcePageCouponList(couponVOS); resourcePageVO.setResourcePageCouponList(couponVOS);
...@@ -2937,6 +2933,37 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -2937,6 +2933,37 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
return resourcePageVO; return resourcePageVO;
} }
@Override
public ResourcePageVO getResourcePageByBookGroupIdOrSceneId4Wechat(Long bookGroupId, Long wechatUserId, Long sceneId) {
if (null == bookGroupId && null == sceneId) {
throw new BookBizException(BookBizException.PARAM_IS_NULL,"参数缺失");
}
String cacheKey = buildCacheKey("book:getResourcePageByBookGroupIdOrSceneId4Wechat", bookGroupId, wechatUserId, sceneId);
ResourcePageVO result = JedisClusterUtils.getJson(cacheKey, ResourcePageVO.class);
if (result == null) {
if (JedisClusterUtils.lock(cacheKey + ":lock", 1)) {
result = queryResourcePageByBookGroupIdOrSceneId4Wechat(bookGroupId, wechatUserId, sceneId);
JedisClusterUtils.setJson(cacheKey, result, 600);
JedisClusterUtils.del(cacheKey + ":lock");
return result;
}
for (int i = 1; i < 6; i++) {
ThreadPoolUtils.sleep(i * 20);
result = JedisClusterUtils.getJson(cacheKey, ResourcePageVO.class);
if (result != null) {
return result;
}
if (i == 5) {
result = queryResourcePageByBookGroupIdOrSceneId4Wechat(bookGroupId, wechatUserId, sceneId);
JedisClusterUtils.setJson(cacheKey, result, 600);
break;
}
}
}
return result;
}
@ParamLog("加载企业微信落地页信息") @ParamLog("加载企业微信落地页信息")
private void fillWxworkPage(ResourcePageVO resourcePageVO) { private void fillWxworkPage(ResourcePageVO resourcePageVO) {
if(resourcePageVO == null || resourcePageVO.getId() == null){ if(resourcePageVO == null || resourcePageVO.getId() == null){
...@@ -4243,23 +4270,58 @@ public class ResourcePageBizImpl implements ResourcePageBiz { ...@@ -4243,23 +4270,58 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
return false; return false;
} }
/** private String buildCacheKey(String prefix, Long...ids) {
* 查询书刊推荐资源 StringBuilder sb = new StringBuilder(prefix);
*/ for (Long id : ids) {
@Override sb.append(":").append(Optional.ofNullable(id).orElse(0L));
public List<RecommendServeVO> getBookRecommendServe(Long wechatUserId, Long bookId, Long adviserId, Long channelId,Long sceneId) { }
return sb.toString();
}
private List<RecommendServeVO> queryBookRecommendServe(Long wechatUserId, Long bookId, Long adviserId, Long channelId,Long sceneId) {
//1.首先查书刊是否开启了资源推荐 //1.首先查书刊是否开启了资源推荐
OpenRecommendVO openRecommend=getRecommend(bookId,adviserId,channelId,sceneId); OpenRecommendVO openRecommend = getRecommend(bookId, adviserId, channelId, sceneId);
if(null==openRecommend || null==openRecommend.getIsOpenRecommend() || 0==openRecommend.getIsOpenRecommend()){ if (null == openRecommend || null == openRecommend.getIsOpenRecommend() || 0 == openRecommend.getIsOpenRecommend()) {
return null; return null;
} }
//2.从系统数据表里面查到推荐资源,填充资源信息 //2.从系统数据表里面查到推荐资源,填充资源信息
List<RecommendServeDto> serveList = bookRecommendBiz.getById(bookId, channelId, adviserId, openRecommend.getRecommendFromType()); List<RecommendServeDto> serveList = bookRecommendBiz.getById(bookId, channelId, adviserId, openRecommend.getRecommendFromType());
if(CollUtil.isEmpty(serveList)){ if (CollUtil.isEmpty(serveList)) {
return null; return null;
} }
//3.填充服务信息。以及channel对应的公众号信息 //3.填充服务信息。以及channel对应的公众号信息
List<RecommendServeVO> result = getRecommendServeVOS(channelId, serveList); return getRecommendServeVOS(channelId, serveList);
}
/**
* 查询书刊推荐资源
*/
@Override
public List<RecommendServeVO> getBookRecommendServe(Long wechatUserId, Long bookId, Long adviserId, Long channelId,Long sceneId) {
String cacheKey = buildCacheKey("book:getBookRecommendServe", wechatUserId, bookId, adviserId, channelId, sceneId);
List<RecommendServeVO> result = JedisClusterUtils.getJsonList(cacheKey, RecommendServeVO.class);
if (result == null) {
if (JedisClusterUtils.lock(cacheKey + ":lock", 1)) {
result = queryBookRecommendServe(wechatUserId, bookId, adviserId, channelId, sceneId);
JedisClusterUtils.setJsonList(cacheKey, Optional.ofNullable(result).orElseGet(ArrayList::new), 600);
JedisClusterUtils.del(cacheKey + ":lock");
return result;
}
for (int i = 1; i < 6; i++) {
ThreadPoolUtils.sleep(i * 20);
result = JedisClusterUtils.getJsonList(cacheKey, RecommendServeVO.class);
if (result != null) {
return result;
}
if (i == 5) {
result = queryBookRecommendServe(wechatUserId, bookId, adviserId, channelId, sceneId);
JedisClusterUtils.setJsonList(cacheKey, Optional.ofNullable(result).orElseGet(ArrayList::new), 600);
break;
}
}
}
return result; return result;
} }
......
...@@ -122,6 +122,14 @@ public class ThreadPoolUtils { ...@@ -122,6 +122,14 @@ public class ThreadPoolUtils {
public static final ExecutorService BOOK_BASE_INFO_POOL = new ThreadPoolExecutor(16, 128, 0L, TimeUnit.SECONDS, public static final ExecutorService BOOK_BASE_INFO_POOL = new ThreadPoolExecutor(16, 128, 0L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("book-base-info-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("book-base-info-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
public static void sleep(int mills) {
try {
TimeUnit.MILLISECONDS.sleep(mills);
} catch (InterruptedException e) {
// ignore
}
}
} }
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