| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | |
|
| | | @Autowired
|
| | | private SysUserMapper userMapper;
|
| | |
|
| | | @Autowired
|
| | | private SysDeptMapper deptMapper;
|
| | |
|
| | | @Autowired
|
| | | private SysUserDeptMapper userDeptMapper;
|
| | |
|
| | | @Autowired
|
| | | @Lazy
|
| | |
| | | }
|
| | |
|
| | | @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))
|
| | | .collect(Collectors.toList());
|
| | | sysNoticeService.insertBatch(collect);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void simpleNoticeByPerms(String title, String message, Long tenantId, List<String> needPerms,
|
| | | String jumpPath) {
|
| | | Long userId = SecurityUtils.getLoginUser().getUserId();
|
| | | if (StrUtil.isBlank(message) || CollectionUtils.isEmpty(needPerms)) {
|
| | | return;
|
| | | }
|
| | | List<SysNotice> collect = userMapper.getUserByPerms(needPerms).stream().map(it -> convertSysNotice(title, message, it,tenantId, jumpPath, userId)).collect(Collectors.toList());
|
| | | sysNoticeService.insertBatch(collect);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void simpleNoticeByUser(String title, String message, List<Long> consigneeId, Long tenantId,
|
| | | String jumpPath) {
|
| | | Long userId = SecurityUtils.getLoginUser().getUserId();
|
| | |
| | | }
|
| | |
|
| | | @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<SysNotice> collect = userMapper.selectList(null).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);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void insertBatch(List<SysNotice> noticesList) {
|
| | | if(CollectionUtils.isEmpty(noticesList)){
|
| | | 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);
|
| | |
|
| | | }
|
| | |
|
| | | private SysNotice convertSysNotice(String title,String message,Long consigneeId, Long tenantId,String jumpPath,Long currentUserId) {
|
| | | SysNotice sysNotice = new SysNotice();
|