| | |
| | | package com.ruoyi.collaborativeApproval.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.collaborativeApproval.dto.NoticeDTO; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Slf4j |
| | |
| | | |
| | | @Override |
| | | public List<NoticeDTO> selectCount() { |
| | | List<Notice> notices = noticeMapper.selectList(Wrappers.lambdaQuery(Notice.class).groupBy(Notice::getType)); |
| | | List<Notice> noticesList = noticeMapper.selectList(null); |
| | | Map<String, Notice> uniqueByType = noticesList.stream() |
| | | .collect(Collectors.toMap( |
| | | Notice::getType, |
| | | n -> n, |
| | | (existing, replacement) -> existing |
| | | )); |
| | | |
| | | List<Notice> notices = new ArrayList<>(uniqueByType.values()); |
| | | Map<String, Long> countMap = noticesList.stream().collect(Collectors.groupingBy(Notice::getType, Collectors.counting())); |
| | | List<NoticeDTO> result = new ArrayList<>(); |
| | | for (Notice notice : notices) { |
| | | NoticeDTO notice1 = new NoticeDTO(); |
| | | BeanUtils.copyProperties(notice, notice1); |
| | | notice1.setCount(noticeMapper.selectCount(new LambdaQueryWrapper<Notice>().eq(Notice::getType, notice.getType()))); |
| | | if (countMap.containsKey(notice.getType())) { |
| | | notice1.setCount(countMap.get(notice.getType()) == null ? 0 : countMap.get(notice.getType())); |
| | | } |
| | | result.add(notice1); |
| | | } |
| | | return result; |