From b5895f07285cb1063e805e122f8acf36f4c458ba Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期五, 27 六月 2025 16:04:14 +0800
Subject: [PATCH] insert 修改神厨和大健康视频发布时匹配填充模式

---
 framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java |   99 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 97 insertions(+), 2 deletions(-)

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 0a734f9..cfa0214 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
@@ -1,6 +1,9 @@
 package cn.lili.modules.lmk.service.impl;
 
+import cn.lili.cache.Cache;
+import cn.lili.cache.CachePrefix;
 import cn.lili.common.security.context.UserContext;
+import cn.lili.modules.lmk.constant.RedisKeyExpireConstant;
 import cn.lili.modules.lmk.domain.entity.*;
 import cn.lili.modules.lmk.domain.form.*;
 import cn.lili.modules.lmk.domain.query.*;
@@ -57,6 +60,7 @@
     private final KitchenVideoTypeRefService kitchenVideoTypeRefService;
     private final VideoGoodsService videoGoodsService;
     private final KitchenTypeService kitchenTypeService;
+    private final Cache cache;
 
     /**
      * 娣诲姞
@@ -197,6 +201,7 @@
                 VideoGoods e = new VideoGoods();
                 e.setVideoId(video.getId());
                 e.setGoodsId(form.getGoodsList().get(i).getGoodsId());
+                e.setGoodsSkuId(form.getGoodsList().get(i).getGoodsSkuId());
                 e.setGoodsNum(form.getGoodsList().get(i).getGoodsNum());
                 e.setOrderNum(i);
                 videoGoods.add(e);
@@ -260,6 +265,7 @@
                 VideoGoods e = new VideoGoods();
                 e.setVideoId(video.getId());
                 e.setGoodsId(form.getGoodsList().get(i).getGoodsId());
+                e.setGoodsSkuId(form.getGoodsList().get(i).getGoodsSkuId());
                 e.setGoodsNum(form.getGoodsList().get(i).getGoodsNum());
                 e.setOrderNum(i);
                 videoGoods.add(e);
@@ -387,6 +393,8 @@
             page.getRecords().forEach(v -> {
                 v.setTagList(tagMap.get(v.getId()));
                 v.setCollected(CollectionUtils.isNotEmpty(collectMap.get(v.getId())));
+                v.setCommentNum(this.getCommentNum(v.getId(), v.getCommentNum()));
+                v.setCollectNum(this.getCollectNum(v.getId(), v.getCollectNum()));
                 if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
                     v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
                     v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverFileKey()));
@@ -398,6 +406,40 @@
             });
         }
         return Result.ok().data(page.getRecords());
+    }
+
+    /**
+     * 浠巖edis涓幏鍙栬瘎璁烘暟閲忥紝濡傛灉redis涓病鏈夊垯灏唌ysql涓殑鏁伴噺鍐欏叆鍒皉edis
+     *
+     * @param videoId
+     * @param mysqlNum
+     * @return
+     */
+    private Integer getCommentNum(String videoId, Integer mysqlNum) {
+        Object redisNum = cache.get(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId));
+        if (Objects.isNull(redisNum)) {
+            // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
+            cache.put(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.COMMENT_NUM_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
+            return mysqlNum;
+        }
+        return (Integer) redisNum;
+    }
+
+    /**
+     * 浠巖edis涓幏鍙栨敹钘忔暟閲忥紝濡傛灉redis涓病鏈夊垯灏唌ysql涓殑鏁伴噺鍐欏叆鍒皉edis
+     *
+     * @param videoId
+     * @param mysqlNum
+     * @return
+     */
+    private Integer getCollectNum(String videoId, Integer mysqlNum) {
+        Object redisNum = cache.get(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId));
+        if (Objects.isNull(redisNum)) {
+            // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
+            cache.put(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.COLLECT_NUM_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
+            return mysqlNum;
+        }
+        return (Integer) redisNum;
     }
 
     @Override
