| | |
| | | package com.ruoyi.article.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.article.controller.forepart.dto.ArticleDTO; |
| | | import com.ruoyi.article.controller.forepart.dto.MemberArticleCollectionDTO; |
| | | import com.ruoyi.article.controller.forepart.vo.MemberArticleCollectionVO; |
| | | import com.ruoyi.article.domain.Article; |
| | | import com.ruoyi.article.domain.MemberArticleCollection; |
| | | import com.ruoyi.article.mapper.ArticleMapper; |
| | | import com.ruoyi.article.mapper.MemberArticleCollectionMapper; |
| | | import com.ruoyi.article.service.IMemberArticleCollectionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class MemberArticleCollectionServiceImpl extends ServiceImpl<MemberArticleCollectionMapper, MemberArticleCollection> implements IMemberArticleCollectionService { |
| | | |
| | | |
| | | @Resource |
| | | private ArticleMapper articleMapper; |
| | | @Resource |
| | | private MemberClient memberClient; |
| | | |
| | | @Override |
| | | public void saveMemberArticleCollection(MemberArticleCollectionDTO memberArticleCollectionDTO) { |
| | | if (memberArticleCollectionDTO.getMemberId()==null) { |
| | | throw new ServiceException("用户ID不能为空"); |
| | | } |
| | | if (memberArticleCollectionDTO.getState()==null) { |
| | | throw new ServiceException("类型不能为空"); |
| | | } |
| | | |
| | | LambdaQueryWrapper< MemberArticleCollection> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(MemberArticleCollection::getMemberId,memberArticleCollectionDTO.getMemberId()); |
| | | wrapper.eq(MemberArticleCollection::getTargetId,memberArticleCollectionDTO.getTargetId()); |
| | | |
| | | if (memberArticleCollectionDTO.getState()==1){ |
| | | List<MemberArticleCollection> list = this.list(wrapper); |
| | | if (list.size()==0){ |
| | | MemberArticleCollection m =new MemberArticleCollection(); |
| | | m.setMemberId(memberArticleCollectionDTO.getMemberId()); |
| | | m.setTargetId(memberArticleCollectionDTO.getTargetId()); |
| | | this.save(m); |
| | | |
| | | Article byId = articleMapper.selectById(memberArticleCollectionDTO.getTargetId()); |
| | | byId.setCollectCount(byId.getCollectCount()+1); |
| | | articleMapper.updateById(byId); |
| | | } |
| | | |
| | | }else{ |
| | | List<MemberArticleCollection> list = this.list(wrapper); |
| | | if (list.size()>0){ |
| | | for (MemberArticleCollection memberArticleCollection:list){ |
| | | Article byId = articleMapper.selectById(memberArticleCollection.getTargetId()); |
| | | byId.setCollectCount(byId.getCollectCount()-1); |
| | | articleMapper.updateById(byId); |
| | | this.removeById(memberArticleCollection); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<MemberArticleCollectionVO> getMemberArticleCollection(ArticleDTO articleDTO) { |
| | | Set<Long> goodsSkuIdList = null; |
| | | if (StringUtils.isNotEmpty(articleDTO.getGoodsSkuName())) { |
| | | LambdaQueryWrapper<Article> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.like(Article::getTitle,articleDTO.getGoodsSkuName()); |
| | | wrapper.eq(Article::getDelFlag,0); |
| | | List<Article> page1 = articleMapper.selectList(wrapper); |
| | | goodsSkuIdList = page1.stream().map(Article::getId) |
| | | .collect(Collectors.toSet()); |
| | | } |
| | | Page<MemberArticleCollection> page = new Page<>(articleDTO.getPageCurr(), articleDTO.getPageSize()); |
| | | LambdaQueryWrapper<MemberArticleCollection> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(MemberArticleCollection::getMemberId,articleDTO.getMemberId()); |
| | | if (StringUtils.isNotEmpty(articleDTO.getGoodsSkuName())){ |
| | | if (goodsSkuIdList.size()>0){ |
| | | wrapper.in(MemberArticleCollection::getTargetId,goodsSkuIdList); |
| | | }else{ |
| | | Set<Long> goodsSkuIdList1 = new HashSet<>(); |
| | | goodsSkuIdList1.add(0L); |
| | | wrapper.in(MemberArticleCollection::getTargetId,goodsSkuIdList1); |
| | | } |
| | | } |
| | | wrapper.eq(MemberArticleCollection::getDelFlag,0); |
| | | wrapper.orderByDesc(MemberArticleCollection::getCreateTime); |
| | | Page<MemberArticleCollection> page1 = this.page(page, wrapper); |
| | | PageDTO<MemberArticleCollectionVO> articleCommentsVOPageDTO = PageDTO.of(page1, MemberArticleCollectionVO.class); |
| | | List<MemberArticleCollectionVO> list2 = articleCommentsVOPageDTO.getList(); |
| | | for (MemberArticleCollectionVO memberArticleCollectionVO:list2){ |
| | | Article byId = articleMapper.selectById(memberArticleCollectionVO.getTargetId()); |
| | | if (Objects.isNull(byId)) { |
| | | continue; |
| | | } |
| | | memberArticleCollectionVO.setContent(byId.getContent()); |
| | | memberArticleCollectionVO.setImages(byId.getImages()); |
| | | memberArticleCollectionVO.setTitle(byId.getTitle()); |
| | | memberArticleCollectionVO.setCreateTime(byId.getCreateTime()); |
| | | memberArticleCollectionVO.setId(byId.getId()); |
| | | R<Member> membeOne = memberClient.getMembeOne(byId.getMemberId(), |
| | | SecurityConstants.INNER); |
| | | Member data = membeOne.getData(); |
| | | if (data!=null){ |
| | | memberArticleCollectionVO.setMemberNickname(data.getNickname()); |
| | | memberArticleCollectionVO.setMemberAvatar(data.getAvatar()); |
| | | }else{ |
| | | memberArticleCollectionVO.setMemberNickname("平台发布"); |
| | | memberArticleCollectionVO.setMemberAvatar("https://jyzx-obs.obs.cn-sccd1.ctyun.cn/d41508d822cb4b7896aaa1bb56e6167f.png"); |
| | | } |
| | | |
| | | memberArticleCollectionVO.setIsCollect(2); |
| | | |
| | | } |
| | | return articleCommentsVOPageDTO; |
| | | } |
| | | } |