Jelajahi Sumber

feat(message): 消息已读状态变更及消息个数接口

huey 1 tahun lalu
induk
melakukan
21b331fbd7

+ 33 - 0
src/main/java/com/dragon/tj/portal/common/vo/message/MsgCountVO.java

@@ -0,0 +1,33 @@
+package com.dragon.tj.portal.common.vo.message;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author huey China.
+ * @Description : 消息总数VO
+ * @Date Created in 2023/7/21 15:30
+ */
+@Getter
+@Setter
+public class MsgCountVO {
+
+    /**
+     * 信息待办
+     */
+    private Integer messageNCount = 0;
+    /**
+     * 信息已办
+     */
+    private Integer messageYCount = 0;
+
+    /**
+     * 消息待办
+     */
+    private Integer noticeNCount = 0;
+
+    /**
+     * 消息已办
+     */
+    private Integer noticeYCount = 0;
+}

+ 10 - 0
src/main/java/com/dragon/tj/portal/controller/MessageCenterController.java

@@ -70,6 +70,16 @@ public class MessageCenterController {
         return R.ok();
     }
 
+    /**
+    * @author huey China.
+    * @Description : 获取信息和消息的待办和已办的个数
+    * @Date Created in 2023/7/21 15:29
+    */
+    @GetMapping("/getCount")
+    public R getCount() {
+        return R.ok(messageInfoService.getCount());
+    }
+
 
 }
 

+ 2 - 2
src/main/java/com/dragon/tj/portal/controller/NoticeInfoController.java

