Przeglądaj źródła

fix 评论点赞收藏

tjf 2 miesięcy temu
rodzic
commit
96abdc2598
17 zmienionych plików z 335 dodań i 178 usunięć
  1. 1 1
      ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/Constants.java
  2. 12 1
      ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java
  3. 1 1
      ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/TenantKeyPrefixHandler.java
  4. 3 3
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/controller/communityNews/CommunityNewsController.java
  5. 22 11
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/domain/communityNews/vo/CommentInteractionVo.java
  6. 1 1
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/domain/communityNews/vo/CommunityNewsVo.java
  7. 90 0
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/listener/RedisKeyExpirationListener.java
  8. 4 0
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/mapper/CommentContentMapper.java
  9. 11 0
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentContentServiceImpl.java
  10. 24 22
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentIndexServiceImpl.java
  11. 85 75
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentLikesServiceImpl.java
  12. 29 25
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentStarsServiceImpl.java
  13. 36 28
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommunityNewsServiceImpl.java
  14. 7 8
      ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/PartyNewsServiceImpl.java
  15. 8 0
      ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentContentMapper.xml
  16. 0 1
      ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentIndexMapper.xml
  17. 1 1
      ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentStarsMapper.xml

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/Constants.java

@@ -123,7 +123,7 @@ public interface Constants {
     String ONE_LIKE = "one_like:";
     //对应用户点赞的文章key=my_like_one:{用户id} value =[资讯文章id]
     String ONE_MY_LIKE = "one_my_like:";
-    //社区资讯文章点赞的数量 给数据库同步数据在 redis中增加一个有过期时间的key key=one_like_count_time:{文章id}#{数量}  过期时候value获取不到
+    //社区资讯文章点赞的数量 给数据库同步数据在 redis中增加一个有过期时间的key key=tenantId:one_like_count_time:{文章id}#{数量}  过期时候value获取不到
     String ONE_LIKE_COUNT_TIME = "one_like_count_time:";
     //社区资讯文章点赞的数量永久key key=like_one_count:{文章id} value = 该文章的点赞数量
     String ONE_LIKE_COUNT = "one_like_count:";

+ 12 - 1
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/config/RedisConfig.java

@@ -22,6 +22,8 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.task.VirtualThreadTaskExecutor;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.listener.RedisMessageListenerContainer;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
@@ -35,7 +37,7 @@ import java.util.TimeZone;
 @Slf4j
 @AutoConfiguration
 @EnableConfigurationProperties(RedissonProperties.class)
-public class RedisConfig {
+public class RedisConfig  {
 
     @Autowired
     private RedissonProperties redissonProperties;
@@ -101,6 +103,15 @@ public class RedisConfig {
         };
     }
 
+    /* redis监听设置*/
+    @Bean
+    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
+        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
+        container.setConnectionFactory(connectionFactory);
+        /*添加redis过期时间的监听器*/
+        // container.addMessageListener(redisKeyExpirationListener,redisKeyExpirationListener.getTop());
+        return container;
+    }
     /**
      * 异常处理器
      */

+ 1 - 1
ruoyi-common/ruoyi-common-tenant/src/main/java/org/dromara/common/tenant/handle/TenantKeyPrefixHandler.java

@@ -39,7 +39,7 @@ public class TenantKeyPrefixHandler extends KeyPrefixHandler {
         }
         String tenantId = TenantHelper.getTenantId();
         if (StringUtils.isBlank(tenantId)) {
-            log.debug("无法获取有效的租户id -> Null");
+            //log.debug("无法获取有效的租户id -> Null");
             return super.map(name);
         }
         if (StringUtils.startsWith(name, tenantId + "")) {

+ 3 - 3
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/controller/communityNews/CommunityNewsController.java

@@ -137,10 +137,10 @@ public class CommunityNewsController extends BaseController {
         Long communityId = bo.getCommunityId();
         String key = SHARE_COMMUNITY + communityId;
         if (RedisUtils.hasKey(key)) {
-            long atomicValue = RedisUtils.getAtomicValue(key);
-            RedisUtils.setAtomicValue(SHARE_COMMUNITY, atomicValue + 1);
+            Object atomicValue = RedisUtils.getCacheObject(key);
+            RedisUtils.setAtomicValue(key, Long.parseLong(atomicValue.toString()) + 1);
         } else {
-            RedisUtils.setAtomicValue(SHARE_COMMUNITY, 1);
+            RedisUtils.setCacheObject(key, 1);
         }
         return R.ok();
     }

+ 22 - 11
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/domain/communityNews/vo/CommentInteractionVo.java

@@ -18,6 +18,8 @@ public class CommentInteractionVo implements Serializable {
     /** 目标id */
     private Long targetId;
 
+    private String tenantId;
+
     /** 目标类型(1:资讯评论 2:资讯点赞 3:资讯收藏 4:评论回复 5:回复点赞) */
     private String targetType;
     /**
@@ -53,6 +55,14 @@ public class CommentInteractionVo implements Serializable {
     private Long communityId;
 
 
+    public String getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(String tenantId) {
+        this.tenantId = tenantId;
+    }
+
     public Long getCommunityId() {
         return communityId;
     }
@@ -136,16 +146,17 @@ public class CommentInteractionVo implements Serializable {
     @Override
     public String toString() {
         return "CommentInteractionVo{" +
-                "targetId=" + targetId +
-                ", targetType='" + targetType + '\'' +
-                ", targetTitle='" + targetTitle + '\'' +
-                ", targetUserId=" + targetUserId +
-                ", userId=" + userId +
-                ", nickName='" + nickName + '\'' +
-                ", avatar='" + avatar + '\'' +
-                ", createTime=" + createTime +
-                ", type='" + type + '\'' +
-                ", communityId=" + communityId +
-                '}';
+            "targetId=" + targetId +
+            ", tenantId='" + tenantId + '\'' +
+            ", targetType='" + targetType + '\'' +
+            ", targetTitle='" + targetTitle + '\'' +
+            ", targetUserId=" + targetUserId +
+            ", userId=" + userId +
+            ", nickName='" + nickName + '\'' +
+            ", avatar='" + avatar + '\'' +
+            ", createTime=" + createTime +
+            ", type='" + type + '\'' +
+            ", communityId=" + communityId +
+            '}';
     }
 }

+ 1 - 1
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/domain/communityNews/vo/CommunityNewsVo.java

@@ -145,7 +145,7 @@ public class CommunityNewsVo implements Serializable {
     /**
      * 分享数量
      */
-    private Long userShare;
+    private String userShare;
 
     /**
      * 备注

+ 90 - 0
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/listener/RedisKeyExpirationListener.java

@@ -0,0 +1,90 @@
+package org.dromara.listener;
+
+
+import jakarta.annotation.Resource;
+import org.dromara.domain.communityNews.CommentContent;
+import org.dromara.domain.communityNews.CommunityNews;
+import org.dromara.mapper.CommentContentMapper;
+import org.dromara.mapper.CommunityNewsMapper;
+import org.springframework.data.redis.connection.Message;
+import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
+import org.springframework.data.redis.listener.PatternTopic;
+import org.springframework.data.redis.listener.RedisMessageListenerContainer;
+import org.springframework.data.redis.listener.Topic;
+import org.springframework.stereotype.Component;
+import static org.dromara.common.core.constant.Constants.ONE_LIKE_COUNT_TIME;
+import static org.dromara.common.core.constant.Constants.TWO_LIKE_COUNT_TIME;
+
+/**
+ * redis过期事件监听器
+ * @Author: tjf
+ * @Date: 2025/2/27 11:13
+ * @Describe:
+ */
+@Component
+public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
+    //"__keyevent@0__:expired"表示监听数据库0中的过期事件。如果你想监听特定数据库的过期事件,只需更改@0__中的数字为相应的数据库编号
+    // 。@*__ 表示监听所有redis数据库 redis0-15一共16个数据库
+    //todo 项目上线需要确定redis监听的数据库编号,在此处修改
+    private final Topic top = new PatternTopic("__keyevent@8__:expired");
+
+    @Resource
+    private CommunityNewsMapper communityNewsMapper;
+
+    @Resource
+    private CommentContentMapper commentContentMapper;
+    /**
+     * Creates new {@link MessageListener} for {@code __keyevent@*__:expired} messages.
+     *
+     * @param listenerContainer must not be {@literal null}.
+     */
+    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
+        super(listenerContainer);
+    }
+
+    /*设置绑定的redis数据库编号*/
+    //"__keyevent@0__:expired"表示监听数据库0中的过期事件。如果你想监听特定数据库的过期事件,只需更改@0__中的数字为相应的数据库编号
+    // 。@*__ 表示监听所有redis数据库 redis0-15一共16个数据库
+    @Override
+    protected void doRegister(RedisMessageListenerContainer listenerContainer) {
+        listenerContainer.addMessageListener(this,top);
+    }
+
+    /**
+     *  redis过期key的具体逻辑
+     * @param message 过期的key
+     * @param pattern 空间名称
+     */
+    @Override
+    public void onMessage(Message message, byte[] pattern) {
+        // 过期key 获取不到value
+        String expiredKey = message.toString();
+        //ONE_LIKE_COUNT_TIME = key=one_like_count_time:{文章id}#{数量}
+        // or TWO_LIKE_COUNT_TIME = key=two_like_count_time:{评论id}#{数量}
+        if (expiredKey.contains(ONE_LIKE_COUNT_TIME)){
+            //处理文章的点赞数量
+            String[] split = expiredKey.split(":");
+            //{文章id}#{数量}
+            String[] splitResult = split[2].split("#");
+            CommunityNews communityNews = new CommunityNews();
+            communityNews.setCommunityId(Long.parseLong(splitResult[0]));
+            communityNews.setUserLikes(splitResult[1]);
+            communityNewsMapper.updateById(communityNews);
+            System.out.println("监听key文章的点赞:"+expiredKey);
+        }else if (expiredKey.contains(TWO_LIKE_COUNT_TIME)){
+            //处理评论的点赞数量
+            String[] split = expiredKey.split(":");
+            //{评论id}#{数量}
+            String[] splitResult = split[2].split("#");
+            CommentContent commentContent = new CommentContent();
+            commentContent.setCommentId(Long.parseLong(splitResult[0]));
+            commentContent.setLikeCount(Long.parseLong(splitResult[1]));
+            commentContentMapper.updateCommentContentByCommentId(commentContent);
+            System.out.println("监听key评论的点赞:"+expiredKey);
+        }
+
+    }
+    public Topic getTop() {
+        return top;
+    }
+}

+ 4 - 0
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/mapper/CommentContentMapper.java

@@ -17,4 +17,8 @@ public interface CommentContentMapper extends BaseMapperPlus<CommentContent, Com
     @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
     int deleteCommentContentByCommentId(Long commentId);
 
+
+    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
+    int updateCommentContentByCommentId( CommentContent commentContent);
+
 }

