rentaiming
2024-05-31 e59e26244b2a07b9d8360551cbab75c6fd8a1248
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.ruoyi.article.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.article.domain.Article;
import com.ruoyi.article.domain.ArticleComments;
import com.ruoyi.article.dto.ArticleCommentsDTO;
import com.ruoyi.article.mapper.ArticleCommentsMapper;
import com.ruoyi.article.mapper.ArticleMapper;
import com.ruoyi.article.service.IArticleCommentsService;
import com.ruoyi.article.service.IArticleService;
import com.ruoyi.common.core.exception.ServiceException;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 资讯评论回复表 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Service
public class ArticleCommentsServiceImpl extends
        ServiceImpl<ArticleCommentsMapper, ArticleComments> implements IArticleCommentsService {
 
    @Resource
    private ArticleMapper articleMapper;
 
    @Override
    public void saveMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) {
        ArticleComments articleComments=new ArticleComments();
        if (articleCommentsDTO.getId()!=null){
            articleComments=  this.getById(articleCommentsDTO.getId());
        }
        if (articleCommentsDTO.getMemberId()==null){
            throw new ServiceException("用户id错误");
        }
        if (articleCommentsDTO.getType()==1){
            articleComments.setMemberId(articleCommentsDTO.getMemberId());
            articleComments.setArticleId(articleCommentsDTO.getArticleId());
            articleComments.setContent(articleCommentsDTO.getContent());
            articleComments.setType(1);
        }else{
            articleComments.setMemberId(articleCommentsDTO.getMemberId());
            articleComments.setArticleId(articleCommentsDTO.getArticleId());
            articleComments.setReplyId(articleCommentsDTO.getReplyId());
            articleComments.setContent(articleCommentsDTO.getContent());
            articleComments.setBmemberId(articleCommentsDTO.getBmemberId());
            articleComments.setType(2);
        }
        Article byId = articleMapper.selectById(articleCommentsDTO.getArticleId());
        byId.setCommentCount(byId.getCommentCount()+1);
        articleMapper.updateById(byId);
        this.saveOrUpdate(articleComments);
    }
 
    @Override
    public void delMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) {
        ArticleComments byId1 = this.getById(articleCommentsDTO.getId());
 
        Article byId = articleMapper.selectById(byId1.getArticleId());
        byId.setCommentCount(byId.getCommentCount()-1);
        articleMapper.updateById(byId);
 
        this.removeById(articleCommentsDTO.getId());
    }
}