f2cc79e9e83aafacc1af0e2c86e3c8df384fc895..817c7de04cb6b74164a42ed0e6050ae5b91b0ef1
2025-05-29 xiangpei
视频评论增加被回复人头像字段
817c7d 对比 | 目录
2025-05-29 xiangpei
视频评论数定时任务、视频评论查询
e0beab 对比 | 目录
14个文件已修改
184 ■■■■ 已修改文件
framework/src/main/java/cn/lili/modules/lmk/domain/entity/VideoComment.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/form/VideoCommentForm.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/resources/mapper/lmk/MyCollectMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/resources/mapper/lmk/VideoMapper.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lmk-job/src/main/java/cn/lili/job/VideoJob.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/domain/entity/VideoComment.java
@@ -38,6 +38,10 @@
    /** 被回复人昵称 */
    private String replyUserNickname;
    @TableField("reply_user_avatar")
    /** 被回复人头像 */
    private String replyUserAvatar;
    @TableField("master_comment_id")
    /** 主评论id */
    private String masterCommentId;
framework/src/main/java/cn/lili/modules/lmk/domain/form/VideoCommentForm.java
@@ -43,6 +43,9 @@
    @ApiModelProperty("回复的人昵称")
    private String replyUserNickname;
    @ApiModelProperty("回复的人头像")
    private String replyUserAvatar;
    @ApiModelProperty("主评论id,可从reply的评论上获取到")
    private String masterCommentId;
framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java
@@ -15,8 +15,8 @@
    private String id;
    /**
     * 收藏数量
     * 统计数量
     */
    private Long collectNum;
    private Long countNum;
}
framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java
@@ -2,6 +2,8 @@
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;
@@ -35,6 +37,7 @@
    private String replyId;
    private String replyUserId;
    private String replyUserNickname;
    private String replyUserAvatar;
    @ApiModelProperty("主评论id")
    private String masterCommentId;
@@ -52,6 +55,18 @@
    @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();
framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java
@@ -1,6 +1,7 @@
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;
@@ -41,10 +42,16 @@
    IPage masterCommentPage(IPage page, @Param("query") VideoCommentQuery query);
    /**
     * 小程序回复评论分页查询
     * 小程序回复评论
     *
     * @param page
     * @param query
     */
    IPage replyCommentPage(IPage page, @Param("query") VideoCommentQuery query);
    /**
     * 统计每个视频的评论数量
     *
     * @return
     */
    List<CollectTypeNumVO> countNumGroupByVideo();
}
framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java
@@ -54,4 +54,11 @@
     * @param numList
     */
    void updateCollectNumBatch(@Param("list") List<CollectTypeNumVO> numList);
    /**
     * 批量更新视频评论数量
     *
     * @param numList
     */
    void updateCommentNumBatch(@Param("list") List<CollectTypeNumVO> numList);
}
framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java
@@ -1,6 +1,7 @@
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;
@@ -63,4 +64,11 @@
     * @return
     */
    Result wxPage(VideoCommentQuery query);
    /**
     * 统计每个视频的评论数量
     *
     * @return
     */
    List<CollectTypeNumVO> countNumGroupByVideo();
}
framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java
@@ -129,6 +129,13 @@
    void updateCollectNumBatch(List<CollectTypeNumVO> numList);
    /**
     * 批量更新视频评论数量
     *
     * @param numList
     */
    void updateCommentNumBatch(List<CollectTypeNumVO> numList);
    /**
     * 保存视频观看记录
     *
     * @param form
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java
@@ -3,6 +3,7 @@
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;
@@ -43,7 +44,6 @@
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result comment(VideoCommentForm form) {
        // 监测内容是否包含敏感词
        if (SensitiveWordsFilter.includeSentenceWord(form.getCommentContent())) {
@@ -65,12 +65,7 @@
        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"));
    }
    /**
@@ -138,10 +133,17 @@
        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();
    }
}
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -295,6 +295,16 @@
    }
    @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());
framework/src/main/resources/mapper/lmk/MyCollectMapper.xml
@@ -57,7 +57,7 @@
    <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
framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml
@@ -10,11 +10,14 @@
        <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>
@@ -28,9 +31,15 @@
            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
@@ -43,9 +52,15 @@
            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
@@ -60,19 +75,30 @@
            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>
@@ -84,17 +110,19 @@
            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
@@ -102,4 +130,16 @@
            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>
framework/src/main/resources/mapper/lmk/VideoMapper.xml
@@ -172,7 +172,7 @@
        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
@@ -182,4 +182,19 @@
        </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>
lmk-job/src/main/java/cn/lili/job/VideoJob.java
@@ -3,6 +3,7 @@
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;
@@ -24,6 +25,7 @@
    private final VideoService videoService;
    private final MyCollectService myCollectService;
    private final VideoCommentService videoCommentService;
    /**
     * 视频收藏数统计
@@ -39,4 +41,18 @@
        }
    }
    /**
     * 视频评论数统计
     *
     * @throws Exception
     */
    @XxlJob("videoCommentNumJob")
    public void videoCommentNumJob() throws Exception {
        XxlJobHelper.log("开始执行:视频评论数统计");
        List<CollectTypeNumVO> numList = videoCommentService.countNumGroupByVideo();
        if (CollectionUtils.isNotEmpty(numList)) {
            videoService.updateCommentNumBatch(numList);
        }
    }
}