Browse Source

消息全部已读

yzc 1 year ago
parent
commit
1a5b89f9f5

+ 13 - 1
hx-socket/src/main/java/com/fjhx/socket/controller/push/PushInfoController.java

@@ -1,5 +1,6 @@
 package com.fjhx.socket.controller.push;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.socket.entity.push.dto.PushInfoSelectDto;
@@ -7,12 +8,15 @@ import com.fjhx.socket.entity.push.vo.PushInfoVo;
 import com.fjhx.socket.service.push.PushInfoService;
 import com.ruoyi.common.constant.BaseSourceConstant;
 import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.ruoyi.common.exception.ServiceException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -48,7 +52,15 @@ public class PushInfoController {
 
     @PostMapping("/read")
     public void read(@RequestBody PushInfoSelectDto dto) {
-        pushInfoService.read(dto.getIdList());
+        List<Long> idList = dto.getIdList();
+        if(ObjectUtil.isEmpty(idList)){
+            throw new ServiceException("消息id列表不能为空");
+        }
+        pushInfoService.read(idList);
+    }
+    @PostMapping("/readAll")
+    public void readAll() {
+        pushInfoService.readAll();
     }
 
 }

+ 1 - 0
hx-socket/src/main/java/com/fjhx/socket/service/push/PushInfoService.java

@@ -35,4 +35,5 @@ public interface PushInfoService extends BaseService<PushInfo> {
      */
     void read(List<Long> idList);
 
+    void readAll();
 }

+ 15 - 1
hx-socket/src/main/java/com/fjhx/socket/service/push/impl/PushInfoServiceImpl.java

@@ -48,7 +48,7 @@ public class PushInfoServiceImpl extends ServiceImpl<PushInfoMapper, PushInfo> i
         });
 
         //业务类型过滤
-        if (ObjectUtil.isNotEmpty(dto.getBusinessType())){
+        if (ObjectUtil.isNotEmpty(dto.getBusinessType())) {
             wrapper.in("pi", PushInfo::getBusinessType, dto.getBusinessType().split(","));
         }
 
@@ -66,6 +66,20 @@ public class PushInfoServiceImpl extends ServiceImpl<PushInfoMapper, PushInfo> i
     @Override
     public void read(List<Long> idList) {
         update(q -> q.in(BaseIdPo::getId, idList)
+                .eq(PushInfo::getPushUserId, SecurityUtils.getUserId())
+                .set(PushInfo::getPushRead, StatusConstant.YES)
+                .set(BasePo::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+        // 已读之后重新推送一次未读消息数量
+        WebSocketPush.pushMessageCount(SecurityUtils.getUserId());
+    }
+
+    @Override
+    public void readAll() {
+        update(q -> q
+                .eq(PushInfo::getPushUserId, SecurityUtils.getUserId())
                 .set(PushInfo::getPushRead, StatusConstant.YES)
                 .set(BasePo::getUpdateTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())