From 1cdb060a8aa59b0979f7609db1781805528e76e7 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 25 六月 2025 18:25:42 +0800
Subject: [PATCH] 视频评论数、收藏数通过mq、redis实现

---
 framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java |   51 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
index 28eb4e8..f4b64ea 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
@@ -1,9 +1,14 @@
 package cn.lili.modules.lmk.service.impl;
 
 import cn.lili.common.enums.CollectTypeEnum;
+import cn.lili.common.properties.RocketmqCustomProperties;
 import cn.lili.common.security.context.UserContext;
 import cn.lili.modules.goods.entity.vos.GoodsVO;
 import cn.lili.modules.lmk.domain.vo.*;
+import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
+import cn.lili.rocketmq.tags.CommentTagsEnum;
+import cn.lili.rocketmq.tags.VideoTagsEnum;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import cn.lili.modules.lmk.domain.entity.MyCollect;
 import cn.lili.modules.lmk.mapper.MyCollectMapper;
@@ -13,6 +18,7 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import cn.lili.modules.lmk.domain.form.MyCollectForm;
 import cn.lili.modules.lmk.domain.query.MyCollectQuery;
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.stereotype.Service;
 import lombok.RequiredArgsConstructor;
 import cn.lili.utils.PageUtil;
@@ -34,28 +40,41 @@
 public class MyCollectServiceImpl extends ServiceImpl<MyCollectMapper, MyCollect> implements MyCollectService {
 
     private final MyCollectMapper myCollectMapper;
-
+    private final RocketmqCustomProperties rocketmqCustomProperties;
     private final LmkFileServiceImpl fileService;
+    private final RocketMQTemplate rocketMQTemplate;
+
+
     /**
-     * 娣诲姞
+     * 鏀惰棌/鍙栨秷鏀惰棌
      * @param form
      * @return
      */
     @Override
     public Result change(MyCollectForm form) {
-        MyCollect myCollect = new LambdaQueryChainWrapper<>(baseMapper)
-                .eq(MyCollect::getCollectType, form.getCollectType())
-                .eq(MyCollect::getRefId, form.getRefId())
-                .eq(MyCollect::getUserId, UserContext.getCurrentUserId())
-                .one();
-        if (Objects.nonNull(myCollect)) {
-            baseMapper.deleteById(myCollect.getId());
+        // 瑙嗛鏀惰棌璧癿q
+        if (CollectTypeEnum.video.getType().equals(form.getCollectType())) {
+            MyCollect collect = new MyCollect();
+            collect.setRefId(form.getRefId());
+            collect.setCollectType(form.getCollectType());
+            collect.setUserId(UserContext.getCurrentUserId());
+            String destination = rocketmqCustomProperties.getVideoTopic() + ":" + VideoTagsEnum.COLLECT.name();
+            rocketMQTemplate.asyncSend(destination, JSON.toJSONString(collect), RocketmqSendCallbackBuilder.commonCallback());
         } else {
-            myCollect = new MyCollect();
-            myCollect.setRefId(form.getRefId());
-            myCollect.setCollectType(form.getCollectType());
-            myCollect.setUserId(UserContext.getCurrentUserId());
-            baseMapper.insert(myCollect);
+            MyCollect myCollect = new LambdaQueryChainWrapper<>(baseMapper)
+                    .eq(MyCollect::getCollectType, form.getCollectType())
+                    .eq(MyCollect::getRefId, form.getRefId())
+                    .eq(MyCollect::getUserId, UserContext.getCurrentUserId())
+                    .one();
+            if (Objects.nonNull(myCollect)) {
+                baseMapper.deleteById(myCollect.getId());
+            } else {
+                myCollect = new MyCollect();
+                myCollect.setRefId(form.getRefId());
+                myCollect.setCollectType(form.getCollectType());
+                myCollect.setUserId(UserContext.getCurrentUserId());
+                baseMapper.insert(myCollect);
+            }
         }
         return Result.ok("鎿嶄綔鎴愬姛");
     }
@@ -141,8 +160,8 @@
     }
 
     @Override
-    public List<CollectTypeNumVO> countNumGroupByType(String type) {
-        return baseMapper.countNumGroupByType(type);
+    public List<CollectTypeNumVO> countNumGroupByVideo() {
+        return baseMapper.countNumGroupByVideo();
     }
 
 

--
Gitblit v1.8.0