From b9a985fea44086bb07069b1913835bbfaf0ed44a Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期三, 11 二月 2026 12:00:30 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New

---
 src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java |  139 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 98 insertions(+), 41 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 f600e91..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,10 +1,13 @@
 package com.ruoyi.project.system.service.impl;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -12,13 +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;
 
 /**
  * 鍏憡 鏈嶅姟灞傚疄鐜�
@@ -35,8 +45,17 @@
     private SysUserMapper userMapper;
 
     @Autowired
+    private SysDeptMapper deptMapper;
+
+    @Autowired
+    private SysUserDeptMapper userDeptMapper;
+
+    @Autowired
     @Lazy
     private ISysNoticeService sysNoticeService;
+
+    @Autowired
+    private UnipushService unipushService;
 
     /**
      * 鏌ヨ鍏憡淇℃伅
@@ -126,60 +145,79 @@
     }
 
     @Override
-    public void simpleNoticeByRoles(final String title, String message, List<String> needPushRoles,
-                                             final String jumpPath) {
-        Long userId = SecurityUtils.getUserId();
-        if (StrUtil.isBlank(message) || CollectionUtils.isEmpty(needPushRoles)) {
-            return;
-        }
-        List<String> rolesWithAdmin = new ArrayList<>(needPushRoles);
-        rolesWithAdmin.add("绠$悊鍛�");
-        List<SysNotice> collect = rolesWithAdmin.stream()
-                .flatMap(it -> userMapper.getUserByRole(it).stream())
-                .map(it -> convertSysNotice(title, message, it, jumpPath, userId))
+    public void simpleNoticeByUser(String title, String message, List<Long> consigneeId, String jumpPath) {
+        Long userId = SecurityUtils.getLoginUser().getUserId();
+        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.insertBatch(collect);
+        sysNoticeService.saveBatch(sysNotices);
+        try {
+            unipushService.sendClientMessage(sysNotices);
+        } catch (Exception e) {
+            log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
+        }
     }
 
     @Override
-    public void simpleNoticeByPerms(String title, String message, List<String> needPerms,
-                                             String jumpPath) {
+    public void simpleNoticeAll(String title, String message,  String jumpPath) {
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        if (StrUtil.isBlank(message) || CollectionUtils.isEmpty(needPerms)) {
+        if (userId == null) {
             return;
         }
-        List<SysNotice> collect = userMapper.getUserByPerms(needPerms).stream().map(it -> convertSysNotice(title, message, it, jumpPath,  userId)).collect(Collectors.toList());
-        sysNoticeService.insertBatch(collect);
-    }
+        Long rootDeptId = SecurityUtils.getLoginUser().getTenantId();
+        //  鏌ユ墍鏈夊瓙閮ㄩ棬
+        List<SysDept> childrenDepts = deptMapper.selectChildrenDeptById(rootDeptId);
 
-    @Override
-    public void simpleNoticeByUser(String title, String message, Long consigneeId,
-                                    String jumpPath) {
-        Long userId = SecurityUtils.getLoginUser().getUserId();
-        SysNotice sysNotice = convertSysNotice(title, message, consigneeId, jumpPath, userId);
-        sysNoticeService.save(sysNotice);
-    }
+        //  缁勮 deptIds
+        List<Long> deptIds = childrenDepts.stream()
+                .map(SysDept::getDeptId)
+                .collect(Collectors.toList());
+        deptIds.add(rootDeptId);
 
-    @Override
-    public void simpleNoticeAll(String title, String message, String jumpPath) {
-        Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<SysNotice> collect = userMapper.selectList(null).stream().map(it -> convertSysNotice(title, message, it.getUserId(), jumpPath,  userId)).collect(Collectors.toList());
+        //  鏌ョ敤鎴稩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);
-    }
-
-    @Override
-    public void insertBatch(List<SysNotice> noticesList) {
-        if(CollectionUtils.isEmpty(noticesList)){
-            return;
+        try {
+            unipushService.sendClientMessage(collect);
+        } catch (Exception e) {
+            log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
         }
-        // 鎺掗櫎鎺夎嚜宸�
-        Long userId = SecurityUtils.getUserId();
-        List<SysNotice> noticesListNew = noticesList.stream().filter(Objects::nonNull).filter(it -> !Objects.equals(it.getConsigneeId(), userId)).collect(Collectors.toList());
-        sysNoticeService.saveBatch(noticesListNew);
-
     }
 
-    private SysNotice convertSysNotice(String title,String message,Long consigneeId,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);//鏍囬
@@ -188,6 +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