Commit e8aeb914 by 阮思源

Merge branch 'zyj-news' into 'master'

1002952首页内容刷新频率修改

See merge request rays/pcloud-book!737
parents fc3991c5 fb9143b4
......@@ -2,6 +2,7 @@ package com.pcloud.book.applet.biz.impl;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletBooklistBiz;
import com.pcloud.book.applet.contants.AppletConstants;
import com.pcloud.book.applet.dao.AppletBooklistClassifyDao;
import com.pcloud.book.applet.dao.AppletBooklistDao;
import com.pcloud.book.applet.dto.AddBookParamDTO;
......@@ -16,7 +17,6 @@ import com.pcloud.book.book.biz.BookBiz;
import com.pcloud.book.book.dao.BookRaysClassifyDao;
import com.pcloud.book.consumer.app.AssistTempletConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.common.constant.CacheConstant;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
......@@ -43,7 +43,6 @@ import java.util.stream.Collectors;
@Component
public class AppletBooklistBizImpl implements AppletBooklistBiz {
private static final String BOOKLIST_BOOK = CacheConstant.BOOK+"APPLET:listBooklist4Wechat_";
@Autowired
private AppletBooklistClassifyDao appletBooklistClassifyDao;
......@@ -83,6 +82,7 @@ public class AppletBooklistBizImpl implements AppletBooklistBiz {
throw new BookBizException(BookBizException.PARAM_IS_NULL,"缺少id");
}
appletBooklistClassifyDao.update(appletBooklistClassify);
JedisClusterUtils.del(AppletConstants.HOME_BOOKLIST);
}
@Override
......@@ -105,7 +105,8 @@ public class AppletBooklistBizImpl implements AppletBooklistBiz {
appletBooklistDao.deleteById(id);
appletBooklistDao.deleteConfigByBooklistId(id);
//删除客户端缓存
JedisClusterUtils.del(BOOKLIST_BOOK+id);
JedisClusterUtils.del(AppletConstants.BOOKLIST_BOOK+id);
JedisClusterUtils.del(AppletConstants.HOME_BOOKLIST);
}
@Override
......@@ -162,7 +163,8 @@ public class AppletBooklistBizImpl implements AppletBooklistBiz {
appletBooklistDao.deleteConfigByBooklistId(booklistId);
appletBooklistDao.addBooklistConfig(configDTOS);
//删除客户端缓存
JedisClusterUtils.del(BOOKLIST_BOOK+booklistId);
JedisClusterUtils.del(AppletConstants.BOOKLIST_BOOK+booklistId);
JedisClusterUtils.del(AppletConstants.HOME_BOOKLIST);
}
@Override
......@@ -224,6 +226,7 @@ public class AppletBooklistBizImpl implements AppletBooklistBiz {
@Override
public PageBeanNew<AppletBooklistDTO> listBooklist4Wechat(Long classifyId, Integer currentPage, Integer numPerPage, Long wechatUserId) {
PageBeanNew<AppletBooklistDTO> pageBeanNew = new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
Map<String, Object> map = new HashMap<>();
if (null == classifyId) {//首页书单推荐
List<Long> classifyIds = appletBooklistClassifyDao.getClassifyIdsByUserId(wechatUserId);
......@@ -237,17 +240,28 @@ public class AppletBooklistBizImpl implements AppletBooklistBiz {
}
map.put("classifyIdList", classifyIds);
map.put("order", 1);
//首页3条缓存5小时
if (currentPage==0 && numPerPage==3){
List<AppletBooklistDTO> homeList = JedisClusterUtils.getJsonList(AppletConstants.HOME_BOOKLIST, AppletBooklistDTO.class);
if (!ListUtils.isEmpty(homeList)) {
pageBeanNew = new PageBeanNew<>(0, 3, homeList.size(), homeList);
} else {
pageBeanNew = appletBooklistDao.listPageNew(new PageParam(0, 3), map, "listBooklist4Wechat");
JedisClusterUtils.setJsonList(AppletConstants.HOME_BOOKLIST, pageBeanNew.getRecordList(), 5 * 3600);
}
}
} else {
map.put("classifyId", classifyId);
}
PageBeanNew<AppletBooklistDTO> pageBeanNew = appletBooklistDao.listPageNew(
new PageParam(currentPage, numPerPage), map, "listBooklist4Wechat");
if (ListUtils.isEmpty(pageBeanNew.getRecordList())){
pageBeanNew = appletBooklistDao.listPageNew(new PageParam(currentPage, numPerPage), map, "listBooklist4Wechat");
}
if (null == pageBeanNew || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
}
for (AppletBooklistDTO booklistDTO : pageBeanNew.getRecordList()) {
Long booklistId = booklistDTO.getId();
String key = BOOKLIST_BOOK + booklistId;
String key = AppletConstants.BOOKLIST_BOOK + booklistId;
List<BookDTO4Booklist> bookList = JedisClusterUtils.getJsonList(key, BookDTO4Booklist.class);
if (ListUtils.isEmpty(bookList)) {
bookList = appletBooklistDao.getBookBaseByBooklistId(booklistId, 0, 3);
......
package com.pcloud.book.applet.biz.impl;
import com.pcloud.book.applet.biz.AppletGroupSearchRecordBiz;
import com.pcloud.book.applet.contants.AppletConstants;
import com.pcloud.book.applet.dao.AppletGroupSearchRecordDao;
import com.pcloud.book.applet.dao.AppletGroupStatementDao;
import com.pcloud.book.applet.dto.AppletGroupSearchRecordDTO;
......@@ -54,9 +55,6 @@ public class AppletGroupSearchRecordBizImpl implements AppletGroupSearchRecordBi
private static final Logger LOGGER = LoggerFactory.getLogger(AppletGroupSearchRecordBizImpl.class);
private static final String GROUP_HEAD_URL_REDIS = CacheConstant.BOOK + "APPLET:pcloudGroupActivity_groupHeadUrl";
private static final String GROUP_STATEMENT_REDIS = CacheConstant.BOOK + "APPLET:pcloudGroupActivity_statement";
@Autowired
private AppletGroupSearchRecordDao appletGroupSearchRecordDao;
@Autowired
......@@ -199,11 +197,11 @@ public class AppletGroupSearchRecordBizImpl implements AppletGroupSearchRecordBi
@Override
public List<String> getHeadUrlList(Integer userNum, Long groupQrcodeId) {
List<String> headUrlList = JedisClusterUtils.hgetJson2List(GROUP_HEAD_URL_REDIS, groupQrcodeId.toString(), String.class);
List<String> headUrlList = JedisClusterUtils.hgetJson2List(AppletConstants.GROUP_HEAD_URL_REDIS, groupQrcodeId.toString(), String.class);
if (ListUtils.isEmpty(headUrlList) || (headUrlList.size() < 9 && !userNum.equals(headUrlList.size()))) {
headUrlList = readerConsr.getRandomHeadUrlList(userNum > 9 ? 9 : userNum);
JedisClusterUtils.hset2Json(GROUP_HEAD_URL_REDIS, groupQrcodeId.toString(), headUrlList);
JedisClusterUtils.expire(GROUP_HEAD_URL_REDIS, 3600);
JedisClusterUtils.hset2Json(AppletConstants.GROUP_HEAD_URL_REDIS, groupQrcodeId.toString(), headUrlList);
JedisClusterUtils.expire(AppletConstants.GROUP_HEAD_URL_REDIS, 3600);
}
return headUrlList;
}
......@@ -213,7 +211,7 @@ public class AppletGroupSearchRecordBizImpl implements AppletGroupSearchRecordBi
if (userNum <= 0) {
return new ArrayList<>();
}
List<AppletGroupStatementDTO> statementDTOS = JedisClusterUtils.hgetJson2List(GROUP_STATEMENT_REDIS, groupQrcodeId.toString(), AppletGroupStatementDTO.class);
List<AppletGroupStatementDTO> statementDTOS = JedisClusterUtils.hgetJson2List(AppletConstants.GROUP_STATEMENT_REDIS, groupQrcodeId.toString(), AppletGroupStatementDTO.class);
if (ListUtils.isEmpty(statementDTOS) || (statementDTOS.size() < 9 && !userNum.equals(statementDTOS.size()))) {
statementDTOS = new ArrayList<>();
userNum = userNum > 50 ? 50 : userNum;//最多50条
......@@ -232,8 +230,8 @@ public class AppletGroupSearchRecordBizImpl implements AppletGroupSearchRecordBi
statementDTO.setDuration(statement.getDuration());
statementDTOS.add(statementDTO);
}
JedisClusterUtils.hset2Json(GROUP_STATEMENT_REDIS, groupQrcodeId.toString(), statementDTOS);
JedisClusterUtils.expire(GROUP_STATEMENT_REDIS, 3600);
JedisClusterUtils.hset2Json(AppletConstants.GROUP_STATEMENT_REDIS, groupQrcodeId.toString(), statementDTOS);
JedisClusterUtils.expire(AppletConstants.GROUP_STATEMENT_REDIS, 3600);
}
return statementDTOS;
}
......
......@@ -2,6 +2,7 @@ package com.pcloud.book.applet.biz.impl;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletNewsBiz;
import com.pcloud.book.applet.contants.AppletConstants;
import com.pcloud.book.applet.dao.AppletLinkClickDao;
import com.pcloud.book.applet.dao.AppletNewsClassifyDao;
import com.pcloud.book.applet.dao.AppletNewsCommentDao;
......@@ -34,6 +35,7 @@ import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import com.pcloud.common.utils.string.StringUtil;
import com.pcloud.readercenter.wechat.entity.WechatUser;
......@@ -89,6 +91,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
throw new BookBizException(BookBizException.ERROR,"id为空");
}
appletNewsClassifyDao.update(appletNewsClassify);
JedisClusterUtils.del(AppletConstants.HOME_NEWS_LIST);
}
@Override
......@@ -98,6 +101,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
throw new BookBizException(BookBizException.ERROR,"请先清空资讯");
}
appletNewsClassifyDao.deleteById(id);
JedisClusterUtils.del(AppletConstants.HOME_NEWS_LIST);
}
@Override
......@@ -133,6 +137,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
rightsSettingBiz.setClassifyAndLabel(appletNews);
appletNewsDao.update(appletNews);
this.updateSource(beforeNews.getSource(),appletNews.getSource());
JedisClusterUtils.del(AppletConstants.HOME_NEWS_LIST);
}
@Override
......@@ -143,6 +148,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
}
appletNewsDao.deleteById(id);
this.updateSource(beforeNews.getSource(), null);
JedisClusterUtils.del(AppletConstants.HOME_NEWS_LIST);
}
@Override
......@@ -274,6 +280,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
@Override
public PageBeanNew<AppletNewsDTO> listAppletNews4Wechat(Integer currentPage, Integer numPerPage, Long newsClassifyId, Long wechatUserId) {
PageBeanNew<AppletNewsDTO> pageBeanNew = new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>()); ;
Map<String, Object> paramMap = new HashMap<>();
if (null == newsClassifyId) {//首页资讯
List<Long> classifyIds = appletNewsClassifyDao.getClassifyIdsByUserId(wechatUserId);
......@@ -287,11 +294,22 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
}
paramMap.put("newsClassifyIdList", classifyIds);
paramMap.put("order", 1);
//首页3条缓存5小时
if (currentPage==0 && numPerPage==3){
List<AppletNewsDTO> homeList = JedisClusterUtils.getJsonList(AppletConstants.HOME_NEWS_LIST, AppletNewsDTO.class);
if (!ListUtils.isEmpty(homeList)) {
pageBeanNew = new PageBeanNew<>(0, 3, homeList.size(), homeList);
} else {
pageBeanNew = appletNewsDao.listPageNew(new PageParam(0, 3), paramMap, "listAppletNews4Wechat");
JedisClusterUtils.setJsonList(AppletConstants.HOME_NEWS_LIST, pageBeanNew.getRecordList(), 5 * 3600);
}
}
} else {//栏目下的资讯
paramMap.put("newsClassifyId", newsClassifyId);
}
PageBeanNew<AppletNewsDTO> pageBeanNew = appletNewsDao.listPageNew(
new PageParam(currentPage, numPerPage), paramMap, "listAppletNews4Wechat");
if (ListUtils.isEmpty(pageBeanNew.getRecordList())) {
pageBeanNew = appletNewsDao.listPageNew(new PageParam(currentPage, numPerPage), paramMap, "listAppletNews4Wechat");
}
if (null == pageBeanNew || ListUtils.isEmpty(pageBeanNew.getRecordList())) {
return new PageBeanNew<>(currentPage, numPerPage, 0, new ArrayList<>());
}
......@@ -344,6 +362,7 @@ public class AppletNewsBizImpl implements AppletNewsBiz {
@Override
public void updateNewsShowState(AppletNews appletNews) {
appletNewsDao.updateNewsShowState(appletNews);
JedisClusterUtils.del(AppletConstants.HOME_NEWS_LIST);
}
@Override
......
......@@ -2,6 +2,7 @@ package com.pcloud.book.applet.biz.impl;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletUserBookcaseBiz;
import com.pcloud.book.applet.contants.AppletConstants;
import com.pcloud.book.applet.dao.AppletUserBookcaseDao;
import com.pcloud.book.applet.dto.AppletUserBookcaseDTO;
import com.pcloud.book.applet.dto.UserLastBookReDTO;
......@@ -47,8 +48,6 @@ import java.util.stream.Collectors;
@Component
public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
private static final String USER_BOOK_CASE = CacheConstant.BOOK+"APPLET:listByWechatUserId";
private static final String USER_BOOK_CASE_COUNT = CacheConstant.BOOK+"APPLET:listByWechatUserId-count";
@Autowired
private AppletUserBookcaseDao appletUserBookcaseDao;
......@@ -68,15 +67,15 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
//数据库去重
appletUserBookcaseDao.insert(appletUserBookcase);
Long wechatUserId = appletUserBookcase.getWechatUserId();
JedisClusterUtils.del(USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(USER_BOOK_CASE_COUNT + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE_COUNT + wechatUserId);
}
@Override
public PageBeanNew<AppletUserBookcaseDTO> listByWechatUserId(Long wechatUserId, Integer currentPage, Integer numPerPage) {
String key = USER_BOOK_CASE+wechatUserId;
String key = AppletConstants.USER_BOOK_CASE+wechatUserId;
String field = currentPage+"-"+numPerPage;
String countKey = USER_BOOK_CASE_COUNT+wechatUserId;
String countKey = AppletConstants.USER_BOOK_CASE_COUNT+wechatUserId;
List<AppletUserBookcaseDTO> bookcaseDTOS = JedisClusterUtils.hgetJson2List(key,field,AppletUserBookcaseDTO.class);
Integer count =0;
String countStr = JedisClusterUtils.get(countKey);
......@@ -220,8 +219,8 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
return;
}
appletUserBookcaseDao.deleteByIds(ids);
JedisClusterUtils.del(USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(USER_BOOK_CASE_COUNT + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE_COUNT + wechatUserId);
}
@Override
......
package com.pcloud.book.applet.contants;
import com.pcloud.common.constant.CacheConstant;
/**
* @ClassName com.pcloud.book.applet.contants.AppletConstants
* @Author zhuyajie
* @Description 常量
* @Date 2020/5/25 11:23
* @Version 1.0
**/
public class AppletConstants {
/**
* 已读书刊列表
*/
public static final String USER_BOOK_CASE = CacheConstant.BOOK+"APPLET:listByWechatUserId";
public static final String USER_BOOK_CASE_COUNT = CacheConstant.BOOK+"APPLET:listByWechatUserId-count";
/**
* 书单书籍列表
*/
public static final String BOOKLIST_BOOK = CacheConstant.BOOK+"APPLET:listBooklist4Wechat_";
/**
* 共读社群头像
*/
public static final String GROUP_HEAD_URL_REDIS = CacheConstant.BOOK + "APPLET:pcloudGroupActivity_groupHeadUrl";
/**
* 共读社群对话
*/
public static final String GROUP_STATEMENT_REDIS = CacheConstant.BOOK + "APPLET:pcloudGroupActivity_statement";
/**
* 首页推荐资讯列表
*/
public static final String HOME_NEWS_LIST = CacheConstant.BOOK+"APPLET:listAppletNews4Wechat";
/**
* 首页推荐书单列表
*/
public static final String HOME_BOOKLIST = CacheConstant.BOOK+"APPLET:listBooklist4Wechat";
}
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