Bladeren bron

1.文章评价回复功能开发完毕
2.文章推荐值功能开发完毕
3.修改文章获取,拆开评价,单独做接口
4.修复若干bug问题

fangzhen 7 maanden geleden
bovenliggende
commit
544c4eb11b
17 gewijzigde bestanden met toevoegingen van 513 en 69 verwijderingen
  1. 55 18
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java
  2. 169 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java
  3. 2 2
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java
  4. 5 2
      ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleComment.java
  5. 62 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleRecommend.java
  6. 80 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityCommentReply.java
  7. 7 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityArticleRecommendMapper.java
  8. 7 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityCommentReplyMapper.java
  9. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleCommentServiceImpl.java
  10. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleRecommendServiceImpl.java
  11. 42 21
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java
  12. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCommentReplyServiceImpl.java
  13. 7 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleCommentService.java
  14. 7 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleRecommendService.java
  15. 7 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityCommentReplyService.java
  16. 6 2
      ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityArticleVo.java
  17. 24 24
      ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

+ 55 - 18
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
+import com.ruoyi.generator.service.ICommunityArticleRecommendService;
 import com.ruoyi.generator.service.ICommunityArticleService;
 import com.ruoyi.generator.service.ICommunityCollectionService;
 import com.ruoyi.generator.vo.CommunityArticleVo;
@@ -64,6 +65,9 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private ICommunityCollectionService communityCollectionService;
 
+    @Autowired
+    private ICommunityArticleRecommendService communityArticleRecommendService;
+
     /**
      * 获取文章列表信息
      */
@@ -127,36 +131,24 @@ public class CommunityArticleController extends BaseController {
         if (null == communityArticleComment.getArticleId()) {
             return AjaxResult.error("文章不存在或异常!");
         }
-
-        if (null == communityArticleComment.getUserId()) {
-            return AjaxResult.error("用户不存在或异常!");
-        }
-
+        communityArticleComment.setUserId(SecurityUtils.getUserId());
         //新增评论
         communityArticleService.sendComment(communityArticleComment);
-
         return AjaxResult.success();
     }
 
