Commit 0bcb938b by 田超

Merge branch 'feature/1003373' into 'master'

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

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