@@ -444,6 +486,10 @@
         List<List<CollectTypeNumVO>> chunks = ListUtils.partition(numList, 500);
         for (List<CollectTypeNumVO> chunk : chunks) {
             baseMapper.updateCollectNumBatch(chunk);
+            new LambdaUpdateChainWrapper<>(baseMapper)
+                    .in(Video::getId, chunk.stream().map(CollectTypeNumVO::getId).collect(Collectors.toList()))
+                    .set(Video::getCollectNumJob, Boolean.FALSE)
+                    .update();
         }
     }
 
@@ -454,6 +500,10 @@
         List<List<CollectTypeNumVO>> chunks = ListUtils.partition(numList, 500);
         for (List<CollectTypeNumVO> chunk : chunks) {
             baseMapper.updateCommentNumBatch(chunk);
+            new LambdaUpdateChainWrapper<>(baseMapper)
+                    .in(Video::getId, chunk.stream().map(CollectTypeNumVO::getId).collect(Collectors.toList()))
+                    .set(Video::getCommentNumJob, Boolean.FALSE)
+                    .update();
         }
     }
 
@@ -571,7 +621,7 @@
         video.setAuthorId(UserContext.getCurrentUserId());
         video.setVideoType(VideoTypeEnum.HEALTH.getValue());
         //璁剧疆濉厖妯″紡 淇濇寔姣斾緥锛屽畬鏁存樉绀�
-        video.setVideoFit("contain");
+        video.setVideoFit(form.getVideoFit());
         video.setVideoContentType(VideoContentTypeEnum.VIDEO.getValue());
         video.setStatus(VideoStatusEnum.PUBLISHED.getValue());
         baseMapper.insert(video);
@@ -628,7 +678,7 @@
         video.setAuthorId(UserContext.getCurrentUserId());
         video.setVideoType(VideoTypeEnum.COOK.getValue());
         //璁剧疆濉厖妯″紡 淇濇寔姣斾緥锛屽畬鏁存樉绀�
-        video.setVideoFit("contain");
+        video.setVideoFit(form.getVideoFit());
         video.setVideoContentType(VideoContentTypeEnum.VIDEO.getValue());
         video.setStatus(VideoStatusEnum.PUBLISHED.getValue());
         baseMapper.insert(video);
@@ -707,4 +757,49 @@
                 .eq(KitchenVideoTypeRef::getVideoId, id));
         return Result.ok("鍒犻櫎鎴愬姛");
     }
+
+    /**
+     * mq鎵ц瑙嗛鐨勬敹钘�/鍙栨秷鏀惰棌
+     *
+     * @param collect
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void mqCollectChange(MyCollect collect) {
+        MyCollect myCollect = new LambdaQueryChainWrapper<>(myCollectService.getBaseMapper())
+                .eq(MyCollect::getCollectType, collect.getCollectType())
+                .eq(MyCollect::getRefId, collect.getRefId())
+                .eq(MyCollect::getUserId, collect.getUserId())
+                .one();
+        boolean add = false;
+        if (Objects.nonNull(myCollect)) {
+            myCollectService.removeById(myCollect.getId());
+        } else {
+            myCollectService.save(collect);
+            add = true;
+        }
+        // 澶勭悊缂撳瓨
+        Video video = baseMapper.selectById(collect.getRefId());
+        if (cache.exist(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(collect.getRefId()))) {
+            if (add) {
+                cache.incr(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(collect.getRefId()));
+            } else {
+                cache.decr(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(collect.getRefId()));
+            }
+        } else {
+            if (Objects.nonNull(video)) {
+                cache.put(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(video.getId()),
+                        video.getCollectNum() + (add ? 1 : -1),
+                        RedisKeyExpireConstant.COLLECT_NUM_EXPIRE,
+                        RedisKeyExpireConstant.EXPIRE_DAY);
+            }
+        }
+        // 鏍囪瘑璇ヨ棰戦渶瑕侀�氳繃瀹氭椂浠诲姟缁熻鏀惰棌鏁�
+        if (Objects.nonNull(video) && ! video.getCollectNumJob()) {
+            new LambdaUpdateChainWrapper<>(baseMapper)
+                    .eq(Video::getId, video.getId())
+                    .set(Video::getCollectNumJob, Boolean.TRUE)
+                    .update();
+        }
+    }
 }

--
Gitblit v1.8.0