Commit 231451b4 by 李传峰

Merge branch 'feature/q4_20221226' into 'master'

feat:[none] 接口加缓存

See merge request rays/pcloud-book!1714
parents 82b6dc82 d1217400
......@@ -2864,11 +2864,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
amqpTemplate.convertAndSend(MQTopicProducer.EXCHAGE, MQTopicProducer.MEMBER_ACTIVITY_BOOK_SET, memberActivityBookSetDTO);
}
@Override
public ResourcePageVO getResourcePageByBookGroupIdOrSceneId4Wechat(Long bookGroupId, Long wechatUserId, Long sceneId) {
if (null == bookGroupId && null == sceneId) {
throw new BookBizException(BookBizException.PARAM_IS_NULL,"参数缺失");
}
private ResourcePageVO queryResourcePageByBookGroupIdOrSceneId4Wechat(Long bookGroupId, Long wechatUserId, Long sceneId) {
Long bookId = null;
if (null != bookGroupId) {
bookId = resourcePageDao.getBookIdByBookGroupId(bookGroupId);
......@@ -2928,7 +2924,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
couponVOS = couponFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
pushTextPermission = pushTextFuture.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("查询实体店铺/优惠券失败"+e.getMessage(),e);
log.error("查询实体店铺/优惠券失败"+e.getMessage(),e);
}
resourcePageVO.setResourcePageBookstoreList(bookstoreVOS);
resourcePageVO.setResourcePageCouponList(couponVOS);
......@@ -2937,6 +2933,37 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
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("加载企业微信落地页信息")
private void fillWxworkPage(ResourcePageVO resourcePageVO) {
if(resourcePageVO == null || resourcePageVO.getId() == null){
......@@ -4243,23 +4270,58 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
return false;
}
/**
* 查询书刊推荐资源
*/
@Override
public List<RecommendServeVO> getBookRecommendServe(Long wechatUserId, Long bookId, Long adviserId, Long channelId,Long sceneId) {
private String buildCacheKey(String prefix, Long...ids) {
StringBuilder sb = new StringBuilder(prefix);
for (Long id : ids) {
sb.append(":").append(Optional.ofNullable(id).orElse(0L));
}
return sb.toString();
}
private List<RecommendServeVO> queryBookRecommendServe(Long wechatUserId, Long bookId, Long adviserId, Long channelId,Long sceneId) {
//1.首先查书刊是否开启了资源推荐
OpenRecommendVO openRecommend=getRecommend(bookId,adviserId,channelId,sceneId);
if(null==openRecommend || null==openRecommend.getIsOpenRecommend() || 0==openRecommend.getIsOpenRecommend()){
OpenRecommendVO openRecommend = getRecommend(bookId, adviserId, channelId, sceneId);
if (null == openRecommend || null == openRecommend.getIsOpenRecommend() || 0 == openRecommend.getIsOpenRecommend()) {
return null;
}
//2.从系统数据表里面查到推荐资源,填充资源信息
List<RecommendServeDto> serveList = bookRecommendBiz.getById(bookId, channelId, adviserId, openRecommend.getRecommendFromType());
if(CollUtil.isEmpty(serveList)){
if (CollUtil.isEmpty(serveList)) {
return null;
}
//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;
}
......
......@@ -122,6 +122,14 @@ public class ThreadPoolUtils {
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());
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