From 134f5b1aedeb90b9f7a71dc41e8f08e96bcb3f85 Mon Sep 17 00:00:00 2001 From: peng <peng.com> Date: 星期二, 29 七月 2025 11:46:54 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java | 96 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 74 insertions(+), 22 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..d5cd650 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,17 @@ 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.query.AuthorVideoQuery; import cn.lili.modules.lmk.domain.vo.*; +import cn.lili.modules.lmk.service.VideoService; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.CommentTagsEnum; +import cn.lili.rocketmq.tags.VideoTagsEnum; +import cn.lili.utils.COSUtil; +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,14 +21,21 @@ 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 com.xkcoding.http.util.StringUtil; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; import cn.lili.utils.PageUtil; import org.springframework.beans.BeanUtils; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -34,28 +49,49 @@ 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; + private VideoService videoService; // 绉婚櫎浜唂inal + private COSUtil cOSUtil; + + @Autowired + public void setVideoService(VideoService videoService) { + // 杩欓噷鍙互娣诲姞棰濆鐨勫垵濮嬪寲閫昏緫 + this.videoService = videoService; + } + + /** - * 娣诲姞 + * 鏀惰棌/鍙栨秷鏀惰棌 * @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 +177,8 @@ } @Override - public List<CollectTypeNumVO> countNumGroupByType(String type) { - return baseMapper.countNumGroupByType(type); + public List<CollectTypeNumVO> countNumGroupByVideo() { + return baseMapper.countNumGroupByVideo(); } @@ -160,14 +196,30 @@ activityVO.setUrl(fileService.getPreviewUrl(activityVO.getCover())); } }else if (CollectTypeEnum.video.getType().equals(query.getType())) { - baseMapper.getVideoCollectPage(page, userId); - List<VideoVO> videoList = page.getRecords().stream() - .filter(obj -> obj instanceof VideoVO) - .map(obj -> (VideoVO) obj) + AuthorVideoQuery videoQuery = new AuthorVideoQuery(); + videoQuery.setAuthorId(UserContext.getCurrentUserId()); + videoQuery.setAuthorSelf(true); + videoQuery.setPageSize(query.getPageSize()); + + videoQuery.setPageNumber(query.getPageNumber()); + Result result = videoService.getAuthorCollectVideoPage(videoQuery); + List<WxVideoVO> list = Optional.ofNullable(result.get("data")) + .filter(data -> data instanceof List<?>) + .map(data -> (List<?>) data) + .orElse(Collections.emptyList()) + .stream() + .filter(WxVideoVO.class::isInstance) + .map(WxVideoVO.class::cast) .collect(Collectors.toList()); - for (VideoVO video : videoList) { - video.setCoverUrl(fileService.getPreviewUrl(video.getCoverUrl())); + for (WxVideoVO wxVideoVO : list){ + if (!CollectionUtils.isEmpty(wxVideoVO.getImgs())){ + List<String> newImages = wxVideoVO + .getImgs().stream().map(item -> cOSUtil.getPreviewUrl(item)).collect(Collectors.toList()); + wxVideoVO.setImgs(newImages); + } + } + return result; }else if (CollectTypeEnum.goods.getType().equals(query.getType())) { baseMapper.getGoodsCollectPage(page, userId); -- Gitblit v1.8.0