From e59e26244b2a07b9d8360551cbab75c6fd8a1248 Mon Sep 17 00:00:00 2001 From: rentaiming <806181062@qq.com> Date: 星期五, 31 五月 2024 15:15:21 +0800 Subject: [PATCH] 修改循环注入 --- ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/MemberLikeServiceImpl.java | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/MemberLikeServiceImpl.java b/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/MemberLikeServiceImpl.java index 8c2ee66..da9f9e8 100644 --- a/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/MemberLikeServiceImpl.java +++ b/ruoyi-modules/ruoyi-article/src/main/java/com/ruoyi/article/service/impl/MemberLikeServiceImpl.java @@ -8,6 +8,7 @@ import com.ruoyi.article.domain.ArticleComments; import com.ruoyi.article.domain.MemberLike; import com.ruoyi.article.dto.MemberLikeDTO; +import com.ruoyi.article.mapper.ArticleMapper; import com.ruoyi.article.mapper.MemberLikeMapper; import com.ruoyi.article.service.IArticleCommentsService; import com.ruoyi.article.service.IArticleService; @@ -31,9 +32,7 @@ IMemberLikeService { @Resource - private IMemberLikeService memberLikeService; - @Resource - private IArticleService articleService; + private ArticleMapper articleMapper; @Resource private IArticleCommentsService articleCommentsService; @@ -52,16 +51,16 @@ wrapper.eq(MemberLike::getType,memberLikeDTO.getType()); wrapper.eq( MemberLike::getDelFlag,0); if (memberLikeDTO.getState()==1){ - List< MemberLike> memberLikes = memberLikeService.list(wrapper); + List< MemberLike> memberLikes = this.list(wrapper); if (memberLikes.size()==0){ MemberLike memberLike=new MemberLike(); memberLike.setMemberId(memberLikeDTO.getMemberId()); memberLike.setArticleId(memberLikeDTO.getArticleId()); memberLike.setType(memberLikeDTO.getType()); if (memberLikeDTO.getType()==1){ - Article byId = articleService.getById(memberLikeDTO.getArticleId()); + Article byId = articleMapper.selectById(memberLikeDTO.getArticleId()); byId.setLikeCount(byId.getLikeCount()+1); - articleService.saveOrUpdate(byId); + articleMapper.updateById(byId); } if (memberLikeDTO.getType()==2){ ArticleComments byId = articleCommentsService.getById(memberLikeDTO.getArticleId()); @@ -73,18 +72,18 @@ byId.setLikeCount(byId.getLikeCount()+1); articleCommentsService.saveOrUpdate(byId); } - memberLikeService.save(memberLike); + this.save(memberLike); } }else{ - List< MemberLike> memberLikes = memberLikeService.list(wrapper); + List< MemberLike> memberLikes = this.list(wrapper); if (memberLikes.size()>0){ for (MemberLike memberLike:memberLikes){ - memberLikeService.removeById(memberLike); + this.removeById(memberLike); if (memberLikeDTO.getType()==1){ - Article byId = articleService.getById(memberLikeDTO.getArticleId()); + Article byId = articleMapper.selectById(memberLikeDTO.getArticleId()); byId.setLikeCount(byId.getLikeCount()-1); - articleService.saveOrUpdate(byId); + articleMapper.updateById(byId); } if (memberLikeDTO.getType()==2){ ArticleComments byId = articleCommentsService.getById(memberLikeDTO.getArticleId()); -- Gitblit v1.7.1