Sfoglia il codice sorgente

1.修复用户点击喜欢的文章后, 该文章要是被删除, 则获取用户喜欢文章的列表会报错的问题

fangzhen 2 giorni fa
parent
commit
9fd64e109e

+ 6 - 6
ruoyi-admin/src/main/resources/application-druid.yml

@@ -6,12 +6,12 @@ spring:
         druid:
             # 主库数据源  47.122.10.161 121.4.140.159
             master:
-                url: jdbc:mysql://121.4.140.159:3307/ruoyi-community?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-                username: root
-                password: fangzhen,7410
-#                url: jdbc:mysql://rm-bp12v02802jkd05j89o.mysql.rds.aliyuncs.com:3306/ruoyi-community_backup?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-#                username: cysd
-#                password: cysd123!@#
+#                url: jdbc:mysql://121.4.140.159:3307/ruoyi-community?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+#                username: root
+#                password: fangzhen,7410
+                url: jdbc:mysql://rm-bp12v02802jkd05j89o.mysql.rds.aliyuncs.com:3306/ruoyi-community_backup?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                username: cysd
+                password: cysd123!@#
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭

+ 2 - 2
ruoyi-admin/src/main/resources/application.yml

@@ -70,8 +70,8 @@ spring:
   # redis 配置
   redis:
     # 地址 47.122.10.161 121.4.140.159
-#    host: 47.122.10.161
-    host: 121.4.140.159
+    host: 47.122.10.161
+#    host: 121.4.140.159
     # 端口,默认为6379
     port: 6379
     # 数据库索引

+ 3 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -247,13 +247,15 @@ public class CommunityArticleController extends BaseController {
             if (isWaterMark && originalImages != null && !originalImages.isEmpty()) {
                 // 获取用户名
                 String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
+                // 在主线程中获取用户ID
+                Long userId = SecurityUtils.getUserId();
                 // 异步处理图片水印
                 communityImageProcessService.processImagesWithWatermark(
                         communityArticle.getId(),
                         originalImages,
                         isFillWater,
                         nickName,
-                        SecurityUtils.getUserId()
+                        userId
                 );
 
                 log.info("文章[{}]的图片水印处理已提交到后台异步处理", communityArticle.getId());

+ 26 - 15
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleServiceImpl.java

@@ -178,6 +178,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             for (Long articleId : articleIds) {
                 //获取指定文章详细内容,文章浏览量+1
                 CommunityArticle article = communityArticleMapper.selectById(articleId);
+                if (article == null) {
+                    continue;
+                }
                 article.setPageViews(article.getPageViews() + 1);
                 communityArticleMapper.updateById(article);
             }
@@ -674,7 +677,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         }
 
 
-        Long userId = SecurityUtils.getLoginUser().getUserId();
+        Long userId = SecurityUtils.getUserId();
         //插入文章信息
         communityArticle.setUserId(userId);
         communityArticle.setCreateBy(userId);
@@ -800,7 +803,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Override
     public void editCommunityArticle(CommunityArticle communityArticle) {
 
-        Long userId = SecurityUtils.getLoginUser().getUserId();
+        Long userId = SecurityUtils.getUserId();
         //编辑文章信息
         communityArticle.setUpdateBy(userId);
         communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
@@ -998,8 +1001,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Override
     public void sendComment(CommunityArticleComment communityArticleComment) throws ParseException {
         communityArticleComment.setId(null);
-        communityArticleComment.setCreateBy(SecurityUtils.getLoginUser().getUserId());
-        communityArticleComment.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
+        Long userId = SecurityUtils.getUserId();
+        communityArticleComment.setCreateBy(userId);
+        communityArticleComment.setUpdateBy(userId);
         communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleComment.setDelete(false);
@@ -1025,9 +1029,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                 communityArticleAt.setType(1L);
                 communityArticleAt.setArticleId(communityArticleComment.getArticleId());
                 communityArticleAt.setCommentId(communityArticleComment.getId());
-                communityArticleAt.setUserId(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setUserId(userId);
                 communityArticleAt.setPeerId(atUserId);
-                communityArticleAt.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setCreateBy(userId);
                 communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
                 communityArticleAts.add(communityArticleAt);
             }
@@ -1043,7 +1047,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Override
     public void deleteComment(CommunityArticleComment communityArticleComment) {
         communityArticleComment.setDelete(true);
-        communityArticleComment.setUpdateBy(SecurityUtils.getUserId());
+        Long userId = SecurityUtils.getUserId();
+        communityArticleComment.setUpdateBy(userId);
         communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
         communityArticleCommentMapper.updateById(communityArticleComment);
     }
@@ -1146,7 +1151,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                 BeanUtils.copyProperties(communityCircle, communityCircleVo);
 
                 //获取当前用户是否有关注这些圈子
-                CommunityUserCircle communityUserCircles = communityUserCircleMapper.selectOne(new QueryWrapper<CommunityUserCircle>().eq("circle_id", communityCircle.getId()).eq("user_id", SecurityUtils.getLoginUser().getUserId()).eq("is_delete", 0));
+                Long userId = SecurityUtils.getUserId();
+                CommunityUserCircle communityUserCircles = communityUserCircleMapper.selectOne(new QueryWrapper<CommunityUserCircle>().eq("circle_id", communityCircle.getId()).eq("user_id", userId).eq("is_delete", 0));
                 if (Objects.isNull(communityUserCircles) || Objects.isNull(communityUserCircles.getId())) {
                     //没找到关注数据,则设为false,反之则true
                     communityCircleVo.setLike(false);
@@ -1167,7 +1173,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      */
     @Override
     public CommunityUserLike addOrDeleteUserLike(Long likeUserId) {
-        Long userId = SecurityUtils.getLoginUser().getUserId();  // 当前登录用户id
+        Long userId = SecurityUtils.getUserId();  // 当前登录用户id
         //1.检查是否已被当前用户关注
         CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", userId).eq("like_user_id", likeUserId));
         //2.1 没有则进行关注,返回关注列表信息
@@ -1242,12 +1248,17 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         //设置是否被当前登录的用户关注
         communityUserInfoVo.setLike(false);
         if (isToken) {
-            Long loginUserId = SecurityUtils.getLoginUser().getUserId();
-            if (!Objects.equals(userId, loginUserId)) {
-                CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
-                if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
-                    communityUserInfoVo.setLike(true);
+            try {
+                Long loginUserId = SecurityUtils.getUserId();
+                if (!Objects.equals(userId, loginUserId)) {
+                    CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
+                    if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
+                        communityUserInfoVo.setLike(true);
+                    }
                 }
+            } catch (Exception e) {
+                log.error("获取当前登录用户ID失败", e);
+                // 如果获取用户ID失败,继续处理,不影响其他功能
             }
         }
         return communityUserInfoVo;
@@ -1612,7 +1623,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     @Override
     public List<CommunityUserPromptVo> selectCommunityUserPrompt(Long userId) {
         if (Objects.isNull(userId)) {
-            userId = SecurityUtils.getLoginUser().getUserId();
+            userId = SecurityUtils.getUserId();
         }
         // 查询自己的通知列表
         List<CommunityUserPrompt> communityUserPrompts