@@ -62,7 +62,7 @@ public class NoticeInfoController {
     }
 
     /**
-     * 阅读
+     * 阅读 targetId
      */
     @GetMapping("read")
     public R read(Long id) {
@@ -70,7 +70,7 @@ public class NoticeInfoController {
     }
 
     /**
-     * 批阅
+     * 批阅 targetId
      */
     @GetMapping("reads")
     public R reads(List<Long> ids) {

+ 4 - 4
src/main/java/com/dragon/tj/portal/entity/MessageInfo.java

@@ -41,10 +41,7 @@ public class MessageInfo implements Serializable {
     *消息级别
     */
     private Integer messageLevel;
-    /**
-     * 阅读状态 默认0未读 1已读
-     */
-    private Integer readStatus;
+
 
     /**
      * 信息标题
@@ -103,5 +100,8 @@ public class MessageInfo implements Serializable {
     @TableField(exist = false)
     private String scopeId;
 
+    @TableField(exist = false)
+    private Long targetId;
+
 
 }

+ 5 - 0
src/main/java/com/dragon/tj/portal/entity/MessageInfoScope.java

@@ -36,6 +36,11 @@ public class MessageInfoScope implements Serializable {
      */
     private Long messageInfoId;
 
+    /**
+     * 阅读状态 默认0未读 1已读
+     */
+    private Integer readStatus;
+
     /**
      * 人员id
      */

+ 4 - 4
src/main/java/com/dragon/tj/portal/entity/NoticeInfo.java

@@ -1,6 +1,7 @@
 package com.dragon.tj.portal.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
@@ -42,10 +43,6 @@ public class NoticeInfo implements Serializable {
     */
     private Integer messageLevel;
 
-    /**
-     * 阅读状态 默认0未读 1已读
-     */
-    private Integer readStatus;
 
     /**
      * 信息标题
@@ -102,5 +99,8 @@ public class NoticeInfo implements Serializable {
      */
     private Integer version;
 
+    @TableField(exist = false)
+    private Long targetId;
+
 
 }

+ 6 - 0
src/main/java/com/dragon/tj/portal/entity/NoticeInfoScope.java

@@ -37,6 +37,12 @@ public class NoticeInfoScope implements Serializable {
      */
     private String memberId;
 
+    /**
+     * 阅读状态 默认0未读 1已读
+     */
+    private Integer readStatus;
+
+
     /**
      * 范围类型 1部门 2 人员
      */

+ 5 - 0
src/main/java/com/dragon/tj/portal/mapper/MessageInfoMapper.java

@@ -8,6 +8,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 信息表 Mapper 接口
@@ -20,4 +23,6 @@ import org.apache.ibatis.annotations.Param;
 public interface MessageInfoMapper extends BaseMapper<MessageInfo> {
 
     IPage<MessageInfo> queryPage(Page page,@Param("req") MessagePageParam req);
+
+    Integer  getCount(@Param("idCard") String idCard,@Param("readStatus") Integer readStatus);
 }

+ 6 - 0
src/main/java/com/dragon/tj/portal/mapper/NoticeInfoMapper.java

@@ -9,6 +9,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 消息表 Mapper 接口
@@ -21,4 +24,7 @@ import org.apache.ibatis.annotations.Param;
 public interface NoticeInfoMapper extends BaseMapper<NoticeInfo> {
 
     IPage<MessageInfo> queryPage(Page page,@Param("req") MessagePageParam req);
+
+    Integer  getCount(@Param("idCard") String idCard,@Param("readStatus") Integer readStatus);
+
 }

+ 4 - 0
src/main/java/com/dragon/tj/portal/service/MessageInfoService.java

@@ -8,6 +8,7 @@ import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
 import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
 import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
 import com.dragon.tj.portal.common.vo.message.MessagePageParam;
+import com.dragon.tj.portal.common.vo.message.MsgCountVO;
 import com.dragon.tj.portal.entity.MessageInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -34,4 +35,7 @@ public interface MessageInfoService extends IService<MessageInfo> {
     boolean reads(List<Long> ids);
 
     IPage queryPage(Page page, MessagePageParam req);
+
+    MsgCountVO getCount();
+
 }

+ 31 - 5
src/main/java/com/dragon/tj/portal/service/impl/MessageInfoServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dragon.tj.portal.auth.model.LoginUser;
+import com.dragon.tj.portal.auth.util.SecurityUtils;
 import com.dragon.tj.portal.auth.web.service.SysDeptService;
 import com.dragon.tj.portal.common.base.R;
 import com.dragon.tj.portal.common.constants.BusinessConstants;
@@ -20,6 +21,7 @@ import com.dragon.tj.portal.common.enums.message.ScopeEnums;
 import com.dragon.tj.portal.common.vo.message.MessageInfoParam;
 import com.dragon.tj.portal.common.vo.message.MessageInfoVO;
 import com.dragon.tj.portal.common.vo.message.MessagePageParam;
+import com.dragon.tj.portal.common.vo.message.MsgCountVO;
 import com.dragon.tj.portal.component.exception.message.MessageInfoException;
 import com.dragon.tj.portal.component.message.KafkaInitialConfiguration;
 import com.dragon.tj.portal.component.message.MessageProducer;
@@ -27,6 +29,7 @@ import com.dragon.tj.portal.entity.MessageInfo;
 import com.dragon.tj.portal.entity.MessageInfoScope;
 import com.dragon.tj.portal.entity.MsgRecord;
 import com.dragon.tj.portal.mapper.MessageInfoMapper;
+import com.dragon.tj.portal.mapper.NoticeInfoMapper;
 import com.dragon.tj.portal.service.MessageInfoScopeService;
 import com.dragon.tj.portal.service.MessageInfoService;
 import com.dragon.tj.portal.service.MsgRecordService;
@@ -41,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -76,6 +80,9 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
     @Value("${message-secret:false}")
     private boolean messageSecret;
 
+    @Autowired
+    private NoticeInfoMapper noticeInfoMapper;
+
     @Override
     public R push(MessageInfoReq messageInfoReq, LoginUser loginUser) {
         return R.ok(this.doMessage(messageInfoReq, loginUser));
@@ -95,25 +102,25 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
 
     @Override
     public boolean read(Long id) {
-        MessageInfo messageInfo = this.getById(id);
+        MessageInfoScope messageInfo = messageInfoScopeService.getById(id);
         Integer readStatus = messageInfo.getReadStatus();
         if (ReadStatusEnum.YES.value().equals(readStatus)) {
             throw new MessageInfoException(MessageInfoErrorEnums.Code.MESSAGE_READ_ALREADY);
         }
         messageInfo.setReadStatus(ReadStatusEnum.YES.value());
-        return this.updateById(messageInfo);
+        return messageInfoScopeService.updateById(messageInfo);
     }
 
     @Override
     public boolean reads(List<Long> ids) {
-        List<MessageInfo> list = Lists.newArrayList();
+        List<MessageInfoScope> list = Lists.newArrayList();
         ids.forEach(e -> {
-            MessageInfo messageInfo = new MessageInfo();
+            MessageInfoScope messageInfo = new MessageInfoScope();
             messageInfo.setReadStatus(ReadStatusEnum.YES.value());
             messageInfo.setId(e);
 
         });
-        return this.updateBatchById(list);
+        return messageInfoScopeService.updateBatchById(list);
     }
 
     @Override
@@ -122,6 +129,25 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
         return queryPage;
     }
 
+    @Override
+    public MsgCountVO getCount() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        String idCard = loginUser.getIdCard();
+        MsgCountVO msgCountVO = new MsgCountVO();
+        Integer noticeY = noticeInfoMapper.getCount(idCard, ReadStatusEnum.YES.value());
+        Integer noticeN = noticeInfoMapper.getCount(idCard,ReadStatusEnum.NO.value());
+
+        Integer msgY = this.baseMapper.getCount(idCard,ReadStatusEnum.YES.value());
+        Integer msgN = this.baseMapper.getCount(idCard,ReadStatusEnum.NO.value());
+
+        log.info("getCount-{}-{}-{}-{}-{}",idCard,noticeN,noticeY,msgN,msgY);
+        msgCountVO.setNoticeNCount(noticeN);
+        msgCountVO.setNoticeYCount(noticeY);
+        msgCountVO.setMessageYCount(msgY);
+        msgCountVO.setNoticeNCount(msgN);
+        return msgCountVO;
+    }
+
 
     /**
      * @author huey China.

+ 9 - 9
src/main/java/com/dragon/tj/portal/service/impl/NoticeInfoServiceImpl.java

@@ -100,25 +100,25 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
 
     @Override
     public boolean read(Long id) {
-        NoticeInfo noticeInfo = this.getById(id);
-        Integer readStatus = noticeInfo.getReadStatus();
+        NoticeInfoScope scope = noticeInfoScopeService.getById(id);
+        Integer readStatus = scope.getReadStatus();
         if (ReadStatusEnum.YES.value().equals(readStatus)) {
             throw new MessageInfoException(MessageInfoErrorEnums.Code.MESSAGE_READ_ALREADY);
         }
-        noticeInfo.setReadStatus(ReadStatusEnum.YES.value());
-        return this.updateById(noticeInfo);
+        scope.setReadStatus(ReadStatusEnum.YES.value());
+        return noticeInfoScopeService.updateById(scope);
     }
 
     @Override
     public boolean reads(List<Long> ids) {
-        List<NoticeInfo> list = Lists.newArrayList();
+        List<NoticeInfoScope> list = Lists.newArrayList();
         ids.forEach(e -> {
-            MessageInfo messageInfo = new MessageInfo();
-            messageInfo.setReadStatus(ReadStatusEnum.YES.value());
-            messageInfo.setId(e);
+            NoticeInfoScope noticeInfoScope = new NoticeInfoScope();
+            noticeInfoScope.setReadStatus(ReadStatusEnum.YES.value());
+            noticeInfoScope.setId(e);
 
         });
-        return this.updateBatchById(list);
+        return noticeInfoScopeService.updateBatchById(list);
     }
 
     @Override

+ 8 - 21
src/main/resources/mapper/MessageInfoMapper.xml

@@ -2,28 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.dragon.tj.portal.mapper.MessageInfoMapper">
 
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.dragon.tj.portal.entity.MessageInfo">
-        <id column="id" property="id" />
-        <result column="message_type" property="messageType" />
-        <result column="read_status" property="readStatus" />
-        <result column="title" property="title" />
-        <result column="content" property="content" />
-        <result column="attachment_path" property="attachmentPath" />
-        <result column="create_by" property="createBy" />
-        <result column="update_by" property="updateBy" />
-        <result column="create_time" property="createTime" />
-        <result column="update_time" property="updateTime" />
-        <result column="del_flag" property="delFlag" />
-        <result column="version" property="version" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        id, message_type, read_status, title, content, attachment_path, create_by, update_by, create_time, update_time, del_flag, version
-    </sql>
     <select id="queryPage" resultType="com.dragon.tj.portal.entity.MessageInfo">
-        SELECT b.id,member_id,scope_type,scope_id,message_type,read_status,title,content,attachment_path from message_info_scope a
+        SELECT b.id,member_id,scope_type,scope_id,message_type,read_status,title,content,attachment_path,a.id as target_id from message_info_scope a
         LEFT JOIN message_info b on a.message_info_id = b.id
         where b.del_flag = 0
         <if test="req.messageType != null">
@@ -46,5 +26,12 @@
         </if>
         order by b.create_time desc
     </select>
+    <select id="getCount" resultType="java.lang.Integer">
+        SELECT COUNT(1) from message_info_scope a
+        LEFT JOIN message_info b on a.message_info_id = b.id
+        where b.del_flag = 0
+        and  a.read_status = #{readStatus}
+        and  a.member_id = #{idCard}
+    </select>
 
 </mapper>

+ 0 - 12
src/main/resources/mapper/MessageInfoScopeMapper.xml

@@ -2,17 +2,5 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.dragon.tj.portal.mapper.MessageInfoScopeMapper">
 
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.dragon.tj.portal.entity.MessageInfoScope">
-        <id column="id" property="id" />
-        <result column="scope_type" property="scopeType" />
-        <result column="scope_id" property="scopeId" />
-        <result column="scope_level" property="scopeLevel" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        id, scope_type, scope_id, scope_level
-    </sql>
 
 </mapper>

+ 8 - 1
src/main/resources/mapper/NoticeInfoMapper.xml

@@ -4,7 +4,7 @@
 
 
     <select id="queryPage" resultType="com.dragon.tj.portal.entity.NoticeInfo">
-        SELECT b.id,member_id,scope_type,scope_id,message_type,read_status,title,content,attachment_path from notice_info_scope a
+        SELECT b.id,member_id,scope_type,scope_id,message_type,read_status,title,content,attachment_path,a.id as target_id from notice_info_scope a
         LEFT JOIN notice_info b on a.notice_info_id = b.id
         where b.del_flag = 0
         <if test="req.messageType != null">
@@ -27,4 +27,11 @@
         </if>
         order by b.create_time desc
     </select>
+    <select id="getCount" resultType="java.lang.Integer">
+        SELECT COUNT(1) from notice_info_scope a
+        LEFT JOIN notice_info b on a.notice_info_id = b.id
+        where b.del_flag = 0
+          and  a.read_status = #{readStatus}
+          and  a.member_id = #{idCard}
+    </select>
 </mapper>

+ 0 - 13
src/main/resources/mapper/NoticeInfoScopeMapper.xml

@@ -2,18 +2,5 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.dragon.tj.portal.mapper.NoticeInfoScopeMapper">
 
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.dragon.tj.portal.entity.NoticeInfoScope">
-        <id column="id" property="id" />
-        <result column="member_id" property="memberId" />
-        <result column="scope_type" property="scopeType" />
-        <result column="scope_id" property="scopeId" />
-        <result column="scope_level" property="scopeLevel" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        id, member_id, scope_type, scope_id, scope_level
-    </sql>
 
 </mapper>