Browse Source

获取聊天列表新增未读消息数量

fangqing 5 months ago
parent
commit
f35d1491d1

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -20,6 +20,7 @@ import com.ruoyi.generator.vo.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.logging.log4j.util.Strings;
+import org.apache.poi.xssf.usermodel.XSSFPivotTable;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -96,6 +97,8 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private ICommunityCollectionUserService communityCollectionUserService;
 
+    @Autowired
+    private CommunityUserPromptMapper communityUserPromptMapper;
 
     /**
      * 获取文章列表信息
@@ -478,6 +481,11 @@ public class CommunityArticleController extends BaseController {
                         .like("circle_name", circleName));
             }
 
+            //为空返回空值
+            if (communityCircles == null){
+                return AjaxResult.success("圈子为空");
+            }
+
             for (CommunityCircle communityCircle : communityCircles) {
                 Long id = communityCircle.getId();
                 Long size = communityUserCircleMapper.selectCount(new QueryWrapper<CommunityUserCircle>()
@@ -991,4 +999,7 @@ public class CommunityArticleController extends BaseController {
 
 
 
+
+
+
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysUserVo.java

@@ -31,6 +31,11 @@ public class SysUserVo {
     //最新消息信息时间
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date msgTime;
+
     //最新一条消息内容
     private String msg;
+
+    //未读消息
+    private Long unreads;
+
 }

+ 14 - 1
ruoyi-system/src/main/resources/mapper/system/CommunityChatMsgMapper.xml

@@ -20,7 +20,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                    WHEN  r.message_type = 4 THEN '[视频]'
                    ELSE r.content
                    END AS msg,
-               r.create_time                                                         AS msgTime
+               r.create_time                                                         AS msgTime,
+               COALESCE(
+                       (
+                           SELECT num
+                           FROM (
+                                    SELECT sender_id, COUNT(*) AS num
+                                    FROM community_chat_msg
+                                    WHERE receiver_id = #{userId} AND receiver_is_read = '0' AND type = #{type}
+                                    GROUP BY sender_id
+                                ) A
+                           WHERE A.sender_id = r.sender_id
+                       ),
+                       0
+                   ) AS unreads
         FROM (SELECT CASE
                          WHEN sender_id = #{userId} THEN receiver_id
                          ELSE sender_id