Browse Source

优化我的消息

hubin 9 months ago
parent
commit
ce42234ac8

+ 3 - 4
src/main/java/com/aizuda/boot/modules/system/entity/vo/InformMessageVO.java

@@ -1,6 +1,5 @@
 package com.aizuda.boot.modules.system.entity.vo;
 
-import com.aizuda.boot.modules.system.entity.SysMessage;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Getter;
 import lombok.Setter;
@@ -18,19 +17,19 @@ public class InformMessageVO {
     private Long noticeNum;
 
     @Schema(description = "通知")
-    private List<SysMessage> noticeList;
+    private List<MyMessageVO> noticeList;
 
     @Schema(description = "消息总数量")
     private Long messageNum;
 
     @Schema(description = "消息")
-    private List<SysMessage> messageList;
+    private List<MyMessageVO> messageList;
 
     @Schema(description = "待办总数量")
     private Long todoNum;
 
     @Schema(description = "待办")
-    private List<SysMessage> todoList;
+    private List<MyMessageVO> todoList;
 
     public Long getNoticeNum() {
         return null == noticeNum ? 0 : noticeNum;

+ 17 - 0
src/main/java/com/aizuda/boot/modules/system/entity/vo/MyMessageVO.java

@@ -0,0 +1,17 @@
+package com.aizuda.boot.modules.system.entity.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class MyMessageVO {
+
+    @Schema(description = "标题")
+    private String title;
+
+    @Schema(description = "内容")
+    private String content;
+
+}

+ 3 - 0
src/main/java/com/aizuda/boot/modules/system/mapper/SysMessageMapper.java

@@ -1,6 +1,7 @@
 package com.aizuda.boot.modules.system.mapper;
 
 import com.aizuda.boot.modules.system.entity.SysMessage;
+import com.aizuda.boot.modules.system.entity.vo.MyMessageVO;
 import com.aizuda.boot.modules.system.entity.vo.SysMessageVO;
 import com.aizuda.service.mapper.CrudMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,4 +18,6 @@ import org.apache.ibatis.annotations.Param;
 public interface SysMessageMapper extends CrudMapper<SysMessage> {
 
     Page<SysMessageVO> selectPageVOByUserId(Page<SysMessage> page, @Param("userId") Long userId, @Param("m") SysMessage sysMessage);
+
+    Page<MyMessageVO> selectPageMyNotViewed(Page<MyMessageVO> page, @Param("userId") Long userId, @Param("category") Integer category);
 }

+ 1 - 1
src/main/java/com/aizuda/boot/modules/system/service/impl/SysMessageReceiverServiceImpl.java

@@ -18,7 +18,7 @@ public class SysMessageReceiverServiceImpl extends BaseServiceImpl<SysMessageRec
     @Override
     public boolean updateViewed(Long messageId, Long userId) {
         lambdaUpdate().set(SysMessageReceiver::getViewed, 1)
-                .eq(null != messageId, SysMessageReceiver::getId, messageId)
+                .eq(null != messageId, SysMessageReceiver::getMessageId, messageId)
                 .eq(SysMessageReceiver::getUserId, userId)
                 .update();
         return true;

+ 6 - 6
src/main/java/com/aizuda/boot/modules/system/service/impl/SysMessageServiceImpl.java

@@ -4,12 +4,12 @@ import com.aizuda.boot.modules.common.MessageEvent;
 import com.aizuda.boot.modules.system.entity.SysMessage;
 import com.aizuda.boot.modules.system.entity.SysMessageReceiver;
 import com.aizuda.boot.modules.system.entity.vo.InformMessageVO;
+import com.aizuda.boot.modules.system.entity.vo.MyMessageVO;
 import com.aizuda.boot.modules.system.entity.vo.SysMessageVO;
 import com.aizuda.boot.modules.system.mapper.SysMessageMapper;
 import com.aizuda.boot.modules.system.service.ISysMessageReceiverService;
 import com.aizuda.boot.modules.system.service.ISysMessageService;
 import com.aizuda.boot.modules.system.service.ISysSSEService;
-import com.aizuda.boot.modules.system.service.ISysUserRoleService;
 import com.aizuda.core.api.ApiAssert;
 import com.aizuda.service.service.BaseServiceImpl;
 import com.aizuda.service.web.UserSession;
@@ -57,15 +57,15 @@ public class SysMessageServiceImpl extends BaseServiceImpl<SysMessageMapper, Sys
         UserSession userSession = UserSession.getLoginInfo();
         InformMessageVO vo = new InformMessageVO();
         // 通知
-        Page<SysMessage> noticePage = this.pageCategoryByUser(userSession.getId(), 0);
+        Page<MyMessageVO> noticePage = this.pageCategoryByUser(userSession.getId(), 0);
         vo.setNoticeNum(noticePage.getTotal());
         vo.setNoticeList(noticePage.getRecords());
         // 消息
-        Page<SysMessage> messagePage = this.pageCategoryByUser(userSession.getId(), 1);
+        Page<MyMessageVO> messagePage = this.pageCategoryByUser(userSession.getId(), 1);
         vo.setMessageNum(messagePage.getTotal());
         vo.setMessageList(messagePage.getRecords());
         // 待办
-        Page<SysMessage> todoPage = this.pageCategoryByUser(userSession.getId(), 2);
+        Page<MyMessageVO> todoPage = this.pageCategoryByUser(userSession.getId(), 2);
         vo.setTodoNum(todoPage.getTotal());
         vo.setTodoList(todoPage.getRecords());
         // 总数量
@@ -73,8 +73,8 @@ public class SysMessageServiceImpl extends BaseServiceImpl<SysMessageMapper, Sys
         return vo;
     }
 
-    public Page<SysMessage> pageCategoryByUser(Long userId, Integer category) {
-        return super.page(Page.of(1, 5));
+    public Page<MyMessageVO> pageCategoryByUser(Long userId, Integer category) {
+        return baseMapper.selectPageMyNotViewed(Page.of(1, 5), userId, category);
     }
 
     @Override

+ 7 - 0
src/main/resources/mapper/SysMessageMapper.xml

@@ -13,5 +13,12 @@
                 AND s.category = #{m.category}
             </if>
         </where>
+        ORDER BY s.create_time DESC
+    </select>
+
+    <select id="selectPageMyNotViewed" resultType="com.aizuda.boot.modules.system.entity.vo.MyMessageVO">
+        SELECT s.title,s.content FROM sys_message s JOIN sys_message_receiver r ON r.message_id = s.id
+        WHERE r.user_id = #{userId} AND s.category = #{category} AND r.viewed = 0
+        ORDER BY s.create_time DESC
     </select>
 </mapper>