| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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()); |
| | | // 视频收藏走mq |
| | | 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("操作成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<CollectTypeNumVO> countNumGroupByType(String type) { |
| | | return baseMapper.countNumGroupByType(type); |
| | | public List<CollectTypeNumVO> countNumGroupByVideo() { |
| | | return baseMapper.countNumGroupByVideo(); |
| | | } |
| | | |
| | | |