From e0beab0edb7049fdf46aca17f32f9dc5f4a8a755 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 29 五月 2025 17:33:15 +0800 Subject: [PATCH] 视频评论数定时任务、视频评论查询 --- framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java | 8 ++ framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml | 59 ++++++++++++++++--- framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java | 11 +++ framework/src/main/resources/mapper/lmk/VideoMapper.xml | 17 +++++ framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java | 18 +++-- framework/src/main/resources/mapper/lmk/MyCollectMapper.xml | 2 framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java | 4 framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java | 7 ++ framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java | 10 +++ framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java | 7 ++ framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java | 14 ++++ lmk-job/src/main/java/cn/lili/job/VideoJob.java | 16 +++++ 12 files changed, 148 insertions(+), 25 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java index d216c92..2097361 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/CollectTypeNumVO.java +++ b/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; } diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java index 2673cad..b10cae5 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/VideoCommentVO.java +++ b/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; @@ -52,6 +54,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(); diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java index 81749f8..a632138 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoCommentMapper.java +++ b/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(); } diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java index c7b4551..28854b7 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/mapper/VideoMapper.java +++ b/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); } diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java b/framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java index 09e62bf..bf8038f 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/service/VideoCommentService.java +++ b/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(); } diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java b/framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java index a781e88..38011b9 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/service/VideoService.java +++ b/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 diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java index 3874f5d..f71a858 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoCommentServiceImpl.java +++ b/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())) { - // 涓嶆槸鍥炲璇勮锛岄偅涔堝氨鏄富璇勮锛屼富璇勮鐨刴asterId璁剧疆涓鸿嚜宸辩殑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(); } } diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java index 8834a3f..bf978a9 100644 --- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java +++ b/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()); diff --git a/framework/src/main/resources/mapper/lmk/MyCollectMapper.xml b/framework/src/main/resources/mapper/lmk/MyCollectMapper.xml index 3a2e4a4..3f06bcb 100644 --- a/framework/src/main/resources/mapper/lmk/MyCollectMapper.xml +++ b/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 diff --git a/framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml b/framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml index 365fe5b..2e64ebc 100644 --- a/framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml +++ b/framework/src/main/resources/mapper/lmk/VideoCommentMapper.xml @@ -15,6 +15,8 @@ <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 +30,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 +51,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 @@ -65,14 +79,24 @@ 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> @@ -89,12 +113,13 @@ 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 +127,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> diff --git a/framework/src/main/resources/mapper/lmk/VideoMapper.xml b/framework/src/main/resources/mapper/lmk/VideoMapper.xml index 12e953f..be18336 100644 --- a/framework/src/main/resources/mapper/lmk/VideoMapper.xml +++ b/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> diff --git a/lmk-job/src/main/java/cn/lili/job/VideoJob.java b/lmk-job/src/main/java/cn/lili/job/VideoJob.java index 0afed57..7b3b710 100644 --- a/lmk-job/src/main/java/cn/lili/job/VideoJob.java +++ b/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); + } + } + } -- Gitblit v1.8.0