From 1ca5584d7e3200a9af65a099bd26d3593e2ba702 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 07 五月 2026 14:36:08 +0800
Subject: [PATCH] 迁移pro

---
 src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java |  152 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 93 insertions(+), 59 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 79a5750..dcbcded 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,24 +1,25 @@
 package com.ruoyi.project.system.service.impl;
 
-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.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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.mapper.SysUserMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.stereotype.Service;
+import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysNotice;
+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.SysNoticeMapper;
+import com.ruoyi.project.system.mapper.SysUserDeptMapper;
+import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.project.system.service.ISysNoticeService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 鍏憡 鏈嶅姟灞傚疄鐜�
@@ -26,17 +27,14 @@
  * @author ruoyi
  */
 @Service
+@RequiredArgsConstructor
 public class SysNoticeServiceImpl  extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {
 
-    @Autowired
-    private SysNoticeMapper noticeMapper;
-
-    @Autowired
-    private SysUserMapper userMapper;
-
-    @Autowired
-    @Lazy
-    private ISysNoticeService sysNoticeService;
+    private final SysNoticeMapper noticeMapper;
+    private final SysUserMapper userMapper;
+    private final SysDeptMapper deptMapper;
+    private final SysUserDeptMapper userDeptMapper;
+    private final UnipushService unipushService;
 
     /**
      * 鏌ヨ鍏憡淇℃伅
@@ -126,60 +124,78 @@
     }
 
     @Override
-    public void simpleNoticeByRoles(final String title, String message, Long tenantId, 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,tenantId, 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);
+        noticeMapper.insert(sysNotices);
+        try {
+            unipushService.sendClientMessage(sysNotices);
+        } catch (Exception e) {
+            log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
+        }
     }
 
     @Override
-    public void simpleNoticeByPerms(String title, String message, Long tenantId, 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,tenantId, 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,  List<Long> consigneeId, Long tenantId,
-                                    String jumpPath) {
-        Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<SysNotice> sysNotices = consigneeId.stream().map(it -> convertSysNotice(title, message, it,tenantId, jumpPath, userId)).collect(Collectors.toList());
-        sysNoticeService.saveBatch(sysNotices);
-    }
+        //  缁勮 deptIds
+        List<Long> deptIds = childrenDepts.stream()
+                .map(SysDept::getDeptId)
+                .collect(Collectors.toList());
+        deptIds.add(rootDeptId);
 
-    @Override
-    public void simpleNoticeAll(String title, String message,  Long tenantId,String jumpPath) {
-        Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<SysNotice> collect = userMapper.selectList(null).stream().map(it -> convertSysNotice(title, message, it.getUserId(),tenantId, jumpPath,  userId)).collect(Collectors.toList());
-        sysNoticeService.saveBatch(collect);
-    }
+        //  鏌ョ敤鎴稩D
+        List<Long> userIds = userDeptMapper.selectList(
+                        Wrappers.<SysUserDept>lambdaQuery()
+                                .in(SysUserDept::getDeptId, deptIds)
+                ).stream()
+                .map(SysUserDept::getUserId)
+                .distinct()
+                .collect(Collectors.toList());
 
-    @Override
-    public void insertBatch(List<SysNotice> noticesList) {
-        if(CollectionUtils.isEmpty(noticesList)){
+        if (userIds.isEmpty()) {
             return;
         }
-        // 鎺掗櫎鎺夎嚜宸�
-        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);
 
+        //  鏌ョ敤鎴�
+        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());
+        noticeMapper.insert(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);//鏍囬
@@ -188,7 +204,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