From c8a21748f87bc0a23744d9fee5dec3eaaa403fdc Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期二, 11 六月 2024 18:59:51 +0800 Subject: [PATCH] 1.提交【管理后台】-资讯管理相关接口 --- ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/ArticleCommentsServiceImpl.java | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/ArticleCommentsServiceImpl.java b/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/ArticleCommentsServiceImpl.java index 4c53c83..ba9e375 100644 --- a/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/ArticleCommentsServiceImpl.java +++ b/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/ArticleCommentsServiceImpl.java @@ -1,9 +1,11 @@ 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.controller.forepart.dto.ArticleCommentsDTO; import com.ruoyi.article.mapper.ArticleCommentsMapper; +import com.ruoyi.article.mapper.ArticleMapper; import com.ruoyi.article.service.IArticleCommentsService; import com.ruoyi.common.core.exception.ServiceException; import org.springframework.stereotype.Service; @@ -21,14 +23,15 @@ @Service public class ArticleCommentsServiceImpl extends ServiceImpl<ArticleCommentsMapper, ArticleComments> implements IArticleCommentsService { + @Resource - private IArticleCommentsService articleCommentsService; + private ArticleMapper articleMapper; @Override public void saveMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) { ArticleComments articleComments=new ArticleComments(); if (articleCommentsDTO.getId()!=null){ - articleComments= articleCommentsService.getById(articleCommentsDTO.getId()); + articleComments= this.getById(articleCommentsDTO.getId()); } if (articleCommentsDTO.getMemberId()==null){ throw new ServiceException("用户id错误"); @@ -46,11 +49,20 @@ articleComments.setBmemberId(articleCommentsDTO.getBmemberId()); articleComments.setType(2); } - articleCommentsService.saveOrUpdate(articleComments); + Article byId = articleMapper.selectById(articleCommentsDTO.getArticleId()); + byId.setCommentCount(byId.getCommentCount()+1); + articleMapper.updateById(byId); + this.saveOrUpdate(articleComments); } @Override public void delMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) { - articleCommentsService.removeById(articleCommentsDTO.getId()); + ArticleComments byId1 = this.getById(articleCommentsDTO.getId()); + + Article byId = articleMapper.selectById(byId1.getArticleId()); + byId.setCommentCount(byId.getCommentCount()-1); + articleMapper.updateById(byId); + + this.removeById(articleCommentsDTO.getId()); } } -- Gitblit v1.7.1