+ 11 - 0
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentContentServiceImpl.java

@@ -9,6 +9,7 @@ import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.domain.communityNews.CommentContent;
 import org.dromara.domain.communityNews.CommentIndex;
 import org.dromara.domain.communityNews.CommunityNews;
@@ -126,6 +127,16 @@ public class CommentContentServiceImpl implements ICommentContentService {
             Long communityId = commentIndex.getCommunityId();
             Long userId = commentIndex.getUserId();
             //评论审核通过
+            //------记录该社区资讯评论的数量-------
+            String communityCommentCountKey = COMMUNITY_COMMENT_COUNT + communityId;
+            Integer communityCommentCount = RedisUtils.getCacheObject(communityCommentCountKey);
+            if (communityCommentCount == null) {
+                RedisUtils.setCacheObject(communityCommentCountKey, 1);
+            } else {
+                //评论数量+1
+                RedisUtils.setCacheObject(communityCommentCountKey, communityCommentCount + 1);
+            }
+            //------记录该社区资讯评论的数量结束-------
             //------设置未读互动,评论的谁就给谁在redis中新增一条未读的互动--------
             CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
             Integer isRoot = commentIndex.getIsRoot();

+ 24 - 22
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentIndexServiceImpl.java

@@ -47,6 +47,7 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
     private final CommentIndexMapper baseMapper;
     private final CommentContentMapper commentContentMapper;
     private final CommunityNewsMapper communityNewsMapper;
+
     /**
      * 查询社区资讯评论
      *
@@ -90,16 +91,17 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
     @Override
     public TableDataInfo<CommentIndexVoOld> getRootComment(CommentIndex commentIndex, PageQuery pageQuery) {
         Page<CommentIndexVoOld> parentComment = baseMapper.getRootComment(pageQuery.build(), commentIndex);
+        String tenantId = commentIndex.getTenantId();
         Long userId = LoginHelper.getUserId();
         List<CommentIndexVoOld> rootComment = parentComment.getRecords();
-        if (rootComment != null && rootComment.size() > 0) {
+        if (rootComment != null && !rootComment.isEmpty()) {
             //要判断所有评论当前人员是否点赞过
             //该用户点赞回复的key
-            String myLikeTwoKey = TWO_MY_LIKE + userId;
-            List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
-            if (communityIdList != null && communityIdList.size() > 0) {
+            String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
+            List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
+            if (communityIdList != null && !communityIdList.isEmpty()) {
                 for (CommentIndexVoOld commentIndexVo : rootComment) {
-                    if (communityIdList.contains(commentIndexVo.getId())) {
+                    if (communityIdList.contains(Math.toIntExact(commentIndexVo.getId()))) {
                         commentIndexVo.setIsLike(Y);
                     }
                 }
@@ -120,17 +122,18 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
     @Override
     public TableDataInfo<CommentChildrenVo> getParentComment(CommentIndex commentIndex, PageQuery pageQuery) {
         Long userId = LoginHelper.getUserId();
+        String tenantId = commentIndex.getTenantId();
         Page<CommentChildrenVo> parentComment = baseMapper.getParentComment(pageQuery.build(), commentIndex);
         List<CommentChildrenVo> allComment = parentComment.getRecords();
         //要判断所有评论当前人员是否点赞过
-        if (allComment != null && allComment.size() > 0) {
+        if (allComment != null && !allComment.isEmpty()) {
             //要判断所有评论当前人员是否点赞过
             //该用户点赞回复的key
-            String myLikeTwoKey = TWO_MY_LIKE + userId;
-            List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
-            if (communityIdList != null && communityIdList.size() > 0) {
+            String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
+            List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
+            if (communityIdList != null && !communityIdList.isEmpty()) {
                 for (CommentChildrenVo commentChildrenVo : allComment) {
-                    if (communityIdList.contains(commentChildrenVo.getId())) {
+                    if (communityIdList.contains(Math.toIntExact(commentChildrenVo.getId()))) {
                         commentChildrenVo.setIsLike(Y);
                     }
                 }
@@ -205,7 +208,7 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
             //再把评论内容表更新上资讯评论表id
             commentContent.setCommentId(commentIndex.getCommentId());
             commentContentMapper.updateById(commentContent);
-            //记录该社区资讯评论的数量
+/*            //记录该社区资讯评论的数量
             String communityCommentCountKey = COMMUNITY_COMMENT_COUNT + communityId;
             Integer communityCommentCount = RedisUtils.getCacheObject(communityCommentCountKey);
             if (communityCommentCount == null) {
@@ -213,7 +216,7 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
             } else {
                 //评论数量+1
                 RedisUtils.setCacheObject(communityCommentCountKey, communityCommentCount + 1);
-            }
+            }*/
         }
         return flag;
     }
