| | |
| | | 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.SysNotice;
|
| | | import com.ruoyi.project.system.mapper.SysNoticeMapper;
|
| | |
| | |
|
| | | /**
|
| | | * 公告 服务层实现
|
| | | * |
| | | *
|
| | | * @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
|
| | | @Lazy
|
| | | private ISysNoticeService sysNoticeService;
|
| | |
|
| | | /**
|
| | | * 查询公告信息
|
| | | * |
| | | *
|
| | | * @param noticeId 公告ID
|
| | | * @return 公告信息
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 查询公告列表
|
| | | * |
| | | *
|
| | | * @param notice 公告信息
|
| | | * @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);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 新增公告
|
| | | * |
| | | *
|
| | | * @param notice 公告信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 修改公告
|
| | | * |
| | | *
|
| | | * @param notice 公告信息
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 删除公告对象
|
| | | * |
| | | *
|
| | | * @param noticeId 公告ID
|
| | | * @return 结果
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 批量删除公告信息
|
| | | * |
| | | *
|
| | | * @param noticeIds 需要删除的公告ID
|
| | | * @return 结果
|
| | | */
|
| | |
| | | {
|
| | | 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 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))
|
| | | .collect(Collectors.toList());
|
| | | sysNoticeService.insertBatch(collect);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void simpleNoticeByPerms(String title, String message, 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, jumpPath, userId)).collect(Collectors.toList());
|
| | | sysNoticeService.insertBatch(collect);
|
| | | }
|
| | |
|
| | | @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);
|
| | | }
|
| | |
|
| | | @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());
|
| | | 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,String jumpPath,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);
|
| | | return sysNotice;
|
| | | }
|
| | | }
|