From 1c7ac77edb8cdd6330ad1fc0958f383bbd064fce Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 11 二月 2026 10:36:50 +0800
Subject: [PATCH] feat: APP已读通告接口、推送携带通知ID

---
 src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 97 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
index ca0303a..28ec77c 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
@@ -1,5 +1,6 @@
 package com.ruoyi.project.system.service.impl;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -14,14 +15,20 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.xiaoymin.knife4j.core.util.StrUtil;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysUser;
+import com.ruoyi.project.system.domain.SysUserDept;
+import com.ruoyi.project.system.mapper.SysDeptMapper;
+import com.ruoyi.project.system.mapper.SysUserDeptMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import com.ruoyi.project.system.domain.SysNotice;
 import com.ruoyi.project.system.mapper.SysNoticeMapper;
 import com.ruoyi.project.system.service.ISysNoticeService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 鍏憡 鏈嶅姟灞傚疄鐜�
@@ -38,8 +45,17 @@
     private SysUserMapper userMapper;
 
     @Autowired
+    private SysDeptMapper deptMapper;
+
+    @Autowired
+    private SysUserDeptMapper userDeptMapper;
+
+    @Autowired
     @Lazy
     private ISysNoticeService sysNoticeService;
+
+    @Autowired
+    private UnipushService unipushService;
 
     /**
      * 鏌ヨ鍏憡淇℃伅
@@ -129,25 +145,79 @@
     }
 
     @Override
-    public void simpleNoticeByUser(String title, String message,  List<Long> consigneeId, Long tenantId,
-                                    String jumpPath) {
+    public void simpleNoticeByUser(String title, String message, List<Long> consigneeId, String jumpPath) {
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<SysNotice> sysNotices = consigneeId.stream().map(it -> convertSysNotice(title, message, it,tenantId, jumpPath, userId)).collect(Collectors.toList());
+        Long tenantId = SecurityUtils.getLoginUser().getTenantId();
+        List<SysNotice> sysNotices = consigneeId.stream()
+                .map(it -> convertSysNotice(title, message, it, tenantId, jumpPath, unipushService.convertWebPathToAppPath(jumpPath), userId))
+                .collect(Collectors.toList());
         sysNoticeService.saveBatch(sysNotices);
+        try {
+            unipushService.sendClientMessage(sysNotices);
+        } catch (Exception e) {
+            log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
+        }
     }
 
     @Override
-    public void simpleNoticeAll(String title, String message,  Long tenantId,String jumpPath) {
+    public void simpleNoticeAll(String title, String message,  String jumpPath) {
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<SysUser> sysUsers = userMapper.selectList(Wrappers.<SysUser>lambdaQuery()
-                .eq(SysUser::getStatus, "0")
-                .eq(SysUser::getTenantId, tenantId));
-        List<SysNotice> collect = sysUsers.stream().map(it -> convertSysNotice(title, message, it.getUserId(),tenantId, jumpPath,  userId)).collect(Collectors.toList());
+        if (userId == null) {
+            return;
+        }
+        Long rootDeptId = SecurityUtils.getLoginUser().getTenantId();
+        //  鏌ユ墍鏈夊瓙閮ㄩ棬
+        List<SysDept> childrenDepts = deptMapper.selectChildrenDeptById(rootDeptId);
+
+        //  缁勮 deptIds
+        List<Long> deptIds = childrenDepts.stream()
+                .map(SysDept::getDeptId)
+                .collect(Collectors.toList());
+        deptIds.add(rootDeptId);
+
+        //  鏌ョ敤鎴稩D
+        List<Long> userIds = userDeptMapper.selectList(
+                        Wrappers.<SysUserDept>lambdaQuery()
+                                .in(SysUserDept::getDeptId, deptIds)
+                ).stream()
+                .map(SysUserDept::getUserId)
+                .distinct()
+                .collect(Collectors.toList());
+
+        if (userIds.isEmpty()) {
+            return;
+        }
+
+        //  鏌ョ敤鎴�
+        List<SysUser> sysUsers = userMapper.selectList(
+                Wrappers.<SysUser>lambdaQuery()
+                        .eq(SysUser::getStatus, "0")
+                        .in(SysUser::getUserId, userIds)
+        );
+
+        //  鍙戦�氱煡
+        List<SysNotice> collect = sysUsers.stream()
+                .map(it -> convertSysNotice(
+                        title,
+                        message,
+                        it.getUserId(),
+                        it.getTenantId(),
+                        jumpPath,
+                        unipushService.convertWebPathToAppPath(jumpPath),
+                        userId
+                ))
+                .collect(Collectors.toList());
+
         sysNoticeService.saveBatch(collect);
+        try {
+            unipushService.sendClientMessage(collect);
+        } catch (Exception e) {
+            log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
+        }
     }
 
 
-    private SysNotice convertSysNotice(String title,String message,Long consigneeId, Long tenantId,String jumpPath,Long currentUserId) {
+    private SysNotice convertSysNotice(String title,String message,Long consigneeId, Long tenantId,String jumpPath,String appJumpPath,Long currentUserId) {
         SysNotice sysNotice = new SysNotice();
         sysNotice.setNoticeType("1");
         sysNotice.setNoticeTitle(title);//鏍囬
@@ -156,7 +226,25 @@
         sysNotice.setConsigneeId(consigneeId);
         sysNotice.setSenderId(currentUserId);
         sysNotice.setJumpPath(jumpPath);
+        sysNotice.setAppJumpPath(appJumpPath);
         sysNotice.setTenantId(tenantId);
         return sysNotice;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean appReadNotice(Long noticeId) {
+        if (noticeId == null) {
+            return false;
+        }
+        SysNotice sysNotice = noticeMapper.selectNoticeById(noticeId);
+        if (sysNotice == null) {
+            return false;
+        }
+        sysNotice.setStatus("1");
+        return noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate()
+                .eq(SysNotice::getNoticeId, noticeId)
+                .eq(SysNotice::getStatus, "0")
+                .set(SysNotice::getStatus, "1")) > 0;
+    }
 }

--
Gitblit v1.9.3