Commit b4ac1cba by 吴博

feat: [1003373] 首页当前在读书设计优化调整

parent 1afc74b9
......@@ -373,6 +373,8 @@ public class BookConstant {
public static final String NO_RESOURCE_REMIND = "no_resource_remind";
public static final Integer HOME_BOOK_PAGE = 3;
public static final String DEFAULT_NEWS_PIC="https://oss.5rs.me/oss/uploadfe/jpg/c469a21a758b79e00783fe3a70a605c5.jpg";
/**
* 群二维码永久图文素材,html 源代码
......
package com.pcloud.book.applet.biz.impl;
import com.google.gson.internal.$Gson$Preconditions;
import com.pcloud.appcenter.assist.dto.AssistTempletDTO;
import com.pcloud.book.applet.biz.AppletNewsBiz;
import com.pcloud.book.applet.biz.AppletUserBookcaseBiz;
......@@ -13,6 +14,7 @@ import com.pcloud.book.applet.entity.AppletUserBookcase;
import com.pcloud.book.applet.entity.AppletUserClickRecord;
import com.pcloud.book.applet.enums.AppletNewsServeTypeEnum;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.book.dao.BookRaysClassifyDao;
import com.pcloud.book.book.entity.BookRaysClassify;
import com.pcloud.book.consumer.app.AssistTempletConsr;
......@@ -120,17 +122,20 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
}
//首页数据是否正确
Boolean correct = true;
if (0 == currentPage && 1 == numPerPage && !ListUtils.isEmpty(bookcaseDTOS)) {
AppletUserBookcaseDTO appletUserBookcase = bookcaseDTOS.get(0);
Integer correctCount = 0;
if (0 == currentPage && BookConstant.HOME_BOOK_PAGE == numPerPage && !ListUtils.isEmpty(bookcaseDTOS)) {
for (AppletUserBookcaseDTO appletUserBookcase : bookcaseDTOS) {
Long settingId = appletUserBookcase.getRightsSettingId() == null ? 0L : appletUserBookcase.getRightsSettingId();
RightsSettingDto rightsSettingDto = rightsSettingBiz.getRightsSettingByBookId4AppletHome(appletUserBookcase.getBookId(), appletUserBookcase.getAdviserId(), appletUserBookcase.getChannelId());
Long actualSettingId = rightsSettingDto.getId() == null ? 0L : rightsSettingDto.getId();
if (!actualSettingId.equals(settingId)) {
correct = false;
appletUserBookcaseDao.updateRightsSettingId(actualSettingId > 0 ? actualSettingId : null, appletUserBookcase.getBookId(), appletUserBookcase.getAdviserId(), appletUserBookcase.getChannelId());
}else {
++correctCount;
}
}
if (!ListUtils.isEmpty(bookcaseDTOS) && count > 0 && correct) {
}
if (!ListUtils.isEmpty(bookcaseDTOS) && count > 0 && correctCount.equals(bookcaseDTOS.size())) {
return new PageBeanNew<>(currentPage, numPerPage, count, bookcaseDTOS);
}
//数据库查询
......@@ -314,20 +319,48 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
@Override
public void randomChangeBook(Long wechatUserId) {
List<AppletUserBookcase> bookcaseList = appletUserBookcaseDao.getListByUserId(wechatUserId);
//无书或只有本不处理
if (ListUtils.isEmpty(bookcaseList) || bookcaseList.size() == 1) {
//无书或只有3本不处理
if (ListUtils.isEmpty(bookcaseList) || bookcaseList.size() < BookConstant.HOME_BOOK_PAGE) {
return;
}
//去除最近一本书
Integer removeCount = bookcaseList.size() - BookConstant.HOME_BOOK_PAGE;
removeCount = removeCount >= BookConstant.HOME_BOOK_PAGE ? BookConstant.HOME_BOOK_PAGE : removeCount;
//去除最近3本书
for (int i = 0; i < removeCount; i++) {
bookcaseList.remove(0);
}
//随机取一本书埋点
AppletUserBookcase appletUserBookcase = bookcaseList.get(new Random().nextInt(bookcaseList.size()));
if (bookcaseList.size() > BookConstant.HOME_BOOK_PAGE) {
bookcaseList = getRandomList(bookcaseList, BookConstant.HOME_BOOK_PAGE);
}
bookcaseList.stream().forEach(appletUserBookcase -> {
this.addUserBook(appletUserBookcase);
});
ThreadPoolUtils.OTHER_THREAD_POOL.execute(() -> {
this.listByWechatUserId(wechatUserId, 0, 1);
this.listByWechatUserId(wechatUserId, 0, BookConstant.HOME_BOOK_PAGE);
});
}
private List<AppletUserBookcase> getRandomList(List<AppletUserBookcase> paramList, int count) {
if (paramList.size() < count) {
return paramList;
}
Random random = new Random();
List<Integer> tempList = new ArrayList<Integer>();
List<AppletUserBookcase> newList = new ArrayList<AppletUserBookcase>();
int temp = 0;
for (int i = 0; i < count; i++) {
temp = random.nextInt(paramList.size());//将产生的随机数作为被抽list的索引
if (!tempList.contains(temp)) {
tempList.add(temp);
newList.add(paramList.get(temp));
} else {
i--;
}
}
return newList;
}
@Override
public List<Long> getBookcaseIdListByUser(Long wechatUserId) {
return appletUserBookcaseDao.getBookcaseIdListByUser(wechatUserId);
......
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