Commit ea2a4b66 by 田超

Merge branch 'feature/1003373' into 'master'

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

See merge request rays/pcloud-book!887
parents 8829304c 7d07a74c
......@@ -20,6 +20,7 @@ import com.pcloud.book.book.entity.BookRaysClassify;
import com.pcloud.book.consumer.app.AssistTempletConsr;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookServeDTO;
import com.pcloud.book.group.enums.AppAndProductTypeEnum;
import com.pcloud.book.group.enums.JoinGroupTypeEnum;
......@@ -49,6 +50,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -329,18 +331,50 @@ public class AppletUserBookcaseBizImpl implements AppletUserBookcaseBiz {
for (int i = 0; i < removeCount; i++) {
bookcaseList.remove(0);
}
//随机取一本书埋点
if (bookcaseList.size() > BookConstant.HOME_BOOK_PAGE) {
bookcaseList = getRandomList(bookcaseList, BookConstant.HOME_BOOK_PAGE);
}
bookcaseList.stream().forEach(appletUserBookcase -> {
this.addUserBook(appletUserBookcase);
});
bookcaseList.stream().forEach(e -> e.setBookGroupId(null == e.getBookGroupId() ? 0L : e.getBookGroupId()));
//升序排序
bookcaseList = bookcaseList.stream().sorted(Comparator.comparing(AppletUserBookcase::getBookGroupId)).collect(Collectors.toList());
addUserBooks(bookcaseList, wechatUserId);
ThreadPoolUtils.OTHER_THREAD_POOL.execute(() -> {
this.listByWechatUserId(wechatUserId, 0, BookConstant.HOME_BOOK_PAGE);
});
}
private void addUserBooks(List<AppletUserBookcase> bookcaseList, Long wechatUserId) {
if (ListUtils.isEmpty(bookcaseList)) {
return;
}
bookcaseList.stream().forEach(appletUserBookcase -> {
if (null == appletUserBookcase.getRightsSettingId()) {//书刊对应的权益
RightsSettingDto rightsSettingDto = rightsSettingBiz.getReadType4Book(wechatUserId, appletUserBookcase.getBookId(), appletUserBookcase.getChannelId(), appletUserBookcase.getAdviserId());
appletUserBookcase.setRightsSettingId(rightsSettingDto == null ? null : rightsSettingDto.getId());
if (null == appletUserBookcase.getReadType()) {//取书刊第一种阅读方式
if (null != rightsSettingDto && !ListUtils.isEmpty(rightsSettingDto.getRightsReadTypes())) {
for (RightsReadType rightsReadType : rightsSettingDto.getRightsReadTypes()) {
if (null != rightsReadType && null != rightsReadType.getRightsCount() && rightsReadType.getRightsCount() > 0) {
appletUserBookcase.setReadType(rightsReadType.getReadType());
break;
}
}
}
}
}
});
//数据库去重
appletUserBookcaseDao.insert(bookcaseList);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE + wechatUserId);
JedisClusterUtils.del(AppletConstants.USER_BOOK_CASE_COUNT + wechatUserId);
List<Long> bookIds = bookcaseList.stream().map(e -> e.getBookId()).collect(Collectors.toList());
if (!ListUtils.isEmpty(bookIds)) {
esBookAndAdviserBiz.updateBookAndAdviserToES(bookIds);
}
}
private List<AppletUserBookcase> getRandomList(List<AppletUserBookcase> paramList, int count) {
if (paramList.size() < count) {
return paramList;
......
......@@ -26,4 +26,7 @@ public class AppletUserBookcase extends BaseEntity {
@ApiModelProperty("权益id")
private Long rightsSettingId;
@ApiModelProperty("是否社群书")
private Long bookGroupId;
}
......@@ -10,12 +10,18 @@
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="read_type" property="readType" jdbcType="TINYINT" />
<result column="rights_setting_id" property="rightsSettingId" jdbcType="BIGINT" />
<result column="book_group_id" property="bookGroupId" jdbcType="BIGINT" />
</resultMap>
<sql id="Base_Column_List" >
id, wechat_user_id, book_id, channel_id, adviser_id, create_time,read_type, rights_setting_id
</sql>
<sql id="Base_Column_List_own" >
a.id, a.wechat_user_id, a.book_id, a.channel_id, a.adviser_id, a.create_time,read_type, a.rights_setting_id
</sql>
<insert id="insert" parameterType="com.pcloud.book.applet.entity.AppletUserBookcase" useGeneratedKeys="true" keyProperty="id">
insert into applet_user_bookcase (
wechat_user_id, book_id, channel_id, adviser_id, create_time, read_type, rights_setting_id
......@@ -28,6 +34,22 @@
create_time = now()
</insert>
<insert id="batchInsert" parameterType="com.pcloud.book.applet.entity.AppletUserBookcase" useGeneratedKeys="true" keyProperty="id">
insert into applet_user_bookcase (
wechat_user_id, book_id, channel_id, adviser_id, create_time, read_type, rights_setting_id
)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.wechatUserId}, #{item.bookId}, #{item.channelId}, #{item.adviserId}, NOW(), #{item.readType}, #{item.rightsSettingId}
)
</foreach>
on duplicate key
update
create_time = now()
</insert>
<select id="listByWechatUserId" parameterType="long" resultType="com.pcloud.book.applet.dto.AppletUserBookcaseDTO">
SELECT
c.id id,
......@@ -57,7 +79,7 @@
LEFT JOIN book_group d ON d.BOOK_ID = a.BOOK_ID and d.create_user=c.adviser_id and d.channel_id=c.channel_id AND d.IS_DELETE = 0
LEFT JOIN rights_setting r ON c.rights_setting_id = r.id AND d.join_group_type=4 and r.show_state = 1 and r.rights_setting_type = 2
WHERE c.wechat_user_id=#{wechatUserId}
ORDER BY c.create_time DESC
ORDER BY c.create_time DESC, d.id desc
</select>
<insert id="insertClickRecord" parameterType="com.pcloud.book.applet.entity.AppletUserClickRecord">
......@@ -178,13 +200,17 @@
<select id="getListByUserId" parameterType="long" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
<include refid="Base_Column_List_own"/>, t1.id book_group_id
FROM
applet_user_bookcase
applet_user_bookcase a
left JOIN book_group t1 ON a.book_id = t1.book_id
AND t1.join_group_type = 4
AND t1.is_delete = 0
WHERE
wechat_user_id = #{wechatUserId}
wechat_user_id = #{wechatUserId}
group by a.book_id, a.channel_id, a.adviser_id
ORDER BY
create_time DESC
create_time DESC, book_group_id desc
</select>
<select id="getBookcaseIdListByUser" resultType="long" parameterType="long">
......
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