| | |
| | | package com.ruoyi.project.system.service.impl;
|
| | |
|
| | | import java.util.List;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.stereotype.Service;
|
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.ruoyi.common.utils.SecurityUtils; |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
|
| | | /**
|
| | | * 公告 服务层实现
|
| | |
| | | * @author ruoyi
|
| | | */
|
| | | @Service
|
| | | public class SysNoticeServiceImpl implements ISysNoticeService
|
| | | {
|
| | | public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService { |
| | | |
| | | @Autowired
|
| | | private SysNoticeMapper noticeMapper;
|
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | private SysUserDeptMapper userDeptMapper; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private ISysNoticeService sysNoticeService; |
| | | |
| | | @Autowired |
| | | private UnipushService unipushService; |
| | |
|
| | | /**
|
| | | * 查询公告信息
|
| | |
| | | * @return 公告集合
|
| | | */
|
| | | @Override
|
| | | public List<SysNotice> selectNoticeList(SysNotice notice)
|
| | | {
|
| | | return noticeMapper.selectNoticeList(notice);
|
| | | public IPage<SysNotice> selectNoticeList(SysNotice notice, Page page) { |
| | | return noticeMapper.selectNoticeList(notice, page); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | {
|
| | | return noticeMapper.deleteNoticeByIds(noticeIds);
|
| | | }
|
| | | |
| | | @Override |
| | | public Long getCount(Long consigneeId) { |
| | | return noticeMapper.selectCount(Wrappers.<SysNotice>lambdaQuery() |
| | | .eq(SysNotice::getStatus, "0") |
| | | .eq(SysNotice::getConsigneeId, consigneeId)); |
| | | } |
| | | |
| | | @Override |
| | | public int readAll() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | return noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate() |
| | | .eq(SysNotice::getConsigneeId, userId) |
| | | .eq(SysNotice::getStatus, "0") |
| | | .set(SysNotice::getStatus, "1")); |
| | | } |
| | | |
| | | @Override |
| | | 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.saveBatch(sysNotices); |
| | | try { |
| | | unipushService.sendClientMessage(sysNotices); |
| | | } catch (Exception e) { |
| | | log.error("APP推送通知失败,原因: {}", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void simpleNoticeAll(String title, String message, String jumpPath) { |
| | | Long userId = SecurityUtils.getLoginUser().getUserId(); |
| | | 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); |
| | | |
| | | // 查用户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, |
| | | 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,String appJumpPath,Long currentUserId) { |
| | | SysNotice sysNotice = new SysNotice(); |
| | | sysNotice.setNoticeType("1"); |
| | | sysNotice.setNoticeTitle(title);//标题 |
| | | sysNotice.setNoticeContent(message); |
| | | sysNotice.setStatus("0"); |
| | | 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; |
| | | } |
| | | }
|