瀏覽代碼

发布文章,评论,回复接口,新增@功能

fangqing 3 月之前
父節點
當前提交
cc998b544c

+ 30 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -326,7 +326,36 @@ public class CommunityCommentController extends BaseController {
             }
             communityCommentReply.setAddress(address);
             communityCommentReplyService.save(communityCommentReply);
+
+            //拿到需要At人的ID
+            List<Long> atUserIds = communityCommentReply.getAtUserIds();
+            if (atUserIds != null && !atUserIds.isEmpty()) {
+                List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+                CommunityArticleAt communityArticleAt = null;
+                for (Long atUserId : atUserIds) {
+                    communityArticleAt = new CommunityArticleAt();
+                    communityArticleAt.setType(2L);
+
+                    //获取文章ID
+                    CommunityArticleComment communityArticleComment = communityArticleCommentMapper.selectOne(new QueryWrapper<CommunityArticleComment>()
+                            .eq("id", communityCommentReply.getCommentId())
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+                    communityArticleAt.setArticleId(communityArticleComment.getArticleId());
+                    communityArticleAt.setCommentId(communityCommentReply.getCommentId());
+                    communityArticleAt.setReplyId(communityCommentReply.getId());
+                    communityArticleAt.setUserId(SecurityUtils.getLoginUser().getUserId());
+                    communityArticleAt.setPeerId(atUserId);
+                    communityArticleAt.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+                    communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityArticleAts.add(communityArticleAt);
+                }
+                communityArticleAtService.saveBatch(communityArticleAts);
+            }
+
         } catch (Exception e) {
+           // e.printStackTrace();
             System.out.println(e.getMessage());
             throw new ProjectException();
         }
@@ -468,7 +497,7 @@ public class CommunityCommentController extends BaseController {
                 }
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            //e.printStackTrace();
             System.out.println(e.getMessage());
             throw new ProjectException();
         }

+ 8 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticleComment.java

@@ -1,5 +1,6 @@
 package com.ruoyi.generator.domain.Community;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -13,6 +14,7 @@ import lombok.NoArgsConstructor;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 文章评价记录表
@@ -95,5 +97,10 @@ public class CommunityArticleComment implements Serializable {
     @ApiModelProperty("用户地址")
     private String address;
 
-
+    /**
+     * 父文章id(编辑文章,草稿箱来源)
+     */
+    @ApiModelProperty("文章at")
+    @TableField(exist = false)
+    private List<Long> atUserIds;
 }

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

@@ -1,5 +1,6 @@
 package com.ruoyi.generator.domain.Community;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -13,6 +14,7 @@ import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
 * 文章评论回复表
@@ -101,4 +103,11 @@ public class CommunityCommentReply implements Serializable {
     @ApiModelProperty("用户地址")
     private String address;
 
+    /**
+     * 父文章id(编辑文章,草稿箱来源)
+     */
+    @ApiModelProperty("文章at")
+    @TableField(exist = false)
+    private List<Long> atUserIds;
+
 }

+ 68 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -131,6 +131,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Autowired
     private RedisTemplate<Object, Object> redisTemplate;
 
+    @Autowired
+    private ICommunityArticleAtService communityArticleAtService;
+
     /**
      * 查询文章列表
      *
@@ -748,6 +751,29 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             collectionArticleService.saveBatch(collectionArticles);
         }
 
+
+        // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
+        if (!communityArticle.getIsDraft()) {
+            //拿到需要At人的ID
+            List<Long> atUserIds = communityArticle.getAtUserIds();
+
+            if (atUserIds != null && !atUserIds.isEmpty()) {
+                List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+                CommunityArticleAt communityArticleAt = null;
+                for (Long atUserId : atUserIds) {
+                    communityArticleAt = new CommunityArticleAt();
+                    communityArticleAt.setType(0L);
+                    communityArticleAt.setArticleId(communityArticle.getId());
+                    communityArticleAt.setUserId(userId);
+                    communityArticleAt.setPeerId(atUserId);
+                    communityArticleAt.setCreateBy(userId);
+                    communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityArticleAts.add(communityArticleAt);
+                }
+                communityArticleAtService.saveBatch(communityArticleAts);
+            }
+        }
+
     }
 
 
@@ -882,7 +908,6 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         //插入合集
         List<String> collectionIds = communityArticle.getCollectionIds();
 
-
         if (collectionIds != null && !collectionIds.isEmpty()) {
             //插入合集 都失效
             collectionArticleService.update(
@@ -909,6 +934,29 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             collectionArticleService.saveBatch(collectionArticles);
         }
 
+
+        // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
+        if (!communityArticle.getIsDraft()) {
+            //拿到需要At人的ID
+            List<Long> atUserIds = communityArticle.getAtUserIds();
+
+            if (atUserIds != null && !atUserIds.isEmpty()) {
+                List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+                CommunityArticleAt communityArticleAt = null;
+                for (Long atUserId : atUserIds) {
+                    communityArticleAt = new CommunityArticleAt();
+                    communityArticleAt.setType(0L);
+                    communityArticleAt.setArticleId(communityArticle.getId());
+                    communityArticleAt.setUserId(userId);
+                    communityArticleAt.setPeerId(atUserId);
+                    communityArticleAt.setCreateBy(userId);
+                    communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityArticleAts.add(communityArticleAt);
+                }
+                communityArticleAtService.saveBatch(communityArticleAts);
+            }
+        }
+
     }
 
     /**
@@ -934,8 +982,26 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         }
 
         communityArticleComment.setAddress(address);
-
         communityArticleCommentMapper.insert(communityArticleComment);
+
+        //拿到需要At人的ID
+        List<Long> atUserIds = communityArticleComment.getAtUserIds();
+        if (atUserIds != null && !atUserIds.isEmpty()) {
+            List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+            CommunityArticleAt communityArticleAt = null;
+            for (Long atUserId : atUserIds) {
+                communityArticleAt = new CommunityArticleAt();
+                communityArticleAt.setType(1L);
+                communityArticleAt.setArticleId(communityArticleComment.getArticleId());
+                communityArticleAt.setCommentId(communityArticleComment.getId());
+                communityArticleAt.setUserId(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setPeerId(atUserId);
+                communityArticleAt.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityArticleAts.add(communityArticleAt);
+            }
+            communityArticleAtService.saveBatch(communityArticleAts);
+        }
     }
 
     /**