|
@@ -2,6 +2,7 @@ package com.ruoyi.generator.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
@@ -90,6 +91,11 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
@Autowired
|
|
@Autowired
|
|
private CommunityArticleRecommendMapper recommendMapper;
|
|
private CommunityArticleRecommendMapper recommendMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICommunityArticleService communityArticleService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICommunityPrivacyService communityPrivacyService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询文章列表
|
|
* 查询文章列表
|
|
@@ -603,6 +609,70 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
return communityUserLikeVos;
|
|
return communityUserLikeVos;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param communityArticleComment
|
|
|
|
+ * @throws ParseException
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean checkCommentPermission(CommunityArticleComment communityArticleComment) throws ParseException {
|
|
|
|
+ /**
|
|
|
|
+ * 1.获取文章创建人ID
|
|
|
|
+ * 2.通过文章创建人ID 查询隐私设置表 communityPrivacyService.selectUserPrivacy
|
|
|
|
+ * 3.查询是否开启 只允许我关注的人评论我 有则进入3,没有就返回,
|
|
|
|
+ * 4.获取用户关注列表
|
|
|
|
+ * 5.是否是关注的人评论我 有则评论成功,没有则返回失败
|
|
|
|
+ */
|
|
|
|
+ //获取文章信息 找到文章创建人
|
|
|
|
+ List<CommunityArticle> communityArticles
|
|
|
|
+ = communityArticleMapper
|
|
|
|
+ .selectList(new QueryWrapper<CommunityArticle>().eq("id", communityArticleComment.getArticleId()));
|
|
|
|
+
|
|
|
|
+ // 提取用户ID
|
|
|
|
+ Long articleId = null; // 初始化用户ID
|
|
|
|
+
|
|
|
|
+ if (!communityArticles.isEmpty()) { // 检查列表是否为空
|
|
|
|
+ CommunityArticle article = communityArticles.get(0); // 获取第一个文章
|
|
|
|
+ articleId = article.getUserId(); // 假设CommunityArticle有getUserId()方法
|
|
|
|
+ } else {
|
|
|
|
+ // 处理未找到文章的情况
|
|
|
|
+ // 例如,可以抛出异常或记录日志
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 直接允许作者评论
|
|
|
|
+ if (articleId.equals(SecurityUtils.getLoginUser().getUserId())) {
|
|
|
|
+ /* // 如果评论者是文章作者,直接进行评论
|
|
|
|
+ communityArticleService.sendComment(communityArticleComment);*/
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 1. 查询隐私设置
|
|
|
|
+ List<CommunityUserPrivacyVo> communityUserPrivacyVos = communityPrivacyService.selectUserPrivacy(articleId);
|
|
|
|
+ // 2. 检查隐私设置 只允许我关注的人评论我
|
|
|
|
+ boolean IsComment = false;
|
|
|
|
+ for (CommunityUserPrivacyVo privacyVo : communityUserPrivacyVos) {
|
|
|
|
+ if (privacyVo.getIsComment() != null && privacyVo.getIsComment()) {
|
|
|
|
+ IsComment = true; // 只允许特定用户评论
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 如果评论受限,则查询用户关注列表
|
|
|
|
+ if (IsComment) {
|
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleId);
|
|
|
|
+
|
|
|
|
+ // 3. 检查评论者是否在关注列表中
|
|
|
|
+ boolean isFollower = communityUserLikeVos.stream()
|
|
|
|
+ .anyMatch(like -> like.getUserId().equals(SecurityUtils.getLoginUser().getUserId()));
|
|
|
|
+
|
|
|
|
+ // 如果不是关注者,返回失败
|
|
|
|
+ if (!isFollower) {
|
|
|
|
+ //return AjaxResult.error("您没有权限评论此文章,因为只允许关注的人评论您!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|