-    @ApiOperation("文章评价")
+    @ApiOperation("删除文章评价")
     @DeleteMapping("/comment")
     @Transactional
     public AjaxResult deleteComment(@RequestBody CommunityArticleComment communityArticleComment) {
-//        if (null == communityArticleComment.getArticleId()) {
-//            return AjaxResult.error("文章不存在或异常!");
-//        }
-
-        if (null == communityArticleComment.getUserId()) {
-            return AjaxResult.error("用户不存在或异常!");
-        }
+        //获取评论信息
+        CommunityArticleComment articleComment = communityArticleCommentMapper.selectById(communityArticleComment.getId());
 
-        if (!SecurityUtils.getUserId().equals(communityArticleComment.getUserId())) {
+        if (!articleComment.getCreateBy().equals(SecurityUtils.getUserId())) {
             return AjaxResult.error("不允许删除别人的评论!");
         }
-
         //删除评论
-        communityArticleService.deleteComment(communityArticleComment);
-
+        communityArticleService.deleteComment(articleComment);
         return AjaxResult.success();
     }
 
@@ -195,6 +187,51 @@ public class CommunityArticleController extends BaseController {
         return AjaxResult.success(message);
     }
 
+    /**
+     * 文章推荐值
+     */
+    @ApiOperation("新增/取消推荐值")
+    @PostMapping("/recommend")
+    @Transactional
+    //@Anonymous
+    public AjaxResult recommend(@RequestBody CommunityArticleRecommend articleRecommend) {
+        if (Objects.isNull(articleRecommend.getArticleId())) {
+            return AjaxResult.error("参数异常!");
+        }
+        boolean isSuccess = true;
+        String message = "";
+        Long userId = SecurityUtils.getUserId();
+        CommunityArticleRecommend recommend = communityArticleRecommendService.getOne(new QueryWrapper<CommunityArticleRecommend>()
+                .eq("article_id", articleRecommend.getArticleId())
+                .eq("user_id", userId).and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                }));
+        if (Objects.isNull(recommend)) {
+            //新增推荐值
+            recommend = new CommunityArticleRecommend();
+            recommend.setArticleId(articleRecommend.getArticleId());
+            recommend.setCreateBy(userId);
+            recommend.setUserId(userId);
+            recommend.setDelete(false);
+            recommend.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            isSuccess = communityArticleRecommendService.save(recommend);
+            message = "感谢推荐";
+        } else {
+            //删除点赞
+            recommend.setDelete(true);
+            recommend.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            recommend.setUpdateBy(userId);
+            isSuccess = communityArticleRecommendService.updateById(recommend);
+            message = "取消推荐";
+        }
+
+        if (!isSuccess) {
+            message = "操作失败!";
+            return AjaxResult.error(message);
+        }
+        return AjaxResult.success(message);
+    }
+
 
     /**
      * 获取文章列表信息

+ 169 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -0,0 +1,169 @@
+package com.ruoyi.generator.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.generator.domain.Community.CommunityArticleComment;
+import com.ruoyi.generator.domain.Community.CommunityCommentLike;
+import com.ruoyi.generator.domain.Community.CommunityCommentReply;
+import com.ruoyi.generator.mapper.community.CommunityCommentLikeMapper;
+import com.ruoyi.generator.service.ICommunityArticleCommentService;
+import com.ruoyi.generator.service.ICommunityCommentReplyService;
+import com.ruoyi.generator.vo.CommunityArticleCommentVo;
+import com.ruoyi.system.mapper.SysUserMapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 评论接口
+ *
+ * @author fangzhen
+ */
+@Api(tags = "评论接口")
+@RestController
+@RequestMapping("/community/comment")
+public class CommunityCommentController extends BaseController {
+
+    @Autowired
+    private ICommunityCommentReplyService communityCommentReplyService;
+
+    @Autowired
+    private ICommunityArticleCommentService communityArticleCommentService;
+
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private CommunityCommentLikeMapper communityCommentLikeMapper;
+
+
+    /**
+     * 获取文章评论
+     */
+    @ApiOperation("获取文章评论")
+    @GetMapping()
+    @Transactional
+    //@Anonymous
+    public AjaxResult comment(String articleId, int currentPage, int limit) {
+        if (Objects.isNull(articleId)) {
+            return AjaxResult.error("参数异常!");
+        }
+        Page<CommunityArticleComment> page = new Page<>(currentPage, limit);
+        List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>()
+                .eq("article_id", articleId).and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                }).orderByDesc("create_time")).getRecords();
+
+        CommunityArticleCommentVo commentVo = null;
+        List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
+        for (CommunityArticleComment record : records) {
+            commentVo = new CommunityArticleCommentVo();
+            BeanUtils.copyProperties(record, commentVo);
+            commentVos.add(commentVo);
+        }
+
+        Long userId = SecurityUtils.getUserId();
+        for (CommunityArticleCommentVo vo : commentVos) {
+            Long commentUserId = vo.getUserId();
+            //获取评论的用户信息
+            SysUser sysUser = sysUserMapper.selectUserById(commentUserId);
+            vo.setUsername(sysUser.getUserName());
+            vo.setAvatar(sysUser.getAvatar());
+            //当前登录用户是否已点赞
+            List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                    .eq("comment_id", vo.getId())
+                    .eq("user_id", userId));
+            vo.setCommentLike(!commentLikes.isEmpty());
+
+            //该评论的点赞数量
+            vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
+        }
+
+        return AjaxResult.success(commentVos);
+    }
+
+    /**
+     * 获取评论回复
+     */
+    @ApiOperation("获取评论回复")
+    @GetMapping("/reply")
+    @Transactional
+    //@Anonymous
+    public AjaxResult reply(String commentId, int currentPage, int limit) {
+        if (Objects.isNull(commentId)) {
+            return AjaxResult.error("参数异常!");
+        }
+        Page<CommunityCommentReply> page = new Page<>(currentPage, limit);
+        List<CommunityCommentReply> replies = communityCommentReplyService
+                .page(page, new QueryWrapper<CommunityCommentReply>()
+                        .eq("comment_id", commentId).and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        })
+                        .orderByDesc("create_time")).getRecords();
+        return AjaxResult.success(replies);
+    }
+
+
+    /**
+     * 对文章评论进行回复
+     */
+    @ApiOperation("对文章评论进行回复")
+    @PostMapping("/reply")
+    @Transactional
+    //@Anonymous
+    public AjaxResult reply(@RequestBody CommunityCommentReply communityCommentReply) {
+        if (Objects.isNull(communityCommentReply.getCommentId())
+                || Objects.isNull(communityCommentReply.getContent())) {
+            return AjaxResult.error("参数异常!");
+        }
+
+        Long userId = SecurityUtils.getUserId();
+        communityCommentReply.setUserId(userId);
+        communityCommentReply.setDelete(false);
+        communityCommentReply.setCreateBy(userId);
+        communityCommentReply.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityCommentReplyService.save(communityCommentReply);
+        return AjaxResult.success("新增回复成功!");
+    }
+
+    /**
+     * 删除回复
+     */
+    @ApiOperation("删除回复")
+    @DeleteMapping("/deleteReply")
+    @Transactional
+    //@Anonymous
+    public AjaxResult deleteReply(String replyId) {
+        if (Objects.isNull(replyId)) {
+            return AjaxResult.error("参数异常!");
+        }
+
+        CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>()
+                .eq("id", replyId)
+                .and((wrapper) -> {
+            wrapper.ne("is_delete", true).or().isNull("is_delete");
+        }));
+        if (Objects.isNull(communityCommentReply)) {
+            return AjaxResult.error("未找到该回复!");
+        }
+
+        Long userId = SecurityUtils.getUserId();
+        communityCommentReply.setDelete(true);
+        communityCommentReply.setUpdateBy(userId);
+        communityCommentReply.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityCommentReplyService.updateById(communityCommentReply);
+        return AjaxResult.success("删除回复成功!");
+    }
+}

