| | |
| | | /** 被回复人昵称 */ |
| | | private String replyUserNickname; |
| | | |
| | | @TableField("reply_user_avatar") |
| | | /** 被回复人头像 */ |
| | | private String replyUserAvatar; |
| | | |
| | | @TableField("master_comment_id") |
| | | /** 主评论id */ |
| | | private String masterCommentId; |
| | |
| | | @ApiModelProperty("回复的人昵称") |
| | | private String replyUserNickname; |
| | | |
| | | @ApiModelProperty("回复的人头像") |
| | | private String replyUserAvatar; |
| | | |
| | | @ApiModelProperty("主评论id,可从reply的评论上获取到") |
| | | private String masterCommentId; |
| | | |
| | |
| | | private String id; |
| | | |
| | | /** |
| | | * 收藏数量 |
| | | * 统计数量 |
| | | */ |
| | | private Long collectNum; |
| | | private Long countNum; |
| | | |
| | | } |
| | |
| | | |
| | | import cn.lili.base.AbsVo; |
| | | import cn.lili.modules.lmk.domain.entity.VideoComment; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | |
| | | private String replyId; |
| | | private String replyUserId; |
| | | private String replyUserNickname; |
| | | private String replyUserAvatar; |
| | | |
| | | @ApiModelProperty("主评论id") |
| | | private String masterCommentId; |
| | |
| | | @ApiModelProperty("评论人头像") |
| | | private String userAvatar; |
| | | |
| | | @ApiModelProperty("评论点赞数") |
| | | private Long thumbsUpCount; |
| | | |
| | | @ApiModelProperty("主评论下面总共有多少条回复") |
| | | private Long replyTotalCount; |
| | | |
| | | @ApiModelProperty("主评论下的子评论") |
| | | private List<VideoCommentVO> replies = new ArrayList(); |
| | | |
| | | @ApiModelProperty("是否展开子评论") |
| | | private Boolean expandReply = false; |
| | | |
| | | public static VideoCommentVO getVoByEntity(@NonNull VideoComment entity, VideoCommentVO vo) { |
| | | if(vo == null) { |
| | | vo = new VideoCommentVO(); |
| | |
| | | package cn.lili.modules.lmk.mapper; |
| | | |
| | | import cn.lili.modules.lmk.domain.entity.VideoComment; |
| | | import cn.lili.modules.lmk.domain.vo.CollectTypeNumVO; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import cn.lili.modules.lmk.domain.vo.VideoCommentVO; |
| | |
| | | IPage masterCommentPage(IPage page, @Param("query") VideoCommentQuery query); |
| | | |
| | | /** |
| | | * 小程序回复评论分页查询 |
| | | * 小程序回复评论 |
| | | * |
| | | * @param page |
| | | * @param query |
| | | */ |
| | | IPage replyCommentPage(IPage page, @Param("query") VideoCommentQuery query); |
| | | |
| | | /** |
| | | * 统计每个视频的评论数量 |
| | | * |
| | | * @return |
| | | */ |
| | | List<CollectTypeNumVO> countNumGroupByVideo(); |
| | | } |
| | |
| | | * @param numList |
| | | */ |
| | | void updateCollectNumBatch(@Param("list") List<CollectTypeNumVO> numList); |
| | | |
| | | /** |
| | | * 批量更新视频评论数量 |
| | | * |
| | | * @param numList |
| | | */ |
| | | void updateCommentNumBatch(@Param("list") List<CollectTypeNumVO> numList); |
| | | } |
| | |
| | | package cn.lili.modules.lmk.service; |
| | | |
| | | import cn.lili.modules.lmk.domain.entity.VideoComment; |
| | | import cn.lili.modules.lmk.domain.vo.CollectTypeNumVO; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import cn.lili.base.Result; |
| | | import cn.lili.modules.lmk.domain.form.VideoCommentForm; |
| | |
| | | * @return |
| | | */ |
| | | Result wxPage(VideoCommentQuery query); |
| | | |
| | | /** |
| | | * 统计每个视频的评论数量 |
| | | * |
| | | * @return |
| | | */ |
| | | List<CollectTypeNumVO> countNumGroupByVideo(); |
| | | } |
| | |
| | | void updateCollectNumBatch(List<CollectTypeNumVO> numList); |
| | | |
| | | /** |
| | | * 批量更新视频评论数量 |
| | | * |
| | | * @param numList |
| | | */ |
| | | void updateCommentNumBatch(List<CollectTypeNumVO> numList); |
| | | |
| | | /** |
| | | * 保存视频观看记录 |
| | | * |
| | | * @param form |
| | |
| | | import cn.lili.common.security.AuthUser; |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.common.sensitive.SensitiveWordsFilter; |
| | | import cn.lili.modules.lmk.domain.vo.CollectTypeNumVO; |
| | | import cn.lili.modules.lmk.enums.general.VideoCommentStatusEnum; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import cn.lili.modules.lmk.domain.entity.VideoComment; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result comment(VideoCommentForm form) { |
| | | // 监测内容是否包含敏感词 |
| | | if (SensitiveWordsFilter.includeSentenceWord(form.getCommentContent())) { |
| | |
| | | entity.setUserAvatar(currentUser.getFace()); |
| | | |
| | | baseMapper.insert(entity); |
| | | if (StringUtils.isBlank(entity.getReplyId())) { |
| | | // 不是回复评论,那么就是主评论,主评论的masterId设置为自己的id |
| | | entity.setMasterCommentId(entity.getId()); |
| | | } |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("添加成功"); |
| | | return Result.ok("添加成功").data(this.detail(entity.getId()).get("data")); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (StringUtils.isNotBlank(query.getMasterCommentId())) { |
| | | // 加载子评论的情况 |
| | | baseMapper.replyCommentPage(page, query); |
| | | return Result.ok().data(page.getRecords()); |
| | | } else { |
| | | // 加载主评论的情况。主评论id = masterCommentId |
| | | baseMapper.masterCommentPage(page, query); |
| | | } |
| | | return Result.ok().data(page.getRecords()); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<CollectTypeNumVO> countNumGroupByVideo() { |
| | | return baseMapper.countNumGroupByVideo(); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateCommentNumBatch(List<CollectTypeNumVO> numList) { |
| | | // 按500条数据进行拆分 |
| | | List<List<CollectTypeNumVO>> chunks = ListUtils.partition(numList, 500); |
| | | for (List<CollectTypeNumVO> chunk : chunks) { |
| | | baseMapper.updateCommentNumBatch(chunk); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Result saveViewRecord(VideoFootPrintForm form) { |
| | | FootPrint footPrint = new FootPrint(); |
| | | footPrint.setViewType(ViewTypeEnum.VIDEO.getValue()); |
| | |
| | | <select id="countNumGroupByType" parameterType="string" resultType="cn.lili.modules.lmk.domain.vo.CollectTypeNumVO"> |
| | | SELECT |
| | | ref_id as id, |
| | | count(id) as collectNum |
| | | count(id) as countNum |
| | | FROM |
| | | lmk_my_collect |
| | | WHERE |
| | |
| | | <result column="reply_id" property="replyId" /> |
| | | <result column="reply_user_id" property="replyUserId" /> |
| | | <result column="reply_user_nickname" property="replyUserNickname" /> |
| | | <result column="reply_user_avatar" property="replyUserAvatar" /> |
| | | <result column="master_comment_id" property="masterCommentId" /> |
| | | <result column="status" property="status" /> |
| | | <result column="create_by" property="userId" /> |
| | | <result column="user_nickname" property="userNickname" /> |
| | | <result column="user_avatar" property="userAvatar" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="replyTotalCount" property="replyTotalCount" /> |
| | | </resultMap> |
| | | |
| | | |
| | |
| | | LVC.video_id, |
| | | LVC.comment_content, |
| | | LVC.reply_id, |
| | | LVC.reply_user_id, |
| | | LVC.reply_user_nickname, |
| | | LVC.master_comment_id, |
| | | LVC.status, |
| | | LVC.id |
| | | LVC.id, |
| | | LVC.create_by, |
| | | LVC.user_nickname, |
| | | LVC.user_avatar, |
| | | LVC.create_time |
| | | FROM |
| | | lmk_video_comment LVC |
| | | WHERE |
| | |
| | | LVC.video_id, |
| | | LVC.comment_content, |
| | | LVC.reply_id, |
| | | LVC.reply_user_id, |
| | | LVC.reply_user_nickname, |
| | | LVC.master_comment_id, |
| | | LVC.status, |
| | | LVC.id |
| | | LVC.id, |
| | | LVC.create_by, |
| | | LVC.user_nickname, |
| | | LVC.user_avatar, |
| | | LVC.create_time |
| | | FROM |
| | | lmk_video_comment LVC |
| | | WHERE |
| | |
| | | LVC.reply_id, |
| | | LVC.reply_user_id, |
| | | LVC.reply_user_nickname, |
| | | LVC.reply_user_avatar, |
| | | LVC.master_comment_id, |
| | | LVC.status, |
| | | LVC.id, |
| | | LVC.create_by, |
| | | LVC.user_nickname, |
| | | LVC.user_avatar |
| | | LVC.user_avatar, |
| | | LVC.create_time, |
| | | COUNT(replies.id) as replyTotalCount |
| | | FROM |
| | | lmk_video_comment LVC |
| | | lmk_video_comment LVC |
| | | LEFT JOIN |
| | | lmk_video_comment replies ON replies.master_comment_id = LVC.id |
| | | AND replies.status = 'normal' |
| | | AND replies.delete_flag = 0 |
| | | WHERE |
| | | LVC.id = LVC.master_comment_id |
| | | AND LVC.video_id = #{query.videoId} |
| | | AND LVC.status = 'normal' |
| | | AND LVC.delete_flag = 0 |
| | | LVC.master_comment_id IS NULL |
| | | AND LVC.video_id = #{query.videoId} |
| | | AND LVC.status = 'normal' |
| | | AND LVC.delete_flag = 0 |
| | | GROUP BY |
| | | LVC.id, LVC.video_id, LVC.comment_content, LVC.reply_id, |
| | | LVC.reply_user_id, LVC.reply_user_nickname, LVC.master_comment_id, |
| | | LVC.status, LVC.create_by, LVC.user_nickname, LVC.user_avatar, LVC.create_time |
| | | ORDER BY |
| | | LVC.create_time DESC |
| | | </select> |
| | |
| | | LVC.reply_id, |
| | | LVC.reply_user_id, |
| | | LVC.reply_user_nickname, |
| | | LVC.reply_user_avatar, |
| | | LVC.master_comment_id, |
| | | LVC.status, |
| | | LVC.id, |
| | | LVC.create_by, |
| | | LVC.user_nickname, |
| | | LVC.user_avatar |
| | | LVC.user_avatar, |
| | | LVC.create_time, |
| | | 0 as replyTotalCount |
| | | FROM |
| | | lmk_video_comment LVC |
| | | WHERE |
| | | LVC.id = LVC.master_comment_id |
| | | AND LVC.video_id = #{query.videoId} |
| | | LVC.video_id = #{query.videoId} |
| | | AND LVC.master_comment_id = #{query.masterCommentId} |
| | | AND LVC.status = 'normal' |
| | | AND LVC.delete_flag = 0 |
| | |
| | | LVC.create_time ASC |
| | | </select> |
| | | |
| | | <select id="countNumGroupByVideo" resultType="cn.lili.modules.lmk.domain.vo.CollectTypeNumVO"> |
| | | SELECT |
| | | video_id as id, |
| | | COUNT(*) as countNum |
| | | FROM |
| | | lmk_video_comment |
| | | WHERE |
| | | delete_flag = 0 AND status = 'normal' |
| | | GROUP BY |
| | | video_id |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | UPDATE lmk_video |
| | | SET collect_num = CASE id |
| | | <foreach collection="list" item="video"> |
| | | WHEN #{video.id} THEN #{video.collectNum} |
| | | WHEN #{video.id} THEN #{video.countNum} |
| | | </foreach> |
| | | ELSE collect_num |
| | | END |
| | |
| | | </foreach> |
| | | </update> |
| | | |
| | | |
| | | <update id="updateCommentNumBatch"> |
| | | UPDATE lmk_video |
| | | SET comment_num = CASE id |
| | | <foreach collection="list" item="video"> |
| | | WHEN #{video.id} THEN #{video.countNum} |
| | | </foreach> |
| | | ELSE comment_num |
| | | END |
| | | WHERE id IN |
| | | <foreach collection="list" item="video" open="(" separator="," close=")"> |
| | | #{video.id} |
| | | </foreach> |
| | | </update> |
| | | |
| | | </mapper> |
| | |
| | | import cn.lili.modules.lmk.domain.vo.CollectTypeNumVO; |
| | | import cn.lili.modules.lmk.enums.general.CollectTypeEnum; |
| | | import cn.lili.modules.lmk.service.MyCollectService; |
| | | import cn.lili.modules.lmk.service.VideoCommentService; |
| | | import cn.lili.modules.lmk.service.VideoService; |
| | | import com.xxl.job.core.context.XxlJobHelper; |
| | | import com.xxl.job.core.handler.annotation.XxlJob; |
| | |
| | | |
| | | private final VideoService videoService; |
| | | private final MyCollectService myCollectService; |
| | | private final VideoCommentService videoCommentService; |
| | | |
| | | /** |
| | | * 视频收藏数统计 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 视频评论数统计 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @XxlJob("videoCommentNumJob") |
| | | public void videoCommentNumJob() throws Exception { |
| | | XxlJobHelper.log("开始执行:视频评论数统计"); |
| | | List<CollectTypeNumVO> numList = videoCommentService.countNumGroupByVideo(); |
| | | if (CollectionUtils.isNotEmpty(numList)) { |
| | | videoService.updateCommentNumBatch(numList); |
| | | } |
| | | } |
| | | |
| | | } |