zouyu
8 天以前 09394848ce262aff81897503d32ec334fd3f2b6f
src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
@@ -14,7 +14,11 @@
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;
@@ -36,6 +40,12 @@
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private SysDeptMapper deptMapper;
    @Autowired
    private SysUserDeptMapper userDeptMapper;
    @Autowired
    @Lazy
@@ -137,12 +147,53 @@
    }
    @Override
    public void simpleNoticeAll(String title, String message,  Long tenantId,String jumpPath) {
    public void simpleNoticeAll(String title, String message, Long rootDeptId, 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;
        }
        //  查所有子部门
        List<SysDept> childrenDepts = deptMapper.selectChildrenDeptById(rootDeptId);
        //  组装 deptIds
        List<Long> deptIds = childrenDepts.stream()
                .map(SysDept::getDeptId)
                .collect(Collectors.toList());
        deptIds.add(rootDeptId);
        //  查用户ID
        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,
                        userId
                ))
                .collect(Collectors.toList());
        sysNoticeService.saveBatch(collect);
    }