+ 2 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java

@@ -47,8 +47,8 @@ public class CommunityTagController extends BaseController {
     @GetMapping()
     @Transactional
     //@Anonymous
-    public AjaxResult tags(String tagName, int currentPage, int limit) {
-        Page<CommunityTag> page = new Page<>(currentPage, limit);
+    public AjaxResult tags(String tagName) {
+        Page<CommunityTag> page = new Page<>(1, 20);
         List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
                     wrapper.ne("is_delete", 1)
                             .or()

+ 5 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleComment.java

@@ -50,16 +50,19 @@ public class CommunityArticleComment implements Serializable {
     private String content;
 
     /** 创建者 */
-    private String createBy;
+    private Long createBy;
 
     /** 创建时间 */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
     /** 更新者 */
-    private String updateBy;
+    private Long updateBy;
 
     /** 更新时间 */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updateTime;
+
+    /** 是否删除 */
+    private boolean isDelete;
 }

+ 62 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleRecommend.java

@@ -0,0 +1,62 @@
+package com.ruoyi.generator.domain.Community;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+* 文章推荐记录表
+* @TableName community_article_recommend
+*/
+@TableName("community_article_recommend")
+@Data
+public class CommunityArticleRecommend implements Serializable {
+
+    /**
+    * 唯一id
+    */
+    @NotNull(message="[唯一id]不能为空")
+    @ApiModelProperty("唯一id")
+    @TableId("id")
+    private Long id;
+    /**
+    * 文章id
+    */
+    @ApiModelProperty("文章id")
+    private Long articleId;
+    /**
+    * 推荐者id
+    */
+    @ApiModelProperty("推荐者id")
+    private Long userId;
+    /**
+    * 创建人
+    */
+    @ApiModelProperty("创建人")
+    private Long createBy;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+    /**
+    * 更新人
+    */
+    @ApiModelProperty("更新人")
+    private Long updateBy;
+    /**
+    * 更新时间
+    */
+    @ApiModelProperty("更新时间")
+    private Date updateTime;
+    /**
+    * 是否删除
+    */
+    @ApiModelProperty("是否删除")
+    private boolean isDelete;
+}

+ 80 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityCommentReply.java

@@ -0,0 +1,80 @@
+package com.ruoyi.generator.domain.Community;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.hibernate.validator.constraints.Length;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+* 文章评论回复表
+* @TableName community_comment_reply
+*/
+@Data
+@TableName("community_comment_reply")
+public class CommunityCommentReply implements Serializable {
+
+    /**
+    * 唯一id
+    */
+    @NotNull(message="[唯一id]不能为空")
+    @ApiModelProperty("唯一id")
+    @TableId("id")
+    private Long id;
+    /**
+    * 评论id
+    */
+    @ApiModelProperty("评论id")
+    private Long commentId;
+    /**
+    * 父回复id
+    */
+    @ApiModelProperty("父回复id")
+    private Long parentReplyId;
+    /**
+    * 回复用户id
+    */
+    @ApiModelProperty("回复用户id")
+    private Long userId;
+    /**
+    * 回复内容
+    */
+    @Size(max= -1,message="编码长度不能超过-1")
+    @ApiModelProperty("回复内容")
+    @Length(max= -1,message="编码长度不能超过-1")
+    private String content;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    /**
+    * 创建人
+    */
+    @ApiModelProperty("创建人")
+    private Long createBy;
+    /**
+    * 更新时间
+    */
+    @ApiModelProperty("更新时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+    /**
+    * 更新人
+    */
+    @ApiModelProperty("更新人")
+    private Long updateBy;
+
+    /**
+     * 是否删除
+     */
+    @ApiModelProperty("是否删除")
+    private boolean isDelete;
+}

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityArticleRecommendMapper.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.mapper.community;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.generator.domain.Community.CommunityArticleRecommend;
+
+public interface CommunityArticleRecommendMapper extends BaseMapper<CommunityArticleRecommend> {
+}

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityCommentReplyMapper.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.mapper.community;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.generator.domain.Community.CommunityCommentReply;
+
+public interface CommunityCommentReplyMapper extends BaseMapper<CommunityCommentReply> {
+}

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleCommentServiceImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleComment;
+import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleCommentServiceImpl extends ServiceImpl<CommunityArticleCommentMapper, CommunityArticleComment> implements ICommunityArticleCommentService {
+
+}

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleRecommendServiceImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleRecommend;
+import com.ruoyi.generator.mapper.community.CommunityArticleRecommendMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleRecommendServiceImpl extends ServiceImpl<CommunityArticleRecommendMapper, CommunityArticleRecommend> implements ICommunityArticleRecommendService {
+
+}

+ 42 - 21
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -90,6 +90,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Autowired
     private CommunityTagBlockMapper communityTagBlockMapper;
 
+    @Autowired
+    private CommunityArticleRecommendMapper recommendMapper;
+
     /**
      * 查询文章列表
      *
@@ -156,27 +159,33 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
             //设置文章的点赞数量
             articleVo.setLikeCount(communityLikeMapper.selectList(new QueryWrapper<CommunityLike>().eq("article_id", articleVo.getId())).size());
-
+            //设置文章的收藏数量
             articleVo.setCollectCount(communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>().eq("article_id", articleVo.getId())).size());
+            //设置文章推荐数量
+            articleVo.setRecommendCount(recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>()
+                    .eq("article_id", articleVo.getId())
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })).size());
 
             //文章下的评论
-            List<Map<String, Object>> comments = articleVo.getComments();
-            for (Map<String, Object> communityArticleCommentVo : comments) {
-                String commentUserId = communityArticleCommentVo.get("userId").toString();
-                if (Objects.isNull(commentUserId)) {
-                    break;
-                }
-                //获取评论的用户信息
-                SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(commentUserId));
-                communityArticleCommentVo.put("username", sysUser.getUserName());
-                communityArticleCommentVo.put("avatar", sysUser.getAvatar());
-                //当前登录用户是否已点赞
-                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id")).eq("user_id", userId));
-                communityArticleCommentVo.put("commentLike", !commentLikes.isEmpty());
-
-                //该评论的点赞数量
-                communityArticleCommentVo.put("commentLikeCount", communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id"))).size());
-            }
+//            List<Map<String, Object>> comments = articleVo.getComments();
+//            for (Map<String, Object> communityArticleCommentVo : comments) {
+//                String commentUserId = communityArticleCommentVo.get("userId").toString();
+//                if (Objects.isNull(commentUserId)) {
+//                    break;
+//                }
+//                //获取评论的用户信息
+//                SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(commentUserId));
+//                communityArticleCommentVo.put("username", sysUser.getUserName());
+//                communityArticleCommentVo.put("avatar", sysUser.getAvatar());
+//                //当前登录用户是否已点赞
+//                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id")).eq("user_id", userId));
+//                communityArticleCommentVo.put("commentLike", !commentLikes.isEmpty());
+//
+//                //该评论的点赞数量
+//                communityArticleCommentVo.put("commentLikeCount", communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id"))).size());
+//            }
 
             //判断是否已收藏
             CommunityArticleCollect collect = communityCollectMapper.selectOne(new QueryWrapper<CommunityArticleCollect>().eq("user_id", userId).eq("article_id", articleVo.getId()));
@@ -186,6 +195,14 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             CommunityLike like = communityLikeMapper.selectOne(new QueryWrapper<CommunityLike>().eq("user_id", userId).eq("article_id", articleVo.getId()));
             articleVo.setLike(!Objects.isNull(like));
 
+            //判断是否已推荐
+            CommunityArticleRecommend recommend = recommendMapper.selectOne(new QueryWrapper<CommunityArticleRecommend>()
+                    .eq("user_id", userId)
+                    .eq("article_id", articleVo.getId()).and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }));
+            articleVo.setRecommend(!Objects.isNull(recommend));
+
             //获取文章标签
             List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>().eq("article_id", articleVo.getId()));
             List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
@@ -303,10 +320,11 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Override
     public void sendComment(CommunityArticleComment communityArticleComment) throws ParseException {
         communityArticleComment.setId(null);
-        communityArticleComment.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
-        communityArticleComment.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
+        communityArticleComment.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+        communityArticleComment.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
         communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticleComment.setDelete(false);
         communityArticleCommentMapper.insert(communityArticleComment);
     }
 
@@ -317,7 +335,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      */
     @Override
     public void deleteComment(CommunityArticleComment communityArticleComment) {
-        communityArticleCommentMapper.deleteById(communityArticleComment);
+        communityArticleComment.setDelete(true);
+        communityArticleComment.setUpdateBy(SecurityUtils.getUserId());
+        communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticleCommentMapper.updateById(communityArticleComment);
     }
 
 

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCommentReplyServiceImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityCommentReply;
+import com.ruoyi.generator.mapper.community.CommunityCommentReplyMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityCommentReplyServiceImpl extends ServiceImpl<CommunityCommentReplyMapper, CommunityCommentReply> implements ICommunityCommentReplyService {
+
+}

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleCommentService.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityArticleComment;
+
+public interface ICommunityArticleCommentService extends IService<CommunityArticleComment> {
+}

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleRecommendService.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityArticleRecommend;
+
+public interface ICommunityArticleRecommendService extends IService<CommunityArticleRecommend> {
+}

+ 7 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityCommentReplyService.java

@@ -0,0 +1,7 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityCommentReply;
+
+public interface ICommunityCommentReplyService extends IService<CommunityCommentReply> {
+}

+ 6 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityArticleVo.java

@@ -1,11 +1,9 @@
 package com.ruoyi.generator.vo;
 
 import com.baomidou.mybatisplus.annotation.TableField;
-import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.ruoyi.common.core.domain.BaseEntity;
-import com.ruoyi.generator.domain.Community.CommunityArticleCircle;
 import com.ruoyi.generator.domain.Community.CommunityArticleImages;
 import com.ruoyi.generator.domain.Community.CommunityTag;
 import io.swagger.annotations.ApiModel;
@@ -67,6 +65,12 @@ public class CommunityArticleVo extends BaseEntity implements Serializable {
     @ApiModelProperty("点赞个数")
     private int likeCount;
 
+    @ApiModelProperty("是否已推荐")
+    private boolean isRecommend;
+
+    @ApiModelProperty("推荐个数")
+    private int recommendCount;
+
     @ApiModelProperty("收藏个数")
     private int collectCount;
 

+ 24 - 24
ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

@@ -133,30 +133,30 @@
         c.user_name as user_name,
         c.nick_name as nick_name,
         c.email as email,
-        c.avatar as avatar,
-        COALESCE((
-        SELECT
-        JSON_ARRAYAGG(
-        CASE
-        WHEN d.id IS NOT NULL THEN
-        JSON_OBJECT(
-        'id', IFNULL(d.id,''),
-        'articleId', IFNULL(d.article_id,''),
-        'userId', IFNULL(d.user_id,''),
-        'content', IFNULL(d.content,''),
-        'createBy', IFNULL(d.create_by,''),
-        'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
-        'updateBy', IFNULL(d.update_by,''),
-        'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
-        )
-        ELSE NULL
-        END
-        )
-        FROM
-        community_article_comment d
-        WHERE
-        d.article_id = a.id
-        ), '[]') AS comments
+        c.avatar as avatar
+#         COALESCE((
+#         SELECT
+#         JSON_ARRAYAGG(
+#         CASE
+#         WHEN d.id IS NOT NULL THEN
+#         JSON_OBJECT(
+#         'id', IFNULL(d.id,''),
+#         'articleId', IFNULL(d.article_id,''),
+#         'userId', IFNULL(d.user_id,''),
+#         'content', IFNULL(d.content,''),
+#         'createBy', IFNULL(d.create_by,''),
+#         'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
+#         'updateBy', IFNULL(d.update_by,''),
+#         'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
+#         )
+#         ELSE NULL
+#         END
+#         )
+#         FROM
+#         community_article_comment d
+#         WHERE
+#         d.article_id = a.id and d.is_delete != 1 order by d.create_time desc
+#         ), '[]') AS comments
         from
         community_article a
         left join sys_user c on a.user_id = c.user_id