@@ -270,7 +273,8 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
         if (commentIndex != null && commentIndex.getUserId().equals(userId)) {
             //社区资讯id
             Long communityId = commentIndex.getCommunityId();
-            flag = baseMapper.deleteById(commentIndex) > 0;
+            result = baseMapper.deleteById(commentIndex);
+            flag = result > 0;
             //删除评论内容表数据
             commentContentMapper.delete(new LambdaQueryWrapper<CommentContent>().eq(CommentContent::getCommentId, commentId));
             //如果是根评论删除,删除所有子评论
@@ -288,22 +292,19 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
             if (communityCommentCount != 0) {
                 //删除所有的评论数量 = 根评论数量+子评论数量
                 communityCommentCount = communityCommentCount - result;
-                if (communityCommentCount < 0) {
-                    communityCommentCount = 0;
-                }
-                RedisUtils.setCacheObject(communityCommentCountKey, communityCommentCount);
+                RedisUtils.setCacheObject(communityCommentCountKey, Math.max(communityCommentCount, 0));
             }
             //删除社区资讯评论点赞的数量永久key key=two_like_count:{评论id} value = 该评论的点赞数量
             RedisUtils.deleteObject(TWO_LIKE_COUNT + commentId);
             //社区资讯回复点赞的人员集合的key
             RedisUtils.deleteObject(TWO_LIKE + commentId);
             //对应用户点赞的回复key=two_my_like:{用户id} value = [评论id]
-            List<Long> commentIdList = RedisUtils.getCacheList(TWO_MY_LIKE + userId);
-            if (commentIdList != null && commentIdList.size() > 0) {
-                commentIdList.remove(commentId);
+            List<Integer> commentIdList = RedisUtils.getCacheList(TWO_MY_LIKE + userId);
+            if (commentIdList != null && !commentIdList.isEmpty()) {
+                commentIdList.removeIf(s -> s == Math.toIntExact(commentId));
             }
             RedisUtils.deleteObject(TWO_MY_LIKE + userId);
-            if (commentIdList != null && commentIdList.size() > 0) {
+            if (commentIdList != null && !commentIdList.isEmpty()) {
                 RedisUtils.setCacheList(TWO_MY_LIKE + userId, commentIdList);
             }
 /*            //删除该资讯点赞的数量需要知道所有评论的id
@@ -339,7 +340,7 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
             if (1 == isRoot) {
                 //如果是根评论先查询是否有子集评论
                 List<CommentIndex> commentIndexList = baseMapper.selectCommentIdListByCommentId(commentId);
-                if (commentIndexList != null && commentIndexList.size() > 0) {
+                if (commentIndexList != null && !commentIndexList.isEmpty()) {
                     for (CommentIndex index : commentIndexList) {
                         //删除未读互动中的子评论相关信息
                         deleteCommentChildren(index);
@@ -374,6 +375,7 @@ public class CommentIndexServiceImpl implements ICommentIndexService {
         }
         return flag;
     }
+
     /**
      * 删除未读互动中的子评论相关信息
      *

+ 85 - 75
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentLikesServiceImpl.java

@@ -46,6 +46,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
     private final CommunityNewsMapper communityNewsMapper;
     private final ICommunityNewsService communityNewsService;
     private final CommentIndexMapper commentIndexMapper;
+
     /**
      * 查询社区资讯点赞
      *
@@ -53,7 +54,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
      * @return 社区资讯点赞
      */
     @Override
-    public CommentLikesVo queryById(Long likesId){
+    public CommentLikesVo queryById(Long likesId) {
         return baseMapper.selectVoById(likesId);
     }
 
@@ -129,7 +130,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
     /**
      * 保存前的数据校验
      */
-    private void validEntityBeforeSave(CommentLikes entity){
+    private void validEntityBeforeSave(CommentLikes entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
@@ -142,7 +143,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
      */
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return baseMapper.deleteByIds(ids) > 0;
@@ -155,12 +156,14 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
      * //文章需要统计点赞的数量和当前登录用户是否已经点赞
      * //点赞之前应该去查一遍该文章或者回复的点赞key,value应该是点赞的人员id判断用户是否已经点赞过了,点赞过了就取消,没点赞过就加入
      * //还需要同步到数据库,需要一个完整的点赞key 一个设置过期时间的监听key
+     * redis配置文件中增加 notify-keyspace-events Ex
      */
     @Override
     public R<Void> giveTheThumbs(CommentLikes commentLikes) {
         String targetType = commentLikes.getTargetType();
         Long targetId = commentLikes.getTargetId();
         Long userId = commentLikes.getUserId();
+        String tenantId = commentLikes.getTenantId();
         //保存点赞信息
         //根据点赞目标id' 点赞目标类型(1:资讯 2:回复) 用户id查询是否已经点赞过
         CommentLikes commentLikesOld = baseMapper.selectCommentLikes(commentLikes);
@@ -174,20 +177,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             setCommentInteractionVo(commentLikes);
             if (ONE.equals(targetType)) {
                 // 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
-                String likeOneKey = ONE_LIKE + targetId;
+                String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
                 //社区资讯文章点赞的数量数据库同步的key
-                String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
+                String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
                 //文章永久点赞的数量key
-                String likeOneCountKey = ONE_LIKE_COUNT + targetId;
+                String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
                 //先去查看key对应的value集合 value = 点赞人员的id集合
-                List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
+                List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
                 //该用户点赞文章的key
-                String myLikeOneKey = ONE_MY_LIKE + userId;
-                List<Long> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
-                if (userIdListValue != null && userIdListValue.size() > 0) {
+                String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
+                List<Integer> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
+                if (userIdListValue != null && !userIdListValue.isEmpty()) {
                     //说明该文章被点过赞
                     //判断该用户是否点过赞
-                    if (userIdListValue.contains(userId)) {
+                    if (userIdListValue.contains(Math.toIntExact(userId))) {
                         //进行取消点赞
                         return unLike(commentLikes);
                     } else {
@@ -197,12 +200,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
                 } else {
                     //该文章没有被点过赞直接新增
                     userIdListValue = new ArrayList<>();
-                    userIdListValue.add(userId);
+                    userIdListValue.add(Math.toIntExact(userId));
                     RedisUtils.setCacheList(likeOneKey, userIdListValue);
                     //给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间  key=like_one_count_time:{文章id}#{数量}
-                    RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1,  Duration.ofMinutes(1));
+                    RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
                     //给该用户点赞文章的key添加值
-                    communityIdList.add(targetId);
+                    communityIdList.add(Math.toIntExact(targetId));
                     RedisUtils.setCacheList(myLikeOneKey, communityIdList);
                     //给该文章永久点赞数量的key添加值
                     RedisUtils.setCacheObject(likeOneCountKey, 1);
@@ -211,20 +214,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             } else {
                 //对回复进行点赞
                 // 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
-                String likeTwoKey = TWO_LIKE + targetId;
+                String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
                 //社区资讯回复点赞的数量数据库同步的key
-                String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
+                String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
                 //回复永久点赞的数量key
-                String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
+                String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
                 //先去查看key对应的value集合 value = 点赞人员的id集合
-                List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
+                List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
                 //该用户点赞回复的key
-                String myLikeTwoKey = TWO_MY_LIKE + userId;
-                List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
-                if (userIdListValue != null && userIdListValue.size() > 0) {
+                String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
+                List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
+                if (userIdListValue != null && !userIdListValue.isEmpty()) {
                     //说明该回复被点过赞
                     //判断该用户是否点过赞
-                    if (userIdListValue.contains(userId)) {
+                    if (userIdListValue.contains(Math.toIntExact(userId))) {
                         //进行取消点赞
                         return unLike(commentLikes);
                     } else {
@@ -234,12 +237,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
                 } else {
                     //该回复没有被点过赞直接新增
                     userIdListValue = new ArrayList<>();
-                    userIdListValue.add(userId);
+                    userIdListValue.add(Math.toIntExact(userId));
                     RedisUtils.setCacheList(likeTwoKey, userIdListValue);
                     //给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
-                    RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofMinutes(1));
+                    RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
                     //给该用户点赞回复的key添加值
-                    communityIdList.add(targetId);
+                    communityIdList.add(Math.toIntExact(targetId));
                     RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
                     //给该回复永久点赞数量的key添加值
                     RedisUtils.setCacheObject(likeTwoCountKey, 1);
@@ -260,60 +263,62 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
         String targetType = commentLikes.getTargetType();
         Long targetId = commentLikes.getTargetId();
         Long userId = commentLikes.getUserId();
+        String tenantId = commentLikes.getTenantId();
         if (ONE.equals(targetType)) {
             // 社区资讯文章点赞的人员集合的key key = ONE_LIKE:{targetId} value = [userId,userId];
-            String likeOneKey = ONE_LIKE + targetId;
+            String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
             //社区资讯文章点赞的数量数据库同步的key
-            String likeOneCountTimeKey = ONE_LIKE_COUNT + targetId;
+            String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
             //文章永久点赞的数量key
-            String likeOneCountKey = ONE_LIKE_COUNT + targetId;
+            String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
             //先去查看key对应的value集合 value = 点赞人员的id集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
             //该用户点赞文章的key
-            String myLikeOneKey = ONE_MY_LIKE + userId;
-            List<Long> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
+            String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
+            List<Integer> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
             //新增点赞信息
             // 新增社区资讯文章点赞的人员集合
-            userIdListValue.add(userId);
+            userIdListValue.add(Math.toIntExact(userId));
             RedisUtils.setCacheList(likeOneKey, userIdListValue);
             //新增该用户点赞文章
-            communityIdList.add(targetId);
+            communityIdList.add(Math.toIntExact(targetId));
             RedisUtils.setCacheList(myLikeOneKey, communityIdList);
             //新增文章永久点赞数量的key更新值
             Integer likeOneCount = RedisUtils.getCacheObject(likeOneCountKey);
             likeOneCount = likeOneCount + 1;
             RedisUtils.setCacheObject(likeOneCountKey, likeOneCount);
             //新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
-            RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofMinutes(1));
+            RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofSeconds(10));
             return R.ok();
         } else {
             // 社区资讯文章回复的人员集合的key key = TWO_LIKE:{targetId} value = [userId,userId];
-            String likeTwoKey = TWO_LIKE + targetId;
+            String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
             //社区资讯文章回复的数量数据库同步的key
-            String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
+            String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
             //文章永久回复的数量key
-            String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
+            String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
             //先去查看key对应的value集合 value = 点赞人员的id集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
             //该用户点赞回复的key
-            String myLikeTwoKey = TWO_MY_LIKE + userId;
-            List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
+            String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
+            List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
             //新增点赞信息
             // 新增社区资讯回复点赞的人员集合
-            userIdListValue.add(userId);
+            userIdListValue.add(Math.toIntExact(userId));
             RedisUtils.setCacheList(likeTwoKey, userIdListValue);
             //新增该用户点赞回复
-            communityIdList.add(targetId);
+            communityIdList.add(Math.toIntExact(targetId));
             RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
             //新增回复永久点赞数量的key更新值
             Integer likeTwoCount = RedisUtils.getCacheObject(likeTwoCountKey);
             likeTwoCount = likeTwoCount + 1;
             RedisUtils.setCacheObject(likeTwoCountKey, likeTwoCount);
             //新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
-            RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofMinutes(1));
+            RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofSeconds(10));
             return R.ok();
         }
     }
+
     /**
      * 用户取消点赞
      *
@@ -325,18 +330,19 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
         String targetType = commentLikes.getTargetType();
         Long targetId = commentLikes.getTargetId();
         Long userId = commentLikes.getUserId();
+        String tenantId = commentLikes.getTenantId();
         if (ONE.equals(targetType)) {
             //文章永久点赞的数量key
-            String likeOneCountKey = ONE_LIKE_COUNT + targetId;
+            String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
             //社区资讯文章点赞的数量数据库同步的key
-            String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
+            String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
             //-------------------------删除 社区资讯文章点赞的人员集合value中的userId
             //  key = ONE_LIKE:{targetId} value = [userId,userId];
-            String likeOneKey = ONE_LIKE + targetId;
+            String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
             //先去查看key对应的value集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
-            userIdListValue.remove(userId);
-            if (userIdListValue.size() == 0) {
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
+            userIdListValue.removeIf(s -> s == Math.toIntExact(userId));
+            if (userIdListValue.isEmpty()) {
                 RedisUtils.deleteObject(likeOneKey);
             } else {
                 RedisUtils.deleteObject(likeOneKey);
@@ -345,10 +351,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             }
 
             //-------------------------删除 该用户点赞文章value中的文章id
-            String myLikeOneKey = ONE_MY_LIKE + userId;
-            List<Long> communityIdListValue = RedisUtils.getCacheList(myLikeOneKey);
-            communityIdListValue.remove(targetId);
-            if (communityIdListValue.size() == 0) {
+            String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
+            List<Integer> communityIdListValue = RedisUtils.getCacheList(myLikeOneKey);
+            communityIdListValue.removeIf(s -> s == Math.toIntExact(targetId));
+            if (communityIdListValue.isEmpty()) {
                 RedisUtils.deleteObject(myLikeOneKey);
             } else {
                 RedisUtils.deleteObject(myLikeOneKey);
@@ -358,23 +364,24 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             //先获取永久点赞数量的值
             Integer likeCount = RedisUtils.getCacheObject(likeOneCountKey);
             //更新永久点赞数量
-            RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount - 1,0));
+            likeCount = likeCount -1;
+            RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount, 0));
             //给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
-            RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
+            RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
             return R.ok();
         } else {
             //评论的删除
             //评论永久点赞的数量key
-            String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
+            String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
             //社区资讯评论点赞的数量数据库同步的key
-            String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
+            String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
             //-------------------------删除 社区资讯文章评论的人员集合value中的userId
             //  key = LIKE_ONE:{targetId} value = [userId,userId];
-            String likeTwoKey = TWO_LIKE + targetId;
+            String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
             //先去查看key对应的value集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
-            userIdListValue.remove(userId);
-            if (userIdListValue.size() == 0) {
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
+            userIdListValue.removeIf(s -> s == Math.toIntExact(userId));
+            if (userIdListValue.isEmpty()) {
                 RedisUtils.deleteObject(likeTwoKey);
             } else {
                 RedisUtils.deleteObject(likeTwoKey);
@@ -382,10 +389,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
                 RedisUtils.setCacheList(likeTwoKey, userIdListValue);
             }
             //-------------------------删除 该用户点赞评论value中的文章id
-            String myLikeTwoKey = TWO_MY_LIKE + userId;
-            List<Long> communityIdListValue = RedisUtils.getCacheList(myLikeTwoKey);
-            communityIdListValue.remove(targetId);
-            if (communityIdListValue.size() == 0) {
+            String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
+            List<Integer> communityIdListValue = RedisUtils.getCacheList(myLikeTwoKey);
+            communityIdListValue.removeIf(s -> s == Math.toIntExact(targetId));
+            if (communityIdListValue.isEmpty()) {
                 RedisUtils.deleteObject(myLikeTwoKey);
             } else {
                 RedisUtils.deleteObject(myLikeTwoKey);
@@ -395,9 +402,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             //先获取永久点赞数量的值
             Integer likeCount = RedisUtils.getCacheObject(likeTwoCountKey);
             //更新永久点赞数量
-            RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount - 1,0));
+            likeCount = likeCount - 1;
+            RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount, 0));
             //给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
-            RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
+            RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
             return R.ok();
         }
     }
@@ -414,6 +422,8 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
         CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
         //先判断是资讯点赞还是回复点赞
         String targetType = commentLikes.getTargetType();
+        String tenantId = commentLikes.getTenantId();
+        commentInteractionVo.setTenantId(tenantId);
         commentInteractionVo.setTargetType(TWO);
         commentInteractionVo.setType(ONE);
         if (ONE.equals(targetType)) {
@@ -423,13 +433,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
             commentInteractionVo.setTargetUserId(communityNews.getUserId());
             //-------------判断是点赞还是取消点赞-------------------
             // 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
-            String likeOneKey = ONE_LIKE + targetId;
+            String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
             //先去查看key对应的value集合 value = 点赞人员的id集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
-            if (userIdListValue != null && userIdListValue.size() > 0) {
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
+            if (userIdListValue != null && !userIdListValue.isEmpty()) {
                 //说明该文章被点过赞
                 //判断该用户是否点过赞
-                if (userIdListValue.contains(userId)) {
+                if (userIdListValue.contains(Math.toIntExact(userId))) {
                     //设置取消点赞
                     commentInteractionVo.setType(TWO);
                 }
@@ -445,13 +455,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
 
             //-------------判断是点赞还是取消点赞-------------------
             // 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
-            String likeTwoKey = TWO_LIKE + targetId;
+            String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
             //先去查看key对应的value集合 value = 点赞人员的id集合
-            List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
-            if (userIdListValue != null && userIdListValue.size() > 0) {
+            List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
+            if (userIdListValue != null && !userIdListValue.isEmpty()) {
                 //说明该回复被点过赞
                 //判断该用户是否点过赞
-                if (userIdListValue.contains(userId)) {
+                if (userIdListValue.contains(Math.toIntExact(userId))) {
                     //设置取消点赞
                     commentInteractionVo.setType(TWO);
                 }

+ 29 - 25
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommentStarsServiceImpl.java

@@ -51,7 +51,7 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
      * @return 社区资讯收藏
      */
     @Override
-    public CommentStarsVo queryById(Long starsId){
+    public CommentStarsVo queryById(Long starsId) {
         return baseMapper.selectVoById(starsId);
     }
 
@@ -127,7 +127,7 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
     /**
      * 保存前的数据校验
      */
-    private void validEntityBeforeSave(CommentStars entity){
+    private void validEntityBeforeSave(CommentStars entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
@@ -140,11 +140,12 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
      */
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return baseMapper.deleteByIds(ids) > 0;
     }
+
     /**
      * 社区资讯收藏或取消收藏
      */
@@ -154,19 +155,21 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
         Long userId = commentStars.getUserId();
         //收藏或者取消收藏判断用户是否收藏过,收藏过就取消收藏
         Long targetId = commentStars.getTargetId();
-        String starsCommunityKey = STARS_COMMUNITY + targetId;
+        String tenantId = commentStars.getTenantId();
+        String starsCommunityKey = tenantId + ":" + STARS_COMMUNITY + targetId;
         //该资讯收藏数量的key
-        String starsUserCountKey = STARS_USER_COUNT + targetId;
-        List<Long> userIdList = RedisUtils.getCacheList(starsCommunityKey);
+        String starsUserCountKey = tenantId + ":" + STARS_USER_COUNT + targetId;
+        List<Integer> userIdList = RedisUtils.getCacheList(starsCommunityKey);
         Integer starsCount = 0;
         CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
+        commentInteractionVo.setTenantId(tenantId);
         commentInteractionVo.setType(ONE);
-        if (userIdList != null && userIdList.size() > 0) {
+        if (userIdList != null && !userIdList.isEmpty()) {
             //判断该用户是否收藏过
-            if (userIdList.contains(userId)) {
+            if (userIdList.contains(Math.toIntExact(userId))) {
                 commentInteractionVo.setType(TWO);
                 //说明收藏过则-----取消收藏
-                userIdList.remove(userId);
+                userIdList.removeIf(s -> s == Math.toIntExact(userId));
                 if (userIdList.isEmpty()) {
                     RedisUtils.deleteObject(starsCommunityKey);
                 } else {
@@ -175,13 +178,12 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
                 }
                 //收藏数量-1
                 starsCount = RedisUtils.getCacheObject(starsUserCountKey);
-                RedisUtils.setCacheObject(starsUserCountKey, Math.max(starsCount - 1,0));
-                commentStars.setDelFlag("Y");
+                RedisUtils.setCacheObject(starsUserCountKey, Math.max(starsCount - 1, 0));
                 //更新数据库
                 baseMapper.updateCommentStarsByUserIdAndCommunityId(commentStars);
             } else {
                 //则-------收藏
-                userIdList.add(userId);
+                userIdList.add(Math.toIntExact(userId));
                 RedisUtils.setCacheList(starsCommunityKey, userIdList);
                 //收藏数量+1
                 starsCount = RedisUtils.getCacheObject(starsUserCountKey);
@@ -192,7 +194,7 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
         } else {
             //----------第一次有人收藏
             userIdList = new ArrayList<>();
-            userIdList.add(userId);
+            userIdList.add(Math.toIntExact(userId));
             RedisUtils.setCacheList(starsCommunityKey, userIdList);
             starsCount = 1;
             //收藏数量+1
@@ -219,6 +221,7 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
         //----------------------设置未读互动完成--------
         return R.ok();
     }
+
     /**
      * 党建收藏或取消收藏
      *
@@ -227,18 +230,19 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
      */
     @Override
     public R<Void> getPartyNewsStars(CommentStars commentStars) {
+        String tenantId = commentStars.getTenantId();
         Long userId = commentStars.getUserId();
         //收藏或者取消收藏判断用户是否收藏过,收藏过就取消收藏
         Long targetId = commentStars.getTargetId();
-        String partyKey = STARS_PARTY_NEWS + userId;
-        List<Long> partyIdList = RedisUtils.getCacheList(partyKey);
+        String partyKey = tenantId + ":" + STARS_PARTY_NEWS + userId;
+        List<Integer> partyIdList = RedisUtils.getCacheList(partyKey);
         int starsCount = 0;
-        Object starsPartyNewsCount = RedisUtils.getCacheObject(STARS_PARTY_NEWS_COUNT + targetId);
-        if (partyIdList != null && partyIdList.size() > 0) {
-            if (partyIdList.contains(targetId)) {
+        Object starsPartyNewsCount = RedisUtils.getCacheObject(tenantId + ":" + STARS_PARTY_NEWS_COUNT + targetId);
+        if (partyIdList != null && !partyIdList.isEmpty()) {
+            if (partyIdList.contains(Math.toIntExact(targetId))) {
                 //说明该党建资讯该用户收藏过     取消收藏
-                partyIdList.remove(targetId);
-                if (partyIdList.size() == 0) {
+                partyIdList.removeIf(s -> s == Math.toIntExact(targetId));
+                if (partyIdList.isEmpty()) {
                     RedisUtils.deleteObject(partyKey);
                 } else {
                     RedisUtils.deleteObject(partyKey);
@@ -246,29 +250,29 @@ public class CommentStarsServiceImpl implements ICommentStarsService {
                 }
                 baseMapper.updateCommentStarsByUserIdAndCommunityId(commentStars);
                 if (ObjectUtils.isNotEmpty(starsPartyNewsCount)) {
-                    RedisUtils.setCacheObject(STARS_PARTY_NEWS_COUNT + targetId, Math.max(Integer.parseInt(starsPartyNewsCount.toString()) - 1,0));
+                    RedisUtils.setCacheObject(tenantId + ":" + STARS_PARTY_NEWS_COUNT + targetId, Math.max(Integer.parseInt(starsPartyNewsCount.toString()) - 1, 0));
                 }
             } else {
                 //则收藏
-                partyIdList.add(targetId);
+                partyIdList.add(Math.toIntExact(targetId));
                 RedisUtils.setCacheList(partyKey, partyIdList);
                 //收藏表新增数据
                 baseMapper.insert(commentStars);
                 //收藏数量+1
                 if (ObjectUtils.isNotEmpty(starsPartyNewsCount)) {
                     starsCount = Integer.parseInt(starsPartyNewsCount.toString()) + 1;
-                    RedisUtils.setCacheObject(STARS_PARTY_NEWS_COUNT + targetId, starsCount);
+                    RedisUtils.setCacheObject(tenantId + ":" + STARS_PARTY_NEWS_COUNT + targetId, starsCount);
                 }
             }
         } else {
             partyIdList = new ArrayList<>();
             //则第一个收藏
-            partyIdList.add(targetId);
+            partyIdList.add(Math.toIntExact(targetId));
             RedisUtils.setCacheList(partyKey, partyIdList);
             //收藏表新增数据
             baseMapper.insert(commentStars);
             //收藏数量+1
-            RedisUtils.setCacheObject(STARS_PARTY_NEWS_COUNT + targetId, 1);
+            RedisUtils.setCacheObject(tenantId + ":" + STARS_PARTY_NEWS_COUNT + targetId, 1);
 
         }
         return R.ok();

+ 36 - 28
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/CommunityNewsServiceImpl.java

@@ -43,31 +43,33 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
      * @return 社区资讯
      */
     @Override
-    public CommunityNewsVo queryById(Long communityId){
+    public CommunityNewsVo queryById(Long communityId) {
         CommunityNewsVo communityNews = baseMapper.selectVoById(communityId);
-        communityNews.setIsStar("N");
-        communityNews.setIsLike("N");
-        communityNews.setUserShare(0L);
+        communityNews.setIsStar(N);
+        communityNews.setIsLike(N);
+        communityNews.setUserShare("0");
+        //分享
         String key = SHARE_COMMUNITY + communityId;
         if (RedisUtils.hasKey(key)) {
-            long atomicValue = RedisUtils.getAtomicValue(key);
-            communityNews.setUserShare(atomicValue);
+            Object shareCount = RedisUtils.getCacheObject(key);
+            communityNews.setUserShare(shareCount.toString());
         }
+        //点赞
         Long userId = LoginHelper.getUserId();
         String likeOneKey = ONE_LIKE + communityId;
-        List<Long> userIdList = RedisUtils.getCacheList(likeOneKey);
-        if (userIdList != null && userIdList.size() > 0) {
-            if (userIdList.contains(userId)) {
-                communityNews.setIsLike("Y");
+        List<Integer> userIdList = RedisUtils.getCacheList(likeOneKey);
+        if (userIdList != null && !userIdList.isEmpty()) {
+            if (userIdList.contains(Math.toIntExact(userId))) {
+                communityNews.setIsLike(Y);
             }
         }
         //该资讯收藏人员的key
         String starsCommunityKey = STARS_COMMUNITY + communityId;
-        List<Long> userIdListStars = RedisUtils.getCacheList(starsCommunityKey);
-        if (userIdListStars != null && userIdListStars.size() > 0) {
+        List<Integer> userIdListStars = RedisUtils.getCacheList(starsCommunityKey);
+        if (userIdListStars != null && !userIdListStars.isEmpty()) {
             //判断该用户是否收藏过
-            if (userIdListStars.contains(userId)) {
-                communityNews.setIsStar("Y");
+            if (userIdListStars.contains(Math.toIntExact(userId))) {
+                communityNews.setIsStar(Y);
             }
         }
         //查询redis中的点赞数量,收藏数量,评论数量
@@ -102,12 +104,12 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
         Page<CommunityNewsVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
         List<CommunityNewsVo> communityNewsList = result.getRecords();
         //设置是否有未读互动
-        if (communityNewsList != null && communityNewsList.size() > 0) {
+        if (communityNewsList != null && !communityNewsList.isEmpty()) {
             for (CommunityNewsVo news : communityNewsList) {
-                news.setIsInteraction("N");
+                news.setIsInteraction(N);
                 //key=comment_interaction_community_user_count:{userId} hkey = {community_id} value = 资讯下有多少个未读的互动(点赞,收藏,回复)
                 if (RedisUtils.hasCacheMapKey(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + userId, news.getCommunityId().toString())) {
-                    news.setIsInteraction("Y");
+                    news.setIsInteraction(Y);
                 }
             }
         }
@@ -183,7 +185,7 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
     /**
      * 保存前的数据校验
      */
-    private void validEntityBeforeSave(CommunityNews entity){
+    private void validEntityBeforeSave(CommunityNews entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
@@ -196,11 +198,12 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
      */
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return baseMapper.deleteByIds(ids) > 0;
     }
+
     /**
      * 设置未读互动
      *
@@ -214,6 +217,7 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
         String targetType = commentInteractionVo.getTargetType();
         String type = commentInteractionVo.getType();
         Long targetId = commentInteractionVo.getTargetId();
+        String tenantId = commentInteractionVo.getTenantId();
         /* 社区资讯ID 当是点赞回复的时候有值 */
         Long communityId = commentInteractionVo.getTargetId();
         //判断是否是点赞回复
@@ -221,7 +225,10 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
             communityId = commentInteractionVo.getCommunityId();
         }
         //-------------------获取设置用户的未读互动数量----------------
-        String commentInteractionUserCountKey = COMMENT_INTERACTION_USER_COUNT + targetUserId;
+        String commentInteractionUserCountKey =  COMMENT_INTERACTION_USER_COUNT + targetUserId;
+        if (StringUtils.isNotBlank(tenantId)) {
+            commentInteractionUserCountKey = tenantId + ":" + COMMENT_INTERACTION_USER_COUNT + targetUserId;
+        }
         Object commentInteractionUserCount = RedisUtils.getCacheObject(commentInteractionUserCountKey);
         if (commentInteractionUserCount != null) {
             //判断是删除还是新增
@@ -238,29 +245,30 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
         //-------------------设置用户的未读互动数量结束----------------
         //-------------------设置用户的未读资讯的id和该资讯下一共有多少未读互动数量----------------
         //key=comment_interaction_community_user_count:{userId} hkey = {community_id} value = 资讯下有多少个未读的互动(点赞,收藏,回复)
-        String commentInteractionCommunityUserCount = RedisUtils.getCacheMapValue(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId, communityId.toString());
+        String key = tenantId + ":" + COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId;
+        String commentInteractionCommunityUserCount = RedisUtils.getCacheMapValue(key, communityId.toString());
         //判断是删除还是新增
         if (ONE.equals(type)) {
             //新增
             if (StringUtils.isNotBlank(commentInteractionCommunityUserCount)) {
-                RedisUtils.setCacheMapValue(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId, communityId.toString(), String.valueOf(Integer.parseInt(commentInteractionCommunityUserCount) + 1));
+                RedisUtils.setCacheMapValue(key, communityId.toString(), String.valueOf(Integer.parseInt(commentInteractionCommunityUserCount) + 1));
             } else {
-                RedisUtils.setCacheMapValue(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId, communityId.toString(), ONE);
+                RedisUtils.setCacheMapValue(key, communityId.toString(), ONE);
             }
         } else {
             //删除
             if (StringUtils.isNotBlank(commentInteractionCommunityUserCount)) {
                 int commentInteractionCommunityUserCountResult = Integer.parseInt(commentInteractionCommunityUserCount) - 1;
                 if (commentInteractionCommunityUserCountResult <= 0) {
-                    RedisUtils.delCacheMapValue(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId, communityId.toString());
+                    RedisUtils.delCacheMapValue(key, communityId.toString());
                 } else {
-                    RedisUtils.setCacheMapValue(COMMENT_INTERACTION_COMMUNITY_USER_COUNT + targetUserId, communityId.toString(), commentInteractionCommunityUserCountResult);
+                    RedisUtils.setCacheMapValue(key, communityId.toString(), commentInteractionCommunityUserCountResult);
                 }
             }
         }
         //-------------------设置用户的未读资讯的id和该资讯下一共有多少未读互动数量结束----------------
         //-------------------存储用户的未读资讯数据----------------
-        String commentInteractionUserKey = COMMENT_INTERACTION_USER + targetUserId;
+        String commentInteractionUserKey = tenantId + ":" +COMMENT_INTERACTION_USER + targetUserId;
         Map<String, Object> commentInteractionUserMap = RedisUtils.getCacheMap(commentInteractionUserKey);
         //hKey={targetType:targetId}
         String hKey = targetType + ":" + targetId;
@@ -269,7 +277,7 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
             RedisUtils.setCacheMapValue(commentInteractionUserKey, hKey, commentInteractionVo);
         } else {
             //删除
-            if (commentInteractionUserMap != null && commentInteractionUserMap.size() > 0) {
+            if (commentInteractionUserMap != null && !commentInteractionUserMap.isEmpty()) {
                 //删除一条数据
                 RedisUtils.delCacheMapValue(commentInteractionUserKey, hKey);
             }
@@ -295,7 +303,7 @@ public class CommunityNewsServiceImpl implements ICommunityNewsService {
         String commentInteractionUserKey = COMMENT_INTERACTION_USER + userId;
         Map<String, Object> commentInteractionUserMap = RedisUtils.getCacheMap(commentInteractionUserKey);
         List<Object> resultList = new ArrayList<>();
-        if (commentInteractionUserMap != null && commentInteractionUserMap.size() > 0) {
+        if (commentInteractionUserMap != null && !commentInteractionUserMap.isEmpty()) {
             resultList.addAll(commentInteractionUserMap.values());
         }
         resultMap.put("list", resultList);

+ 7 - 8
ruoyi-modules/ruoyi-wuye/src/main/java/org/dromara/service/impl/PartyNewsServiceImpl.java

@@ -22,8 +22,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import static org.dromara.common.core.constant.Constants.STARS_PARTY_NEWS;
-import static org.dromara.common.core.constant.Constants.STARS_PARTY_NEWS_COUNT;
+import static org.dromara.common.core.constant.Constants.*;
 
 /**
  * 党建资讯Service业务层处理
@@ -53,10 +52,10 @@ public class PartyNewsServiceImpl implements IPartyNewsService {
         baseMapper.updateById(update);
         String partyKey = STARS_PARTY_NEWS + LoginHelper.getUserId();
         List<Long> partyIdList = RedisUtils.getCacheList(partyKey);
-        partyNewsVo.setIsStars("N");
+        partyNewsVo.setIsStars(N);
         Long partyIdNews = partyNewsVo.getPartyId();
-        if (partyIdList.contains(partyIdNews)) {
-            partyNewsVo.setIsStars("Y");
+        if (partyIdList.contains(partyIdNews.intValue())) {
+            partyNewsVo.setIsStars(Y);
         }
         //插入收藏数量
         partyNewsVo.setStarsCount(0);
@@ -82,10 +81,10 @@ public class PartyNewsServiceImpl implements IPartyNewsService {
             String partyKey = STARS_PARTY_NEWS + LoginHelper.getUserId();
             List<Long> partyIdList = RedisUtils.getCacheList(partyKey);
             for (PartyNewsVo news : result.getRecords()) {
-                news.setIsStars("N");
+                news.setIsStars(N);
                 Long partyId = news.getPartyId();
-                if (partyIdList.contains(partyId)) {
-                    news.setIsStars("Y");
+                if (partyIdList.contains(partyId.intValue())) {
+                    news.setIsStars(Y);
                 }
                 //插入收藏数量
                 news.setStarsCount(0);

+ 8 - 0
ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentContentMapper.xml

@@ -7,4 +7,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="deleteCommentContentByCommentId" parameterType="org.dromara.domain.communityNews.CommentContent">
         update comment_content set del_flag = '1' where comment_id in(select comment_id from comment_index where parent_id = #{commentId})
     </update>
+
+    <update id="updateCommentContentByCommentId" parameterType="org.dromara.domain.communityNews.CommentContent">
+        update comment_content
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="likeCount != null">like_count = #{likeCount},</if>
+        </trim>
+        where comment_id = #{commentId}
+    </update>
 </mapper>

+ 0 - 1
ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentIndexMapper.xml

@@ -196,7 +196,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             AND i.del_flag = '0'
             <if test="commentIndex.parentId != null ">and i.parent_id = #{commentIndex.parentId}</if>
         </where>
-        order by i.create_time DESC,c.like_count DESC
     </select>
 
     <select id="selectCommentIdListByCommentId" resultMap="CommentIndexResult">

+ 1 - 1
ruoyi-modules/ruoyi-wuye/src/main/resources/mapper/wuYe/CommentStarsMapper.xml

@@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="org.dromara.mapper.CommentStarsMapper">
 
     <update id="updateCommentStarsByUserIdAndCommunityId" parameterType="org.dromara.domain.communityNews.CommentStars">
-        update comment_stars set del_flag = 'Y'
+        update comment_stars set del_flag = '1'
         where user_id = #{userId} and target_id = #{targetId} and target_type = #{targetType}
     </update>
 </mapper>